How do I use the below properly: I want to find all files belonging to user and copy them in a folder.
find / -user Joe | xargs -I {} cp {} /home/Joe/Folder
The commands hangs and on ctrl C
it prints a 0 that represents something.
How do I use the below properly: I want to find all files belonging to user and copy them in a folder.
find / -user Joe | xargs -I {} cp {} /home/Joe/Folder
The commands hangs and on ctrl C
it prints a 0 that represents something.
find / -user Joe -exec cp {} /home/Joe/Folder \;
This will also copy for instance filenames with whitespace in them.
If you insist on using xargs as well:
find / -user Joe -print0 | xargs -0 -I{} cp {} /home/Joe/Folder
find
's option -print0
will make it terminate filenames with a nul
, while for xargs
-0
will make it accept (only) filenames ending in nul
. The effect of this is to ensure that for instance filenames with whitespace in them will also be seen correctly by xargs
, and will be acted upon accordingly (in this case copied elsewhere).
Finally, please be aware that your cp
command as is will not copy directories or their contents; you would need the additional cp
options -dR
. See man 1 cp
.