Remove spaces from file names with Linux

Written by
Date: 2011-07-25 11:36:30 00:00


I've been using this line to remove spaces from file names in Linux.

Usually Windows users like to add spaces in the file names, I prefer dashes (-) or under scores (_) instead, they are easy to manage in the console.

I've found this command a long time ago in a forum, and still have it on my personal notes.

Here posted for everybody:

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