9

How to do below in one bash command ? I mean rename file to current date

$ echo `date +"%m-%d-%y"`
01-14-16
$ mv backup1.tar 01-14-16

1 Answer 1

16
mv backup1.tar "$(date +"%m-%d-%y")"

$(...) is an alternative syntax to ``. This will first execute $(date +"%m-%d-%y"), so that the command line really becomes mv backup1.tar 01-14-16.

Please note that it might be good to do some checking here, e.g. if the file already exists.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .