I have 1 directory with 9 subdirectories and 10 files. Subdirectory have next level subdirectories and files.
/home/directory/
/home/directory/subdirectory1
/home/directory/subdirectory2
...
/home/directory/subdirectory9
/home/directory/file1
...
/home/directory/file10
I want to copy all subdirectories and files recursivly excluding:
/home/directory/subdirectory5
/home/directory/subdirectory7
What is the best way for it?
rsync -avz --exclude subdirectory5 --exclude subdirectory7 /home/directory/ target-path
I don't know a good way of doing it with cp
, but it's fairly easy using rsync
and the --exclude
switch.
Maybe the find
command will help you:
$ find /home/directory -mindepth 1 -maxdepth 1 -name 'subdirectory[57]' -or -exec cp -r {} /path/to/dir \;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With