I want to exclude two directories while copying.
Example:
$ ls /root/tmp
a b c d e f    
I want to exclude directories a and b:
$ cp -rp /root/tmp/ /root/tmp1/
I want to exclude two directories while copying.
Example:
$ ls /root/tmp
a b c d e f    
I want to exclude directories a and b:
$ cp -rp /root/tmp/ /root/tmp1/
 
    
     
    
    rsync can be used to exclude multiple directories like this:
rsync -av --exclude=/root/tmp/a --exclude=/root/tmp/b /root/tmp/ /root/tmp1/
with cp command
cp -r /root/tmp/!(a | b) /root/tmp1/
Execute  shopt -s extglob  before cp command to enable ! in cp
 
    
    Try the below rsync it works for me on ubuntu 14.04
rsync -av --exclude='/root/tmp/a' --exclude='/root/tmp/b' 
/path/to/include /path/to/include /path/to/destination
 
    
    You could exclude the directories as part of find results before the copy, but using rsync or cp with the '!' support enabled as suggested by Sathiya is a much simpler solution. 
See find example below:
find /root/tmp/ -mindepth 1 -maxdepth 1 -type d ! -regex '\(.*a\|.*b\)' -exec cp -r {} /root/tmp1/ \;
 
    
     
    
    You can do this in bash (does not work in sh):
shopt -s extglob
cp -r !(somefile|somefile2|somefolder) destfolder/
