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:

#!/bin/bash

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

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.

Gdansk, Poland https://sleeplessbeastie.eu