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.gzIn first day(2011-10-07), those two files will be renamed to:2011-10-07_file1.tar.gz2011-10-07_file2.tar.gzIn next day(2011-10-08), they are changed to:2011-10-08_file1.tar.gz2011-10-08_file2.tar.gzFinally, the folder contains the following files:2011-10-07_file1.tar.gz2011-10-07_file2.tar.gz2011-10-08_file1.tar.gz2011-10-08_file2.tar.gzHow 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 codecdate=`date +%Y-%m-%d`; rename .gz .gz.$cdate *.gz
Rename Multiple files and add date before the files
bash;rename
Clearly, the key is to avoid renaming files that already have a date prefix.cdate=$(date +%Y-%m-%d)shopt -s extglobfor file in !([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]*.gz); do  mv $file ${cdate}_$filedone