-1

I need to rename a bunch of files (more than 100) on an Ubuntu system, and want to know how to I do that when the pattern of the files is something like "Filename_01.jpg" to "NameOfFile_01.jpg" In Windows, I would type:

ren Filename_*.jpg NameOfFile*.jpg 

Because of the convoluted way the various commands I have found (rename, mmv, etc.) work, and the syntax examples, I can't make heads or tails of those commands. I don't need to full explanation of how the command works, I just need the exact syntax to do this.

terdon
  • 242,166
  • 2
    If you provide a representative sample of both your input filename list and of your expected renamed output filename list, it'll be easier on those willing to help. – Cbhihe Sep 23 '23 at 19:49
  • Look at the code block, it shows that: ren Filename_.jpg NameOfFile.jpg. I want to rename every file that starts with Filename_ to NameOfFile_ – Tornado726 Sep 23 '23 at 19:51
  • 1
    I and others have multiple possible solutions for you. You will get one or the other depending on the actual list of files and target names... Or are the input filenames all built with the same prefix "filename_" and the output all equally prefixed with "NameOfFile_" ? (which would be a rather weird naming scheme anyway). – Cbhihe Sep 23 '23 at 20:00
  • 1
    @Tornado726 the resulting filename in the question and the comments don't match - just saying. – tink Sep 23 '23 at 20:16
  • I am using a placeholder filename for the old and new filenames. A filename might be something like FileName_01.jpg or FileName02.jpg. I want to rename FileName_01.jpg to NameOfFile_01.jpg and FileName_02.jpg to NameOfFile_02.jpg, etc.The actual filenames might change each time I need to run the command. In the question, I typed the command syntax for the Windows 'ren' command. – Tornado726 Sep 24 '23 at 03:27
  • 1
    Next time @Tornado726 please update your question instead of providing information in the comments. Put everything in one place so it's easy for people to help you – Chris Davies Sep 24 '23 at 12:52

1 Answers1

1

One approach (depending on the distro the rename will have a different syntax, this is from the default in the debian family):

tink@box1:~/tmp$ ls
ranting          filename_17.jpg  filename_27.jpg  filename_37.jpg  filename_47.jpg
blub             filename_18.jpg  filename_28.jpg  filename_38.jpg  filename_48.jpg
ds_words.de      filename_19.jpg  filename_29.jpg  filename_39.jpg  filename_49.jpg
ds_words.es      filename_1.jpg   filename_2.jpg   filename_3.jpg   filename_4.jpg
filename_10.jpg  filename_20.jpg  filename_30.jpg  filename_40.jpg  filename_50.jpg
filename_11.jpg  filename_21.jpg  filename_31.jpg  filename_41.jpg  filename_5.jpg
filename_12.jpg  filename_22.jpg  filename_32.jpg  filename_42.jpg  filename_6.jpg
filename_13.jpg  filename_23.jpg  filename_33.jpg  filename_43.jpg  filename_7.jpg
filename_14.jpg  filename_24.jpg  filename_34.jpg  filename_44.jpg  filename_8.jpg
filename_15.jpg  filename_25.jpg  filename_35.jpg  filename_45.jpg  filename_9.jpg
filename_16.jpg  filename_26.jpg  filename_36.jpg  filename_46.jpg

tink@box1:~/tmp$ rename -e 's/filename_/NameOfFile_/' *jpg

tink@box1:~/tmp$ ls ranting NameOfFile_17.jpg NameOfFile_27.jpg NameOfFile_37.jpg NameOfFile_47.jpg blub NameOfFile_18.jpg NameOfFile_28.jpg NameOfFile_38.jpg NameOfFile_48.jpg ds_words.de NameOfFile_19.jpg NameOfFile_29.jpg NameOfFile_39.jpg NameOfFile_49.jpg ds_words.es NameOfFile_1.jpg NameOfFile_2.jpg NameOfFile_3.jpg NameOfFile_4.jpg NameOfFile_10.jpg NameOfFile_20.jpg NameOfFile_30.jpg NameOfFile_40.jpg NameOfFile_50.jpg NameOfFile_11.jpg NameOfFile_21.jpg NameOfFile_31.jpg NameOfFile_41.jpg NameOfFile_5.jpg NameOfFile_12.jpg NameOfFile_22.jpg NameOfFile_32.jpg NameOfFile_42.jpg NameOfFile_6.jpg NameOfFile_13.jpg NameOfFile_23.jpg NameOfFile_33.jpg NameOfFile_43.jpg NameOfFile_7.jpg NameOfFile_14.jpg NameOfFile_24.jpg NameOfFile_34.jpg NameOfFile_44.jpg NameOfFile_8.jpg NameOfFile_15.jpg NameOfFile_25.jpg NameOfFile_35.jpg NameOfFile_45.jpg NameOfFile_9.jpg NameOfFile_16.jpg NameOfFile_26.jpg NameOfFile_36.jpg NameOfFile_46.jpg

On Ubuntu you need to install the rename package:

sudo apt install rename
terdon
  • 242,166
tink
  • 6,765