Linux - Replacing spaces in the file names

Mithun Sreedharan picture Mithun Sreedharan · Nov 27, 2009 · Viewed 77.9k times · Source

I have a number of files in a folder, and I want to replace every space character in all file names with underscores. How can I achieve this?

Answer

neesh picture neesh · Nov 27, 2009

This should do it:

for file in *; do mv "$file" `echo $file | tr ' ' '_'` ; done