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 *
do
   mv "$i" ${i// /_}
done

Leave a Reply

Your email address will not be published. Required fields are marked *