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.
Leave A Reply
- 1 Reply
Replies
January 12th 2014 - remke
Very nice, yust wat i was looking for (renaming downloads) Thx!
~remke