Thursday, December 18, 2003

Batch File Rename By File Extension in Unix

Batch File Rename By File Extension in Unix

These are one-liners which batch rename files meeting a certain criteria under unix
These are very powerful command line tools. They have been used on FreeBSD, Linux, and MacOSX with success. But as with any batch file changing, you are advised to use them with caution. Backups are your friend!

# change .htm files to .html
for file in *.htm ; do mv $file `echo $file sed 's/\(.*\.\)htm/\1html/'` ; done

# change .html files to .htm
for file in *.html ; do mv $file `echo $file sed 's/\(.*\.\)html/\1htm/'` ; done

#change .html files to .shtml
for file in *.html ; do mv $file `echo $file sed 's/\(.*\.\)html/\1shtml/'` ; done

#change .html files to php
for file in *.html ; do mv $file `echo $file sed 's/\(.*\.\)html/\1php/'` ; done"

5 comments:

André said...

For those that don't like sed:

## rename all .html files to .txt
for i in *.html ; do mv "$i" `basename "$i" .html`.txt ; done

formaldresses4us said...

Once again great post. You seem to have a good understanding of these themes.When I entering your blog,I felt this . Come on and keep writting your blog will be more attractive. To Your Success!
----------------------------------------------------------
Flower Girl Dresses|Empire Wedding Dresses|New Style Wedding Dresses

winnieqinjiaxin said...

Once again great post. You seem to have a good understanding of these themes.When I entering your blog,I felt this . Come on and keep writting your blog will be more attractive. To Your Success!

Classic Dresses
Classic Bridesmaid Dresses
Wedding Dresses with Sleeves
Flower Girl Dresses

Empire Wedding Dresses

Unknown said...

Thank you for blog.
-----------------
WOW Gold Buy WOW Gold Cheap WOW Gold RS Gold Runescape Gold

lulur bali joss said...

salam kenal bos. lagi jalan jalan pagi nih