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
Written by Jean-Rémy Duboc
Related protips
2 Responses
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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#