Last Updated: March 02, 2016
·
218
· Jean-Remy Duboc

Renamimg all files in a folder using the `mv` command

Imagine you've got hundreds or more jpg files in a folder, and you need to rename them all following a simple convention.
For instance, you might want to add '-img' at the end of each file (but before the file extension).

You can do that easily using the good old mv command, looping through each file and renaming it like so:

for file in *.jpg
do
    mv -i "${file}" "${file/.jpg/-img.jpg}";
done

2 Responses
Add your response

Or if you have installed util-linux package you could use "rename" command :)

over 1 year ago ·

Indeed !
It's just useful to know that you can use mv for servers where you may not have the access rights to install a new package :)

over 1 year ago ·