Saturday, July 7, 2007

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.

1 Comments:

Blogger Jadu Kumar Saikia said...

This is indeed very helpful :-)

December 27, 2007 at 4:53 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home