Posted By

tylerhall on 05/26/07


Tagged

regex file Bash rename


Versions (?)


Advertising

Website Promotion DIRECTORY is a crucial factor for all websites that need to gain better organic search engine rankings and increase website traffic.
Submitting your website as part of your Web Promotion strategy to our SEO friendly and high traffic Business Directory for review is an excellent way to gain a valuable backlink and increase your websites visibility online.

Submit Site


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.

Expand | Embed | Plain Text
  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.

You need to login to post a comment.

Download royalty free graphics