Web Dev Blog

Looking for help with WordPress, Apache, Vim, Web Security and more. Here are a few tips.

Removing Special Characters From Linux Filenames

This goes with the previous post concerning converting files from flac to mp3. Sometimes filenames have characters beyond spaces that make it difficult to work with in a script. If you want to rename your files without annoying special characters, use the following command.

for f in *
do
mv "$f" $(echo $f | sed -e 's/[^A-Za-z0-9._-]/_/g')
done

This will replace every non-alphanumeric character in the filename with an underscore _

Leave a Reply