exclude directories when tarring with tar in Ubuntu
November 4, 2007
I thought I’d post a working example showing the exact syntax for excluding directories with tar.
I had trouble getting it to work and none of the examples I found on the internets worked correctly in Ubuntu.
tar \
- -exclude=/home/username/My_Music \
- -exclude=/home/username/Desktop \
- -exclude=/home/username/.trash \
-cvpzf home_bup.tgz /home/username
hope this helps someone.

January 8, 2008 at 1:52 pm
Hi,
Thanks yaar. It works. but it should have been –exclude instead of -exclude.
January 9, 2008 at 12:41 pm
that’s a problem with this font. I did have two dashes. should have tried to make that clearer (I’ll do so now).
thanks for pointing that out.
March 3, 2009 at 8:06 am
Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru
March 13, 2009 at 12:47 pm
it`s very annoying to use exclude like this
tar \
- -exclude… \
- -exclude… \
- -exclude… \
…
- -exclude… \
-cvpzf home_bup.tgz /home/username
I suggest such manner
for fedora core
tar cvpzPf /tmp/backup.tar.gz –exclude={/proc/*,/sys/*,/tmp/*,/dev/*} /
for Debian
tar cvfpP /tmp/debian2.tar –exclude={“/proc/*”,”/sys*”,”/tmp/*”,”/home/user/*”} /
and more common if i need backup using ssh
ssh root@192.168.0.1 “cd /;nice -n 10 tar cvpP –exclude={“/proc/*”,”/sys*”,”/tmp/*”,”/home/user/*”} /”>backup.tar.gz
August 17, 2009 at 6:27 pm
Thank you for this info! Helped a lot.