Categories
Linux shell

Remove spaces or Edit chracters in filenames

Needed  to remove spaces from filenames, so here we are 🙂

for file in *.mp3; do mv "$file" `echo $file | sed -e 's/  */_/g' -e 's/_-_/-/g'`; done

or replace all spaces by _ using perl

ls *.bed |perl -ne 'use File::Copy;chomp;$old=$_;s/\s+/_/g;move($old,$_);'

remove underscores

rename 's/2012mp3/2012/' *.mp3

Remove the letters mp3 from middle fo filename say in case of 123-20121mp3.mp3 or some such

for i in *.mp3; do mv $i ${i//[[:punct:]]/}; done

remove punctuations from filename. WARNING it will also remove the . from extension names.

for foobar in *.mp3 ; do
temp=`echo "$foobar" | cut -c 2-`
mv "$foobar" "$temp" ;
done

remove first X characters from file name. change the 2 to any number to change the first characters removed. the formula for that is 1 + actual number. make sure to change the extension.

rename 's/1234/12-34/' *.mp3

remove some character from the middle of the file name, in this case the dash ( – ).

Leave a Reply

Your email address will not be published. Required fields are marked *