Wednesday, February 9, 2011

Bulk rename files in Linux

Use the rename command :

To add the album title at the beginning :$ rename -v 's/^/TITLE-HERE-/' *.mp3

-v : verbose
s : substitute. it acts in the same way as regular expressions do in SED.

To replace a part of filename: $ rename -v 's/MISC\.\ -/Fossils-/' *.mp3

e.g. :-
MISC. - 01.mp3 to Fossils-01.mp3
MISC. - 02.mp3 to Fossils-02.mp3
MISC. - 03.mp3 to Fossils-03.mp3

To rename to lower case: $ rename 'y/A-Z/a-z/' *

To rename recursively: $ find ./ -type f -exec rename 'y/A-Z/a-z/' {} \;

No comments:

Print chess board in command line

The following bash one-liner will print a chess board in a terminal (the script works for the shells bash and ksh only) for (( i = 1; i ...