Results 1 to 7 of 7

Thread: tar: exclude directories or files not working

  1. #1
    Join Date
    Sep 2007
    Beans
    7

    tar: exclude directories or files not working

    I've tried many variations on ways of excluding directories in a tar command
    and would appreciate any thoughts on this issue.

    none work.

    tar -cvfpj --exclude=~/My_Music tarFile.bz2 /home/evan/
    tar -cvfpj tarFile.bz2 --exclude=~/My_Music /home/evan/
    tar -cvfpj tarFile.bz2 --exclude=~/My_Music /home/evan/
    tar -cvf --exclude=~/My_Music tarFile.tar /home/evan/

    # quoting the exclude paths:
    tar -cvfpj --exclude="~/My_Music" tarFile.bz2 /home/evan/
    tar -cvfpj tarFile.bz2 --exclude="~/My_Music" /home/evan/
    tar -cvfpj tarFile.bz2 --exclude="~/My_Music" /home/evan/
    tar -cvf --exclude="~/My_Music" tarFile.tar /home/evan/

    # not using ~ character in exclude paths:
    tar -cvfpj --exclude="/My_Music" tarFile.bz2 /home/evan/
    tar -cvfpj tarFile.bz2 --exclude="/My_Music" /home/evan/
    tar -cvfpj tarFile.bz2 --exclude="/My_Music" /home/evan/
    tar -cvf --exclude="/My_Music" tarFile.tar /home/evan/

    # not using ~ character and not quoting the exclude paths:
    tar -cvfpj --exclude=/My_Music tarFile.bz2 /home/evan/
    tar -cvfpj tarFile.bz2 --exclude=/My_Music /home/evan/
    tar -cvfpj tarFile.bz2 --exclude=/My_Music /home/evan/
    tar -cvf --exclude=/My_Music tarFile.tar /home/evan/

    #creating an exclude list file and referencing that
    tar -cvfX ~/scripts/EXCLUDE_list tarFile.tar /home/evan/
    tar -cvf --exclude-from ~/scripts/EXCLUDE_list tarFile.tar /home/evan/
    tar -cvf --exclude-from=~/scripts/EXCLUDE_list tarFile.tar /home/evan/
    tar -cvf --exclude-from="~/scripts/EXCLUDE_list" tarFile.tar /home/evan/
    tar -cvf --exclude-from=$HOME/scripts/EXCLUDE_list tarFile.tar /home/evan/

    #contents of the EXCLUDE_list file have taken many forms -
    # none have appeared to have any effect.

    # version 1
    /My_Music/

    # version 2
    /My_Music

    # version 3
    My_Music

    # version 4 - trying to isolate file types
    *.mpg
    *.mp3
    *.m4a

    Thanks.
    http://www.hobbylobby.wordpress.com/

  2. #2
    Join Date
    Apr 2006
    Location
    Green Bay, WI, USA
    Beans
    399
    Distro
    Kubuntu 8.04 Hardy Heron

    Re: tar: exclude directories or files not working

    according to the man page, the exclude option requires two "dashes"
    Code:
    --exclude=
    A computer without Microsoft is like a chocolate cake without mustard.

  3. #3
    Join Date
    Mar 2007
    Location
    Your Closet
    Beans
    380
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: tar: exclude directories or files not working

    None of your examples should work. I'm not gonna go through them all and say why tho. This might work, idk.
    Code:
    tar --exclude=/home/evan/My_Music -cvfpj tarFile.bz2 /home/evan/
    ...

  4. #4
    Join Date
    Aug 2007
    Location
    Canada
    Beans
    458
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: tar: exclude directories or files not working

    Here I go:
    PHP Code:
    tar --exclude='My_Music' -cvjf tarFile.bz2 /home/evan
    Best, Gnusci

    "Never make a calculation until you know the answer." -- Wheeler, Spacetime Physics, pg 60.

  5. #5
    Join Date
    Mar 2007
    Location
    Your Closet
    Beans
    380
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: tar: exclude directories or files not working

    Quote Originally Posted by gnusci View Post
    Here I go:
    Code:
    tar --exclude='My_Music' -cvjf tarFile.bz2 /home/evan/
    That's exactly the same except it would exclude "/home/evan/blah/My_Music" if it exists, which may or may not be what he wants. You couldn't explain the difference for him?
    ...

  6. #6
    Join Date
    Sep 2007
    Beans
    7

    Re: tar: exclude directories or files not working

    I'm running my script with this line:

    Code:
    tar --exclude=/home/evan/My_Music --exclude=/home/evan/SCHOOL -cvpzf home_bup.tgz /home/evan
    and it all seems to be working properly !!!

    I've seen many examples and can't recall anyone putting --exclude before the switches. that wasn't obvious at all.

    thanks for the advice.

    oh - I was using 2 dashes... it just didn't look like it with this font.

    and I finally figured out another less than obvious thing about tar - the "-f" switch has to be the last one listed.

    That caused me all kinds of grief

    .evan
    http://www.hobbylobby.wordpress.com/

  7. #7
    Join Date
    Sep 2008
    Beans
    6

    Re: tar: exclude directories or files not working

    i had the same problem. man tar describes option exclude very badly.

    common style using "tar+exclude" suggested in internet sources is like:


    tar \
    - -exclude… \
    - -exclude… \
    - -exclude… \

    - -exclude… \
    -cvpzf home_bup.tgz /home/username

    but i think it is a very annoying method.

    I suggest next:

    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+nice+tar)

    ssh root@192.168.0.1 “cd /;nice -n 10 tar cvpP –exclude={”/proc/*”,”/sys*”,”/tmp/*”,”/home/user/*”} /”>backup.tar.gz



    and before "exclude" we have two "-" not one.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •