How to recursively copy directories starting with "abc" on Linux/Unix? How to recursively copy directories starting with "abc" on Linux/Unix? linux linux

How to recursively copy directories starting with "abc" on Linux/Unix?


Not sure why what you're trying didn't work (but what is the "copy" command?), but this works on Linux at least:

cp -r ~/plugins/abc* ~/destination


Here is an old trick I still use frequently:

 (cd ~/plugins/ && tar cfp - abc/) | (cd ~/destination && tar xfpv -)

where the p preserves attributes, and ~/destination can be anywhere.


It is possible to use the output of find with rsync:

# warning: untestedfind ~/plugins/ -type d -name "abc*" -print0 | rsync -av --files-from=- --from0 ~/plugins/ ~/destination
  • the -print0 in find, and --from0 in rsync makes sure that we handle files with spaces correctly
  • the --files-from=- states that we are reading a list of files from stdin