Rename multiple files on linux

So I have a folder with several files named like this:

name_file_00000.jpg  
name_file_00001.jpg  
name_file_00002.jpg  
name_file_00003.jpg  
...  
name_file_00080.jpg

And I want to rename this files like this:

name_file_00000.jpg ==> name_file_00001.jpg  
name_file_00001.jpg ==> name_file_00002.jpg  
name_file_00002.jpg ==> name_file_00003.jpg  
...  
name_file_00080.jpg ==> name_file_00081.jpg

How can I do that in Linux with a single command?

1 answer

  • answered 2018-05-16 04:43 marcel.js

    Try this: a simple for loop, which loops from 80 to 00 and ueses the mv command. It has to loop backwards, because you can't rename the file_name_00000.jpg to file_name_00001.jpg while file_name_00001.jpg isn't renamed already.

    for i in `seq -sw 0 80`; do mv "file_name_000$i.jpg file_name_000$[i+1].jpg"; done