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)

  • 3
    possible duplicate of Renaming a word in the filename of all *.jpg files – A.B. Sep 16 '15 at 8:47
  • please note that the proposals int the mentioned duplicates will most probably result in images being overwritten (i.e. moving 1.jpg to 11.jpg will result in 11.jpg being overwritten) – user448115 Sep 16 '15 at 9:20
  • 1
    @JacobVlijm ok, retracted – A.B. Sep 16 '15 at 10:08
  • 1
    @JacobVlijm I was also about to close it when I noticed the thing. We discussed this on Meta already, but I think a good solution would be to have a canonical CW post (or to add an / some CW answer(s) to the question you linked before to address also this and other cases). This way also this "category" of question could be closed in favor of the question you linked. I'm starting to agree with you on the fact that there are too many. – kos Sep 16 '15 at 10:20
  • 2
    @JacobVlijm I personally enjoy answering them, but I think that some "general enough" cases such as this one could be addressed by using a good duplicate – kos Sep 16 '15 at 10:20

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.

  • 1
    Hi Adonis, sorry, sorry, I didn't look properly into you answer. upvoted! – Jacob Vlijm Sep 16 '15 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.