Command to rename files according to creation date on Mac OS X

Someone might find this command useful, it renames files in the current directory according to their respective creation dates:

I found this link and modified the command per the below:

for i in *; do newname=$(stat -t %Y%m%d%H%M%S -f %Sm -- $i); mv -- $i $newname; done

I used it to rename .jpg screenshots that I created before uploading them to WordPress to ensure strict uniform file naming convention. To do that I ran:

for i in *.jpg; do newname=$(stat -t %Y%m%d%H%M%S -f %Sm -- $i); mv -- $i $newname.jpg; done

Hopefully this may save someone a few dollars as you won’t need to buy some of those Mac file renaming applications just to rename files according to creation date.

Command to remove first three characters of filenames

Run the following command on your Mac to remove the first three characters of all filenames in the current folder:

ls | awk '{printf "mv \"%s\" \"%s\"\n", $0, substr($0, 3) }' | bash

So I have a folder called test that contains 4 files that need to be renamed:

01 test1.jpg
02 test2.jpg
03 test3.jpg
04 test4.jpg

So I run the command and we get:

test1.jpg
test2.jpg
test3.jpg
test4.jpg

As you can see above the files have all been renamed accordingly – the numbers and the space at the beginning of each file have gone.