Skip to main content
deleted 31 characters in body
Source Link
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 | 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).

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
    [[ -x "${dir%% 2}" ]] || mv "$dir" "${dir%% 2}"
done

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

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

added 263 characters in body
Source Link
nohillside
  • 104.5k
  • 42
  • 222
  • 275

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
    [[ -x "${dir%% 2}" ]] || mv "$dir" "${dir%% 2}"
done

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

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.

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
    [[ -x "${dir%% 2}" ]] || mv "$dir" "${dir%% 2}"
done

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

added 220 characters in body
Source Link
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.

Use find to locate files like this way:

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

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

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.

added 5 characters in body
Source Link
jherran
  • 13.4k
  • 11
  • 59
  • 75
Loading
Source Link
jherran
  • 13.4k
  • 11
  • 59
  • 75
Loading