One-liner: How to remove spaces in file names

Spaces in file names are nasty and might prevent various script from working properly. Here’s a one-liner to replace spaces with underscore for all files in the current directory:

for $i in *
   file2=`echo "$i"| sed -e "s/ /_/g"`
   mv "$i" $file2

Leave a Reply

Your email address will not be published.