Terminal find, rename by deletion Mac will append a ' 2' (note the space) to the end of a file/folder that is  a copy of another file/folder inside the same directory... I was wondering if anybody knows how to batch remove/rename this ' 2' from a directory of folders from Terminal.
Use find to locate files like this way:

find . -name "* 2" -exec rm -r "{}" \;


This command will search for files and folders from where your are . with name "* 2" and delete every result -exec rm {}.

If you want to rename directories:

find . -name "* 2" -type d -exec rename 's/ 2/-copy/g' {} \;


As other command, locate only folders with name "*.2" and rename it replacing 2 with -copy.

If you don't have rename installed, you can also use

find . -name "* 2" -type d -exec bash -c '[[ -x "${0/ 2/-copy}" ]] || mv "$0" "${0/ 2/-copy}"' {} \;


(The [[ -x part tests whether a file/folder already exists).