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 | while read dir; do
-exec bash -c [['[[ -x "${dir%%0/ 2/-copy}" ]] || mv "$dir""$0" "${dir%%0/ 2/-copy}"
done"' {} \;
(The [[ -x
part tests whether a file/folder without the " 2" already exists).