Ubuntu – How to rename files in a directory by adding a value to current name

batch-renamerename

I have multiple files in a directory like 1.jpg, 2.jpg, 15.jpg etc. I want to add a specific value to these names -for eg: 10, so that the files are renamed to 11.jpg, 12.jpg, 25.jpg etc.
Is there any way to achieve it?

(It's not bulk renaming. It's to do renaming by adding a value to the current name)

Best Answer

You can use:

mkdir new
for f in *.jpg; do
    mv "$f" "new/$(( ${f%%.jpg} + 10)).jpg";done
mv new/* .
rmdir new

it will put the new files in a temporary new folder in order to avoid overwrites.

Related Question