Ubuntu: How to exclude multiple directories with rsync?
Channel: Roel Van de Paar
Date: 20/06/2019

Ubuntu: How to exclude multiple directories with rsync?


Question: I am trying to backup my home directory using rsync, and I want to exclude some
of the directories that contain junk. I want to specifically exclude /home/
ben/.ccache and /home/ben/build. Unfortunately the documentation for rsync was
information overload and didn't answer my question. This is what I tried:
rsync -arv --exclude "/home/ben/.ccache:/home/ben/build" /home/ben /media/ben/
thumbdrive/
What is the right way to do this?

Solutions Sample (Please watch the whole video to see all solutions, in order of how many people found them helpful):

== This solution helped 208 people ==
OK I feel really dumb. Before I even posted this question my friend showed me
how to do it and it is really simple. To exclude multiple directories you just
use multiple --exclude=path switches. So my command above properly written is
as follows:
rsync -arv --exclude=.ccache --exclude=build /home/ben /media/ben/thumbdrive/

== This solution helped 69 people ==
You can also exclude multiple paths within curly braces:
rsync -arv --exclude={.ccache,build} /home/ben /media/ben/thumbdrive/

With thanks & praise to God! With thanks to all the many who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music & music license: https://www.bensound.com/royalty-free-music | Images & images license: https://stocksnap.io/license and others | With thanks to user user228759 (https://askubuntu.com/users/228759), user tripleee (https://askubuntu.com/users/25077), user György Ráth (https://askubuntu.com/users/328108), user Freedom_Ben (https://askubuntu.com/users/136192), user Freedom_Ben (https://askubuntu.com/users/136192), user bryan kennedy (https://askubuntu.com/users/244567), and the Stack Exchange Network (http://askubuntu.com/questions/320458). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything should be amiss at Roel D.OT VandePaar A.T gmail.com.