-1

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?

  • Just write a shell script to calculate the expected file name and do `mv` move command. – Samuel Toh May 16 '18 at 04:30
  • with a for loop and the mv command in a shellscript – marcel.js May 16 '18 at 04:33
  • Possible duplicate of [Rename all files in directory from $filename\_h to $filename\_half?](https://stackoverflow.com/questions/7450818/rename-all-files-in-directory-from-filename-h-to-filename-half) – James Whyte May 16 '18 at 04:39
  • Stack Overflow is not a code writing service. Please show your code. Since Stack Overflow hides the Close reason from you: *Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/).* – jww May 17 '18 at 01:27

1 Answers1

1

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
marcel.js
  • 313
  • 2
  • 12