How to batch rename files via Terminal using the file's date as filename?

Solution 1:

for f in *.*; do 
    echo mv "$f" "$(stat -f '%Sm' -t '%Y-%m-%d %H.%M.%S' "$f").${f##*.}"
done

Or as a one-liner:

for f in *.*; do echo mv "$f" "$(stat -f '%Sm' -t '%Y-%m-%d %H.%M.%S' "$f").${f##*.}"; done

In either case, remove the echo command after testing.

The ${f##*.} portion of the command get the extension of $f so you can use the glob *.* vs. using an extension in the for f in, i.e. for f in *.* vs. for f in *.jpg

Solution 2:

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

Remove the echo once you are sure that the command looks ok.