Thursday, 1 September 2011

Remove spaces from file names with Linux


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

No comments:

Post a Comment