Remove white space from file name and rename it with bash command

Some Linux tools does not properly work with files which include spaces in their names. This simple bash for loop will remove white space from file names and rename/move for all files in the given directory.

First enter directory with cd:

cd /my/directory

and then run:

for f in *; do mv "$f" `echo $f | tr ' ' '_'`; done

One Response to “Remove white space from file name and rename it with bash command”

  1. Google is great, but would be nothing without you! Thanks for the awesome tip.

Leave a Reply

You must be logged in to post a comment.