If the order of collided file suffixes does not need to give precedent to the pre-existing file then the following works for me:
bash/find/mv 8084 bytes, 16 spaces
find -depth -execdir bash -c '[ "${0//[^ ]}" ] && mv -{T,--b=t} "$0" "${0// }"' {} \;
bash/find/mv 7882 bytes, 14 spaces
find -depth -execdir bash -c '[ "${0//[^ ]}" ]&&mv -{T,-b=t} "$0" "${0// }"' {} \;
Cuddled &&
to save two space bytes.
bash/find/mv 5660 bytes, 11 spaces
find -d -execdir bash -c 'mv -{T,-b=t} "$0" "${0// }"' {} \;
Drops error protection so it gets errors from mv on files which have no spaces to start with.
Edit: Dropped the quotes from {}
as reminded by Dennis. Also allowed find
to scream about portability and deprecation in the shortest version where mv
is already screaming about moving a file on top of itself.
Edit 2: Added -T
to mv
command to avoid nesting directories instead of renaming as pointed out by pqnet. Used brace expansion at cost of one character over just using one space.