Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

Remove spaces from file names with Linux

Date: 2011-07-25 00:00:00 -0400

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

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.