Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 16 down vote accepted

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/
share|improve this answer
2  
The exclude is relative to the "source" directory I believe, so those excludes should really be: --exclude '.ccache' --exclude 'build'. The way they are written above, they would be excluding: "/home/ben/home/ben/.ccache" which is not what is wanted. –  Seanchán Dec 1 '13 at 22:38
    
Yes you're right! I fixed the example. Thanks! –  Freedom_Ben Dec 2 '13 at 2:52

When having multiple directories and/or files to exclude, make a text file and use the "--exclude-from" switch. Make a file called exclude_me.txt and in it list your exclusions. Example:
/home/ben/exclude_me.txt .ccache build .java .gvfs .xsession-errors
Then your rsync would look something like:


rsync -arv --exclude-from '/home/ben/exclude_me.txt'/home/ben /media/ben/thumbdrive/

This may also help:


/dir/ means exclude the root folder /dir
/dir/* means get the root folder /dir but not the contents
dir/ means exclude any folder anywhere where the name contains dir/
Examples excluded: /dir/, /usr/share/mydir/, /var/spool/dir/
/dir means exclude any folder anywhere where the name contains /dir
Examples excluded: /dir/, /usr/share/directory/, /var/spool/dir/
/var/spool/lpd//cf means skip files that start with cf within any folder
within /var/spool/lpd
share|improve this answer
    
Good tip, thanks! +1 –  Freedom_Ben May 19 at 22:01

This should also work:

sync -arv --exclude={.ccache,build} /home/ben /media/ben/thumbdrive/
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.