I have a folder contains one or more tar.gz files. I want to add current date before each files when the script run.
For example:
Two file name(those files will be created each day, but the name will remain the same):
file1.tar.gz
file2.tar.gz
In first day(2011-10-07), those two files will be renamed to:
2011-10-07_file1.tar.gz
2011-10-07_file2.tar.gz
In next day(2011-10-08), they are changed to:
2011-10-08_file1.tar.gz
2011-10-08_file2.tar.gz
Finally, the folder contains the following files:
2011-10-07_file1.tar.gz
2011-10-07_file2.tar.gz
2011-10-08_file1.tar.gz
2011-10-08_file2.tar.gz
How to achieve this using one line? I tried to use "rename" command, but I can only add the date after the file, not before.
My code
cdate=`date +"%Y-%m-%d"`; rename .gz .gz.$cdate *.gz