cp dir recursivly excluding 2 subdirs

dr0zd picture dr0zd · Feb 27, 2012 · Viewed 21.4k times · Source

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?

Answer

kjohri picture kjohri · Aug 22, 2012
rsync -avz --exclude subdirectory5 --exclude subdirectory7 /home/directory/ target-path