How to move output of find command to another directory?
You don't need any pipe-ing, and xargs
to make the filenames as arguments for mv
.
Just use mv
within the -exec
action of find
:
find /home -type f -name '*.pdf' -exec mv -t /destination {} +
- Replace
/destination
with the actual destination directory -
find
will handle all possible filenames -
find
will handleARG_MAX
by passing as many filenames in one go so that does not triggerARG_MAX
- If you are looking for only files (presumably in this case), limit the search vector by adding
-type f
- Quote the glob expansion,
'*.pdf'
, so that shell does not expand them beforehand asfind
will handle them
If for some weird reason, or for learning purpose, you must use pipe-xargs
:
find /home -type f -name '*.pdf' -print0 | xargs -0 mv -t /destination