Rename Multiple files and add date before the files

gar*_*ncn 1 bash rename

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

In next day(2011-10-08), they are changed to:

2011-10-08_file1.tar.gz
2011-10-08_file2.tar.gz
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

gle*_*man 6

Clearly, the key is to avoid renaming files that already have a date prefix.

cdate=$(date +"%Y-%m-%d")
shopt -s extglob
for file in !([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]*.gz); do
  mv "$file" "${cdate}_$file"
done
Run Code Online (Sandbox Code Playgroud)