-1

I have hundreds of image files (.jpg) with different names with nothing in common; e.g., 12223.jpg, beautiful-ocean.jpg, aWkqi.jpg. How can i rename them all in series, such as 1.jpg, 2.jpg, 3.jpg...

K7AAY
  • 17,202
  • https://stackoverflow.com/questions/3211595/renaming-files-in-a-folder-to-sequential-numbers or https://askubuntu.com/questions/301781/how-to-rename-multiple-files-sequentially-from-command-line – Rinzwind Jun 04 '19 at 20:51

1 Answers1

1

One could rename the files as 001.jpg, 002.jpg, ... 999.jpg in bash by:

declare -i num=1
for file in *.jpg ; do
    printf -v newname "%03d.jpg" $num
    num=$(( num + 1 ))
    echo mv "$file" "$newname"
done

Change "echo mv" to "mv" when you're happy with the generated results.

waltinator
  • 36,399