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:
  • email
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Technorati
  • Netvibes

Post to Twitter Post to Delicious Post to Digg Post to Reddit

Possibly Related (no promises):

  1. Easily sum matching file line counts
  2. Useful grep incantations
  3. Useful ways to list directory contents

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

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.