//View Tip #231
Similar Tips
» Find files by modified time
» Moved Trac and Subversion repositories to another machine/direct
» Pipe files to an archive
» Delete old files
» Find and Grep


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 a lot of files at once:
find . | perl -ne'chomp; next unless -e; $oldname = $_; s/aaa/bbb/; next if -e; rename $oldname, $_'

Change 'aaa' and 'bbb' to what you want to find and replace in the filename

View Comments »


Add your comment

Comments are currently disabled
Don't necessarily need Perl for this.

Suppose you want to rename .JPEG files to .jpg -- I'd do something like this (in bash):

find . -name \*.JPEG | while IFS= read -r f; do
  echo mv "$f" "${f%.JPEG}.jpg"

Remove the "echo" when you're ready to actually perform the commands.
Posted 2008-11-13 17:47:57

or pipe it to bash !

find | while read f; do echo mv "$f" "${f//aaa/bbb}"; done | bash
Posted 2009-06-02 22:41:11

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit