Bash – How to Remove Whitespace from All Items in a Directory and Subdirectory

bashfilesrecursiverename

I have a directory which contains files and sub directories, some of which have whitespace in their names. Further more each of these sub directories contains files with whitespace in their names. Is there a simple way to remove the whitespace from all the names in the parent directory and all sub directories at once?

Best Answer

Is there a simple way to remove the whitespace from all the names in the parent directory and all sub directories at once?

Yes there is:

find /tmp/ -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;

Further Reading

Good Luck!

Related Question