Ubuntu – How to bulk rename files numerically, in order of modification date

batch-renamecommand linephoto-managementsoftware-recommendation

I've got some photos with quite random names, but the dates (not exif, but when they were last edited) are correct. I'd like to rename them in that order, preferably so that the first photo is named 1.jpg and so on, but anything goes.

How can I do that?

Best Answer

  • In the directory containing the pictures, run:

    mkdir renamed; num=0; for f in $(ls -t); do cp -p "$f" renamed/IMG_$(printf "%03d" $num).jpg; num=$((num+1)); done

    This will copy the files to a new directory renamed, keeping timestamps untouched. The format will be IMG_###.jpg with three-digit numbers, using leading zeros. You can change the number of digits by changing the %03d part.