2 added 115 characters in body
source | link

When using -exec ... {} +, the {} must be at the end, just before the +.

This means that you would have to use

-exec mv -t cheatSheet {} +

which would require access to GNU mv. Without GNU mv, you would use

-exec mv {} cheatSheat \;

to move one file at a time, or

-exec sh -c 'mv "$@" cheatSheet' sh {} +

to call an in-line script that moves all files in one go.

You additionally don't need -iregex. The following will be easier to read and understand:

find "$HOME" -ipath '*cheat*.pdf' \
    -exec sh -c 'mv "$@" cheatSheet' sh {} +

or, for clarity, either one of the following which does what you actually mean (it depends on whether you want cheat to be part of the filename at the end of the path (the first alternative), or one of the directory names in the path (the second alternative)):

find "$HOME" -iname '*cheat*.pdf' \
    -exec sh -c 'mv "$@" cheatSheet' sh {} +

find "$HOME" -ipath '*cheat*/*' -iname '*.pdf' \
    -exec sh -c 'mv "$@" cheatSheet' sh {} +

Note that -ipath is a GNU find extension, but that -iname, though non-standard, is more commonly implemented.

Related:

When using -exec ... {} +, the {} must be at the end, just before the +.

This means that you would have to use

-exec mv -t cheatSheet {} +

which would require access to GNU mv. Without GNU mv, you would use

-exec mv {} cheatSheat \;

to move one file at a time, or

-exec sh -c 'mv "$@" cheatSheet' sh {} +

to call an in-line script that moves all files in one go.

You additionally don't need -iregex. The following will be easier to read and understand:

find "$HOME" -ipath '*cheat*.pdf' \
    -exec sh -c 'mv "$@" cheatSheet' sh {} +

or, for clarity, either one of the following which does what you actually mean (it depends on whether you want cheat to be part of the filename at the end of the path (the first alternative), or one of the directory names in the path (the second alternative)):

find "$HOME" -iname '*cheat*.pdf' \
    -exec sh -c 'mv "$@" cheatSheet' sh {} +

find "$HOME" -ipath '*cheat*/*' -iname '*.pdf' \
    -exec sh -c 'mv "$@" cheatSheet' sh {} +

Related:

When using -exec ... {} +, the {} must be at the end, just before the +.

This means that you would have to use

-exec mv -t cheatSheet {} +

which would require access to GNU mv. Without GNU mv, you would use

-exec mv {} cheatSheat \;

to move one file at a time, or

-exec sh -c 'mv "$@" cheatSheet' sh {} +

to call an in-line script that moves all files in one go.

You additionally don't need -iregex. The following will be easier to read and understand:

find "$HOME" -ipath '*cheat*.pdf' \
    -exec sh -c 'mv "$@" cheatSheet' sh {} +

or, for clarity, either one of the following which does what you actually mean (it depends on whether you want cheat to be part of the filename at the end of the path (the first alternative), or one of the directory names in the path (the second alternative)):

find "$HOME" -iname '*cheat*.pdf' \
    -exec sh -c 'mv "$@" cheatSheet' sh {} +

find "$HOME" -ipath '*cheat*/*' -iname '*.pdf' \
    -exec sh -c 'mv "$@" cheatSheet' sh {} +

Note that -ipath is a GNU find extension, but that -iname, though non-standard, is more commonly implemented.

Related:

1
source | link

When using -exec ... {} +, the {} must be at the end, just before the +.

This means that you would have to use

-exec mv -t cheatSheet {} +

which would require access to GNU mv. Without GNU mv, you would use

-exec mv {} cheatSheat \;

to move one file at a time, or

-exec sh -c 'mv "$@" cheatSheet' sh {} +

to call an in-line script that moves all files in one go.

You additionally don't need -iregex. The following will be easier to read and understand:

find "$HOME" -ipath '*cheat*.pdf' \
    -exec sh -c 'mv "$@" cheatSheet' sh {} +

or, for clarity, either one of the following which does what you actually mean (it depends on whether you want cheat to be part of the filename at the end of the path (the first alternative), or one of the directory names in the path (the second alternative)):

find "$HOME" -iname '*cheat*.pdf' \
    -exec sh -c 'mv "$@" cheatSheet' sh {} +

find "$HOME" -ipath '*cheat*/*' -iname '*.pdf' \
    -exec sh -c 'mv "$@" cheatSheet' sh {} +

Related: