Rename files by date

A short Terminal loop renames every file in a folder to its date and time, like 2026-09-25_14.30.05.jpg. Two files from the same second get -2, -3 on the end, and running it twice changes nothing.

How

Go to the folder:

cd ~/Pictures/trip

Rename each file to the date it was last changed, never overwriting:

for f in *.*; do d=$(stat -f %Sm -t %Y-%m-%d_%H.%M.%S "$f"); e="${f##*.}"; n="$d.$e"; i=2; while [ -e "$n" ] && [ "$n" != "$f" ]; do n="$d-$i.$e"; i=$((i+1)); done; [ "$n" = "$f" ] || mv -n "$f" "$n"; done

This uses the date the file was last changed. Photos copied straight off a camera or phone usually keep the shot time, but an edited or re-saved photo carries the edit time. Try it on a copy first.

Or just ask Titan
Rename the photos in this folder by the date they were taken. Do it with Titan

Titan is an AI that lives on your computer: tell it what you need and it does it while you watch — you press Return, nothing runs by itself. What is Titan?

Titan isn’t on this computer yet. Get Titan, then press the button again — the task will be waiting, typed in.

Related

Rename many files at onceSort files into folders by type