Mac zip compress without __MACOSX folder?

后端 未结 14 1487
有刺的猬
有刺的猬 2020-12-07 06:53

When I compress files with the built in zip compressor in Mac OSX, it results in an extra folder titled \"__MACOSX\" created in the extracted zip.

Can I adjust my se

相关标签:
14条回答
  • 2020-12-07 07:06

    When I had this problem I've done it from command line:

    zip file.zip uncompressed

    EDIT, after many downvotes: I was using this option for some time ago and I don't know where I learnt it, so I can't give you a better explanation. Chris Johnson's answer is correct, but I won't delete mine. As one comment says, it's more accurate to what OP is asking, as it compress without those files, instead of removing them from a compressed file. I find it easier to remember, too.

    0 讨论(0)
  • 2020-12-07 07:08

    I'm using this Automator Shell Script to fix it after. It's showing up as contextual menu item (right clicking on any file showing up in Finder).

    while read -r p; do
      zip -d "$p" __MACOSX/\* || true
      zip -d "$p" \*/.DS_Store || true
    done
    
    1. Create a new Service with Automator
    2. Select "Files and Folders" in "Finder"
    3. Add a "Shell Script Action"

    0 讨论(0)
  • 2020-12-07 07:09
    zip -r "$destFileName.zip" "$srcFileName" -x "*/\__MACOSX" -x "*/\.*"
    
    • -x "*/\__MACOSX": ignore __MACOSX as you mention.
    • -x "*/\.*": ignore any hidden file, such as .DS_Store .
    • Quote the variable to avoid file if it's named with SPACE.

    Also, you can build Automator Service to make it easily to use in Finder. Check link below to see detail if you need.

    Github

    0 讨论(0)
  • 2020-12-07 07:10

    Do you mean the zip command-line tool or the Finder's Compress command?

    For zip, you can try the --data-fork option. If that doesn't do it, you might try --no-extra, although that seems to ignore other file metadata that might be valuable, like uid/gid and file times.

    For the Finder's Compress command, I don't believe there are any options to control its behavior. It's for the simple case.

    The other tool, and maybe the one that the Finder actually uses under the hood, is ditto. With the -c -k options, it creates zip archives. With this tool, you can experiment with --norsrc, --noextattr, --noqtn, --noacl and/or simply leave off the --sequesterRsrc option (which, according to the man page, may be responsible for the __MACOSX subdirectory). Although, perhaps the absence of --sequesterRsrc simply means to use AppleDouble format, which would create ._ files all over the place instead of one __MACOSX directory.

    0 讨论(0)
  • 2020-12-07 07:10

    This is how i avoid the __MACOSX directory when compress files with tar command:

    $ cd dir-you-want-to-archive $ find . | xargs xattr -l # <- list all files with special xattr attributes ... ./conf/clamav: com.apple.quarantine: 0083;5a9018b1;Safari;9DCAFF33-C7F5-4848-9A87-5E061E5E2D55 ./conf/global: com.apple.quarantine: 0083;5a9018b1;Safari;9DCAFF33-C7F5-4848-9A87-5E061E5E2D55 ./conf/web_server: com.apple.quarantine: 0083;5a9018b1;Safari;9DCAFF33-C7F5-4848-9A87-5E061E5E2D55

    Delete the attribute first:

    find . | xargs xattr -d com.apple.quarantine

    Run find . | xargs xattr -l again, make sure no any file has the xattr attribute. then you're good to go:

    tar cjvf file.tar.bz2 dir

    0 讨论(0)
  • 2020-12-07 07:16

    You can't.

    But what you can do is delete those unwanted folders after zipping. Command line zip takes different arguments where one, the -d, is for deleting contents based on a regex. So you can use it like this:

    zip -d filename.zip __MACOSX/\*
    
    0 讨论(0)
提交回复
热议问题