Liam Delahunty: Home Tips Web Contact
Recommended laptop
under £500
.

Think I deserve a present? See my Amazon Wish List

Linux - Renaming Files

Renaming multiple files in a single directory

I tried the following "script" in a shell...


for i in `ls *.php`; 
do 
mv $i `echo $i|tr 'php3' 'php'`;
done

with the intention of renaming all the files in a folder from .php to .php... WRONG Instead, I now have *.phpp

(BTW I repaired my error with rename phpp php *.phpp)

This would have worked:

for file in *.php
do
mv $file `basename $file .php`.php
done

...or...

for i in *.php; do mv "$i" `echo "$i" | sed 's/\.php3$/.php/'`; done

Please also see how-to rename a single file or a directory

Share this!  



Linux Rename Directory | Linux Rename Files | Linux Search And Replace Multiple Files


 

  Tips | Home | Search | Contact

Link here: