Use bash to sequencially rename files
A few days ago, I came across the need to neatly rename a group of files in a folder. The main idea was to use a prefix and then a number (in addition to the extension, of course). For example:
photo-001.jpg
photo-002.jpg
photo-003.jpg
and so on..
The quickest solution I found in bash was as follows:
find -name '*.jpg' | awk 'BEGIN{ a=1 }{ printf "mv %s photo-%04d.jpg\n", $0, a++ }' | bash
This Bash script finds all files with the “.jpg” extension, assigns them names with a prefix “photo-” followed by a four-digit number (padded with zeros if necessary), and executes the rename command using mv
.