So… Lets say You have folder Dupa in Your home folder and inside that folder – chaos… ;). Files with spaces in the file and folder names. You want to sanitize them and rename them so that they all contain _ instead of space? Do this:
Run:
cd ~/Dupa/
And then run:
find . -depth -name '* *'
| while IFS= read -r f ; do mv -i "$f" "$(dirname "$f")/$(basename "$f"|tr ' ' _)" ; done
This is a ONE command. Both lines.
Repeat until all the files and directories are renamed properly. I had to run this command several times before the chaos got whipped into a sensible shape.
If You want to check if there are any files or folders with spaces in the name left run:
find . | grep ' '
Cheers.
Andrzej
Source? https://stackoverflow.com/questions/2709458/bash-script-to-replace-spaces-in-file-names