How to get rid of spaces in file names

If you want to get rid of the spaces in the file/directory names then just look at this simple script:


ls | grep "\ " | while read item
  new=`echo ${item} | tr [:blank:] _`
  mv "${old}" ${new}

Above mentioned script works in current directory for files and directories.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.