Posted By

tylerhall on 05/26/07


Tagged

regex file Bash rename


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

basicmagic
lukaszkorecki
moonbather
ascarion


Rename Multiple Files in Bash Using Regular Expressions


 / Published in: Bash
 

This small, bash script will loop though the specified files and rename them according to a sed regular expression. In this example, I'm renaming a bunch of .avi movie files.

  1. for i in *.avi
  2. do
  3. j=`echo $i | sed 's/find/replace/g'`
  4. mv "$i" "$j"
  5. done
  6.  
  7. Can also be written on a single line as
  8.  
  9. for i in *.avi; do j=`echo $i | sed 's/find/replace/g'`; mv "$i" "$j"; done

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: mind on May 26, 2007

prename is much simpler, and it is in the perl standard distributio that is installed in almost all unix systems. to use it: prename 's/find/replace/ files

enjoy

Posted By: jaduks on December 28, 2008

A post on rename can be found here : http://unstableme.blogspot.com/2008/09/bash-rename-command-rename-multiple.html Its useful.

Posted By: boondoklife on October 18, 2010

LOVE IT. This is just what I was looking for to complete my transmission script!

You need to login to post a comment.