Last active
August 29, 2015 14:09
-
-
Save leftclickben/6550e269edc7a64dfac3 to your computer and use it in GitHub Desktop.
Rename whitespace in files to underscores, with any level of nesting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.