Bash: Rename all files in current directory to include the time

I have a directory of files and I want to append the creation date (mtime) to the filename for archival purposes. I worked up a simple bash command to do it:

for i in *; do date_raw=$(stat --format %Y "$i"); date_format=$(date --date=@$date_raw +%Y-%m-%d); mv "$i" "$date_format-$i"; done;

Basically it stats the file to get the mtime, then uses date to format it, and finally renames the file.



Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
 
Logged IP: 34.204.183.113
To prevent spam please submit by clicking the kitten: