space_to_underscore
space_to_underscore copied to clipboard
no need to use "grep" to find eligible files
Nice script... I was looking to do this exact thing today.
I have these two lines in my $HOME/.bashrc, because I rename files so much.
function nospace () { local x="$1" ; mv -v "$x" "${x// /_}" ; }
function nospaces () { for x in *\ * ; do mv -v "$x" "${x// /_}" ; done ; }
This script is a nice addition.
Actually, I think this line will do it all in one go. Your hint that "find" will print the directories before it descends and prints the files was what made it click for me.
find | grep ' ' | while read item ; do d=$(dirname "$item") ; f=$(basename "$item") ; mv -v "${d// /_}/$f" "${item// /_}" ; done