Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a question concerning the renaming of multiple files in a folder. For about 200 files I would like to add the String 1_ to the beginning of all filenames. The filenames are, for example, DATASET_X_Y_Z and the result should be 1_DATASET_X_Y_Z. Maybe somebody knows how to do this the easy way. Unfortunately, I don't know a thing about Shell scripting, but maybe there is a one liner for the terminal.

Thanks!

share|improve this question
    
up vote 25 down vote accepted
  • rename 's/^/1_/' * for renaming all files in the current directory

or

  • rename 's/^/1_/' DATASET* for renaming all files in the current directory starting with DATASET in their name

Explanation: the expression s/^/1_/ says: "replace the beginning of the filename (that means this symbol -> ^)' with 1_".

share|improve this answer
    
perfect, just what i needed. Thanks – macydanim Jun 8 '11 at 11:23
    
If your rename doesn't do this out of the box, you need to install prename (PERL rename). – user1359 Jan 15 at 0:51

You can use pyRenamer. It can be found in the Ubuntu software center. enter image description here The original file pattern should be {X} and the renamed file pattern should be 1_{1}

share|improve this answer
    
One of my favourite programs – Allan Jul 15 '11 at 13:40

You can easily rename all the files in current directory typing (assuming you are using bash):

for i in *; do mv $i 1_$i; done

obviously take it with care; it will remane ALL the files in the current directory that are 'visible' (filename not starting with a '.')

share|improve this answer

Very easily to rename all the files in the current directory you can type (assuming you are using bash):

sample example

1st File name BookOFAmit.txt
2nd File name BookOFAmit1.txt and so on
want to change it to The_GREAT_BookOFAmit.txt_20150119 and The_GREAT_BookOFAmit1.txt_20150119

for i in *; do mv $i The_GREAT_BookOFAmit.$i_20150119;done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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