Skip to main content
5 of 5
deleted 31 characters in body
jherran
  • 13.4k
  • 11
  • 59
  • 75

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).

jherran
  • 13.4k
  • 11
  • 59
  • 75