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.

5 Responses to “exclude directories when tarring with tar in Ubuntu”

  1. quark Says:

    Hi,

    Thanks yaar. It works. but it should have been –exclude instead of -exclude.

  2. hobbylobby Says:

    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.

  3. Alexwebmaster Says:

    Hello webmaster
    I would like to share with you a link to your site
    write me here preonrelt@mail.ru

  4. aceqbaceq Says:

    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

    :)

  5. Apteryx Says:

    Thank you for this info! Helped a lot.


Leave a Reply