How to exclude directories while using rsync

Sometimes when you copy a lot of data with rsync you may to exclude some sub-directories.
You can do this by using –exclude.
For instance, you want to copy files from /mnt to /home/destination_dir/, and you want to exclude directory /mnt/dir1/dir2/.

rsync -az --exclude='dir1/dir2/' /mnt/ /home/destination_dir/

A lot of users do mistake when specifing path. This path should be relative to source directory (/mnt in our case).

Didn’t find the answer to your question? Ask it our administrators to reply we will publish on website.

Leave a Reply

Your email address will not be published. Required fields are marked *