//View Tip #47
Similar Tips
» another solution to #67
» My code is compiling
» Close shell keeping all subprocess running
» Command line currency conversion
» Bash fork bomb


Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Rename replaces string X in a set of file names with string Y.

rename 's/.html$/.php/' *.html

This will change the extension of every .html file in your CWD to .php.

View Comments »


Add your comment

Comments are currently disabled
this appears to be incorrect.  I hand-typed the command, that did not work.  I copied and pasted from the page into the command line, that did not work.  There appears to be a missing piece to this.
Posted 2008-11-14 19:01:21
from "man rename" on ArchLinux:

      The rename command is part of the util-linux-ng package and is available from ftp://ftp.kernel.org/pub/linux … -linux-ng/.
Posted 2009-02-12 10:29:15
@ehannah- 'rename' uses Perl regex, which means the '.' matches any character. Escape it, and you'll be golden.

$ rename 's/\.html$/\.php/' *.html
Posted 2009-03-11 20:20:00
This seems to be overly complicated, on my system rename work like:

rename .html .php *.html
Posted 2009-03-19 10:11:46
Pablo Martinez
In pure bash
for F in *.html ; do mv "$F" "${F%.html}.php" ; done
Posted 2009-03-23 22:21:16

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit