space_to_underscore icon indicating copy to clipboard operation
space_to_underscore copied to clipboard

no need to use "grep" to find eligible files

Open sudoer opened this issue 3 years ago • 1 comments

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.

sudoer avatar Dec 04 '21 16:12 sudoer

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

sudoer avatar Dec 04 '21 16:12 sudoer