Remove White Spaces from Filesnames in Bash

Filenames with white spaces are kind of difficult to handle for some applications in Linux, so here’s a small “for loop” that can be used right from the shell. It renames all files in current directory while replacing white space for underscore “_”.

for i in *; do
> new="$(echo $i | tr ' ' '_')"
> mv "$i" $new
> done
Share This!

Add a Comment

Your email address will not be published.

Sign up for our Newsletter

Download "Google Search Pro"

Enter your email and stay on top of things,