tail -f findings.out

« Generate Random Passwords on the Command Line

Find out why webpages load slowly »

File renaming made simpler

Some people have difficulty renaming lots of files at once on the command line. I used to experience this issue a lot, especially since “mv” was the command recommended. While I can appreciate why mv makes sense for renaming, it still was not intuitive for me. The original file is, in a sense, gone. Renaming a file can be seen as making a new file.

However, there is another command, nearly as available, which can rename things quite easily. You will never guess its name. Something simple, and descriptive of the action of renaming files…: rename! It syntax is easy:

rename 'PERL REGEX' FILELIST

The FILELIST can use regex as well. So if I wanted to renamed all of my Mahler “Symphony No. 1″ files (they all started with “_- Mahler”), I would simply run this in the folder the files were in:

rename 's/^\_\-\ Mahler/Mahler/' *.mp3

VoilĂ ! Now all my file names have been fixed in one fell swoop. An explanation of regex is not something I want or can do right now, but internet tutorials and articles on it are legion.

Share and Enjoy:
  • E-mail this story to a friend!
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Technorati
  • Netvibes

[Post to Twitter]  [Post to Delicious]  [Post to Digg]  [Post to Reddit] 

Possibly Related (no promises):

  1. Recursively ignoring multiple file patterns in subversion
  2. Easily sum matching file line counts
  3. Useful grep incantations
  4. View compressed log files easily
  5. An awesome xargs option and cleaning up SVN accidents

Related posts brought to you by Yet Another Related Posts Plugin.

Tags: , , ,
July 7, 2007 - 3:38 PM
1 comment »
Leave a reply

Subscribe without commenting