This is my problem: I have a folder with 500 images named:


and so on..

I copied that folder and now I need to rename those same pictures from 501 to 1000 but in order like this:

1.jpg  becomes    501.jpg
2.jpg  becomes    502.jpg
3.jpg  becomes    503.jpg          

When I use my standard renaming command:

i=501;for img in $(find . -iname '*.jpg'); do echo -n "Converting $img"; mv $img $i.jpg  && echo $i && ((i++)); done

It orders images from 501 to 1000 but they are all scattered:

23.jpg becomes 501.jpg,    
66.jpg becomes 502.jpg 

(they are in right order, but it mixes them up)

I know it's probably one command I'm missing...

  • Use 2 variables i and j mv $i.jpg $j.jpg and increment your variables. – Panther Aug 25 '17 at 17:12
  • thank you, hope you'll figure it out. I searched but didn't find the answer.. – Painkiller Aug 25 '17 at 17:12
  • Just curious, the original names, in what range are they? Should the original number just be renamed + 500? – Jacob Vlijm Aug 25 '17 at 17:15
  • Yes Jacob you +500. I am trying to write what bodhi told me but I am not so good in lnux, I killed my self to write the rename command above :D – Painkiller Aug 25 '17 at 17:17
  • My poor laptop is heavily occupied atm, but if no satisfying answer comes up (which I doubt :) ) and if you won't manage, I'll post a tiny python script tonight. – Jacob Vlijm Aug 25 '17 at 17:22

Try Thunar, which is the default file manager for Xfce. It is very lightweight and comes with a handy bulk renaming tool. You can install Thunar by running the following command in Terminal:

sudo apt-get install thunar

You'll probably be able to install from Ubuntu Software too.

How to use the utility

  1. Once you've installed Thunar, launch the Bulk Rename utility.
  2. Click on the + icon and add the files you want to rename in the proper order.
  3. Click on the drop-down box just below the list of selected files and select Numbering. Click on the box next to it and select Name Only.
  4. In the "Start With:" box enter 501, leave the "Text:" box empty. You should see the preview of the changes in the New Name column.
  5. To apply the changes click on the Rename Files button.

Besides Numbering this utility supports the following actions:

  • Insert Date / Time
  • Insert / Overwrite
  • Remove Characters
  • Search & Replace
  • Uppercase / Lowercase
  • Thanks man you're the MVP! I only have to add that I also needed to change Text format to: Text - Number. (just in case anyone else use this) – Painkiller Aug 25 '17 at 17:30
  • 2
    To Switch fm to... perform a simple task seems overkill to me. Writing a simple nautilus script extension takes less time then switching fm. – Jacob Vlijm Aug 25 '17 at 17:40
  • 1
    @JacobVlijm I'm using Thunar just for the bulk rename tool along with Nautilus. Thunar is pretty light and doesn't seem to cause any conflict with Nautilus or other file managers. – pomsky Aug 25 '17 at 17:45
  • 4
    If you don't want a second file manager, pyrenamer works perfectly and is what I use for bunk renames when I want a GUI to compare before/after output. – Tom Brossman Aug 25 '17 at 17:48

The find command finds files in 'directory' order (23.jpg, 66.jpg, ...). you could put a |sort after the find.

But your methods are overcomplex.

for i in $( seq 1 500 ) ; do
    j=$(( $i + 500 ))
    mv $i.jpg $j.jpg
  • 3
    for i in {1..500}; do ... would have bee easier. – David Foerster Aug 26 '17 at 13:40

With rename command.

rename -n 's/^(\d+)/sprintf("%d",$1+500)/e' *.jpg

Or in pure bash and using shell parameter expansion.

for FILE in *.jpg; do
    mv "$FILE" "$(( ${FILE%.jpg}+500 )).jpg" 

If I've understood what you are asking correctly, I think you can do it using the default rename tool:

rename 's/^(\d+)/sprintf("%d",$1+500)/e' *.jpg -vn

You should remove the -vn (verbose - no action) switch after testing, to make the change effective.

  • How can one install this tool in Ubuntu? by default rename is linked to prename(1) from the perl package which doesn't support all these command-line options. – David Foerster Aug 26 '17 at 13:45
  • @DavidFoerster You may be right. I couldn't find a current installation link (I haven't used it since about 2014). With the default rename tool, I think the regex expression should be 's/^(\d+)/sprintf("%d",$1+500)/e'. I'll update my answer accordingly. Thanks. – sempaiscuba Aug 26 '17 at 14:11
  • 1
    Your answer is now a duplicate of AFSHIN’s. – David Foerster Aug 26 '17 at 14:22
  • @DavidFoerster Sorry, what answer? The only other answers I can see are by pomsky & waltinator. Neither use rename (either version). – sempaiscuba Aug 26 '17 at 14:26
  • The direct link to the answer I mean is included in my previous comment. – David Foerster Aug 26 '17 at 14:28

Another way of achieving this with just shell command

count=1;for i in ls; do mv $i CN$((count++)).${i##*.}; done

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.