当我用Mac OSX中内置的zip压缩器压缩文件时,它会在提取的zip中创建一个名为“__MACOSX”的额外文件夹。

我是否可以调整我的设置以避免创建此文件夹,或者我是否需要购买第三方压缩工具?

更新:我刚刚发现了一个OSX的免费应用程序,解决了我的问题:“YemuZip”

更新2:YemuZip不再是免费软件。


当前回答

在阅读了所有现有的答案后,我有一个更好的解决方案。所有的事情都可以通过一个简单的右键点击工作流来完成。 没有额外的软件,没有复杂的命令行,没有shell技巧。

自动化工作流程:

输入:来自任何应用程序的文件或文件夹。 步骤1:创建Archive,系统内置默认参数。 步骤2:运行Shell命令,输入为参数。复制下面的命令。 zip -d "$@" "__MACOSX/*" || true Zip -d "$@" "*/。DS_Store" || true

保存它,我们就完成了!只需右击文件夹或大量文件,并从服务菜单中选择工作流。将同时创建没有元数据的存档。

图片更新:当我创建一个新的工作流时,我选择了“快速行动”-这里是一个英文版的截图:

其他回答

你指的是zip命令行工具还是Finder的压缩命令?

对于zip,您可以尝试——data-fork选项。如果这不能解决问题,您可以尝试——no-extra,尽管这似乎忽略了其他可能有价值的文件元数据,如uid/gid和文件时间。

对于Finder的压缩命令,我不相信有任何选项来控制它的行为。这是一个简单的例子。

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.

我使用这个Automator Shell脚本来修复它之后。 它显示为上下文菜单项(右键单击Finder中显示的任何文件)。

while read -r p; do
  zip -d "$p" __MACOSX/\* || true
  zip -d "$p" \*/.DS_Store || true
done

使用Automator创建一个新的服务 在“查找器”选择“文件及文件夹” 添加一个“Shell Script Action”

这是我在使用tar命令压缩文件时避免__MACOSX目录的方法:

$ CD dir-you-want-to-archive $ find。| xargs xattr - l# <-列出所有具有特殊xattr属性的文件 ... ./conf/clamav: com.apple.quarantine: 0083;5a9018b1 ./conf/global: com.apple.quarantine: 0083;5a9018b1;Safari ./conf/web_server: com.apple.quarantine: 0083;5a9018b1

先删除属性:

找到。|xargs xattr -d com.apple.quarantine

运行find。| xargs xattr -l,确保没有任何文件具有xattr属性。然后你就可以开始了:

你是水手bz2你

zip -r "$destFileName.zip" "$srcFileName" -x "*/\__MACOSX" -x "*/\.*"

-x "*/\__MACOSX":忽略你提到的__MACOSX。 - x”* / \。*":忽略任何隐藏文件,如. ds_store。 如果变量以空格命名,则引用该变量以避免文件。

此外,您可以构建Automator Service,使其易于在Finder中使用。 如果需要,请检查下面的链接查看详细信息。

Github

不要压缩任何隐藏文件:

zip newzipname filename.any  -x "\.*"

对于这个问题,它应该是这样的:

zip newzipname filename.any  -x "\__MACOSX"

必须指出的是,在终端中运行zip命令只是压缩文件,它不压缩任何其他文件。所以这样做的结果是一样的:

zip newzipname filename.any