Sunday, February 28, 2010

How to remove empty spaces in filenames

One of my friends gave me a collection of mp3 files last week . The files were ripped and converted to mp3 on windows platform. Even though music was excellent, the files or rather file names were not very pleasing . They all had empty spaces in in the file names. Some of them looked like this.
"my mp3 collection file1.mp3"
As I am using Ubuntu , I decided to strip of the empty spaces and put under score instead. The command for this is

rename "s/ /_/g" "my mp3  collection file1.mp3"

This worked for files with single spaces. There were some files with multiple spaces like
"my mp3 collection file1.mp3" . The above command will put under score for each space. Try the following command.


rename 's/\ * /_/g' "my mp3 collection file1.mp3"

This will fix multiple spaces with a single under score. This hack can work on all unix variants.

1 comment:

Anonymous said...

try pyrenamer!