Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Rename whitespace in files to underscores, with any level of nesting
maxdepth=`find . -printf '%d\\n' | sort -n | tail -1` && for depth in `seq 1 $maxdepth`; do find -mindepth 1 -maxdepth $depth -exec bash -c 'f=`echo "{}" | sed -r s:\\\s+:_:g` ; if [ "$f" != "{}" ]; then mv "{}" "$f"; fi' \; ; done

This comment has been minimized.

Copy link
Owner Author

leftclickben commented Nov 12, 2014

I'm sure this isn't the shortest code to achieve the result, but it does handle the case where a file or directory with spaces is nested inside another directory with spaces (to any level of recursion). It does this simply by processing one level of depth at a time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.