LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Renaming group of files within one directory (http://www.linuxquestions.org/questions/linux-general-1/renaming-group-of-files-within-one-directory-484817/)

DIRdiver 09-18-2006 11:09 PM

Renaming group of files within one directory
 
Hi , was wondering if anyone knew of a spiffy way to say take a group of files all within 1 directory and say rename them to say keep all there filenames the same and just append a word to them all for example:

file1.pdf
file2.pdf
file3.pdf
file4.pdf
file5.pdf

I want to say append scuba to all of these files in one fawl swoop.

tia

trickykid 09-19-2006 06:01 AM

You could use the `basename` or `rename` command or a `for BLAH in "list"` loop would work..


Code:

for FILE in 'file1.pdf file2.pdf file3.pdf`
do
mv $FILE $FILE.scuba
done

This would rename file1.pdf to file1.pdf.scuba

And say if you have a bunch of files named the same but just have sequential numbers (file1 file2 file3 file4), you can make things easier on you by doing something like this:

Code:

for BLAH in `seq 1 10`
do
mv filename$BLAH newfilename$BLAH
done

Try searching this su bject matter, it's asked quite frequently and plenty of known good scripts out on the net, etc.

DIRdiver 09-19-2006 09:53 PM

Thank you very much TrickyKid worked great ..

penguin_powered 10-25-2006 10:57 AM

Here's how you can rename a long list of files (adding .scuba to the end of the name) in a single command.

for i in *.pdf;do mv $i ${i%}.scuba;done

John


All times are GMT -5. The time now is 10:27 PM.