Results 1 to 8 of 8

Thread: How to: Exclude files from a ZIP archive

  1. #1

    Default How to: Exclude files from a ZIP archive

    opensuse v11.2, linux 2.6.31.12-0.1-desktop x86_64
    ZIP v2.32

    I thought I knew ZIP pretty well. Hah!

    I wish to exclude some files from a zip archive. On other OSes to exclude an entire directory I would use the "-x" option like so:
    Code:
    zip -r archive-name * -x dir1/*
    Simple. And just add "-x"'s as needed (or use an exclusion file).

    Not how it works here, it would seem. AFAICT all "-x" options are ignored. (The entries in an exclusion file also.) For instance, "-x diy/mplayer/*" should ignore everything in the <diy/mplayer> directory. It does not. I have tried fully qualified paths as well; no joy.

    What is different about ZIP on linux?
    Can files be excluded?
    What am I missing?

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: How to: Exclude files from a ZIP archive

    Try quoting the exclude argument:

    -x 'dir1/*'

  3. #3
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    4,654

    Default Re: How to: Exclude files from a ZIP archive

    ken yap wrote:

    >
    > Try quoting the exclude argument:
    >
    > -x 'dir1/*'
    >

    or escape the * with a backslash to avoid shell filename substitution.

    -x dir1/\*




  4. #4
    palladium NNTP User

    Default Re: How to: Exclude files from a ZIP archive

    jimoe666 wrote:
    > What am I missing?


    missing: should not expect zip to be the same as on the other system..

    and, maybe missed that Linux comes with a complete manual on all the
    switches and magic available for zip..

    the easy way to read the zip manual is to open a terminal and type

    Code:
    man zip
    personally i like to read it in konqueror, all pretty and nicely
    formatted, if you have konqueror try

    Code:
    #zip
    and, if you wanna know more about the manuals,

    Code:
    #man
    and, there are LOTS of other manuals: cp, rm, mount, fsck, ps, top,
    zypper, etc etc etc etc

    Have a lot of fun!

    --
    palladium

  5. #5

    Default Re: How to: Exclude files from a ZIP archive

    Okay, quoting the strings or escaping the wildcard works on the command line. Thanks!

    How do I get the same result when using an exclude file?

    And, yes, quoting/escaping were mentioned in the man page. I missed it since it was tucked away under the "-d" option description.

  6. #6
    palladium NNTP User

    Default Re: How to: Exclude files from a ZIP archive

    jimoe666 wrote:
    > How do I get the same result when using an exclude file?


    have you tried it exactly the way the man lays it out in one line, and
    it didn't work?

    can you give an example of what didn't work..


    > quoting/escaping were mentioned in the man page. I missed it
    > since it was tucked away under the "-d" option description.


    if you launch the zip man in konqueror you can then Ctrl+f and a
    search box will pop up, into which you can type 'exclude' . . .

    or, if you prefer the CLI you can:

    man zip | grep -i exclude

    --
    palladium

  7. #7

    Default Re: How to: Exclude files from a ZIP archive

    have you tried it exactly the way the man lays it out in one line, and it didn't work?
    It works on the command line, either quoted or escaped, for multiple "-x" options.

    It is a bit confusing since "zip -r * archive ..." works but "zip -r '*' archive ..." does not ("file * not found"). I tried finessing it with "zip -r './*' archive ..."; no go there.

    For the exclude file the man page indicates each pattern is on a separate line. I would swear that I tried non-quoted or non-escaped strings for each line entry. Apparently I did not since it now works as expected.

  8. #8
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: How to: Exclude files from a ZIP archive

    Quote Originally Posted by jimoe666 View Post
    It is a bit confusing since "zip -r * archive ..." works but "zip -r '*' archive ..." does not ("file * not found"). I tried finessing it with "zip -r './*' archive ..."; no go there.
    Some things are meant to be quoted/escaped and some not. Filename arguments should not be quoted since you want the shell to expand the pattern. However exclude arguments should be quoted because you want the pattern to survive into the zip program where it will be used as a pattern.

    One is a shell glob, the other is a regex pattern. The difference is who is meant to interpret it. That dictates whether it should be quoted or not.

Tags for this Thread

Posting Permissions

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