How do I run find
and cp
commands concurrently? I have tried this:
find -name "*pdf*" | xargs cp $1 ./
But it doesn't work.
How do I run find
and cp
commands concurrently? I have tried this:
find -name "*pdf*" | xargs cp $1 ./
But it doesn't work.
Use
-exec
option:The
{}
is replaced with the current file names being processed.From the man page for
find
:Note the use of
-t
(target directory) option (which is a GNU extension). We cannot use-exec cp {} . +
, because the matched file names are appended to the end of the command line, while destination would have to be specified last. Another workaround is to invokesh
:I have habitually escaped the
+
character. Note, you should escape special characters of thefind
syntax to protect them from expansion by the shell. In particular, there is likely no need in backslash before+
, because most shells will interpret it as a string (it will not be expanded to something different). However, you will definitely have to escape/quote the;
(which applies the command to each file sequentially):