当我用Mac OSX中内置的zip压缩器压缩文件时,它会在提取的zip中创建一个名为“__MACOSX”的额外文件夹。
我是否可以调整我的设置以避免创建此文件夹,或者我是否需要购买第三方压缩工具?
更新:我刚刚发现了一个OSX的免费应用程序,解决了我的问题:“YemuZip”
更新2:YemuZip不再是免费软件。
当我用Mac OSX中内置的zip压缩器压缩文件时,它会在提取的zip中创建一个名为“__MACOSX”的额外文件夹。
我是否可以调整我的设置以避免创建此文件夹,或者我是否需要购买第三方压缩工具?
更新:我刚刚发现了一个OSX的免费应用程序,解决了我的问题:“YemuZip”
更新2:YemuZip不再是免费软件。
当前回答
可以通过zip -d filename.zip __MACOSX/\*
并且,删除。ds_store文件:zip -d filename.zip \*/。DS_Store
其他回答
你指的是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.
不需要的文件夹还可以通过以下方式删除:
zip -d filename.zip "__MACOSX*"
最适合我
zip命令行工具永远不会创建__MACOSX目录,所以你可以像这样运行一个命令:
zip directory.zip -x \*.DS_Store -r directory
在下面的输出中,我用zip命令行工具创建的a.s zip不包含__MACOSX目录,但我从Finder创建的2.zip包含__MACOSX目录。
$ touch a
$ xattr -w somekey somevalue a
$ zip a.zip a
adding: a (stored 0%)
$ unzip -l a.zip
Archive: a.zip
Length Date Time Name
-------- ---- ---- ----
0 01-02-16 20:29 a
-------- -------
0 1 file
$ unzip -l a\ 2.zip # I created `a 2.zip` from Finder before this
Archive: a 2.zip
Length Date Time Name
-------- ---- ---- ----
0 01-02-16 20:29 a
0 01-02-16 20:31 __MACOSX/
149 01-02-16 20:29 __MACOSX/._a
-------- -------
149 3 files
-x . ds_store不排除目录中的. ds_store文件。DS_Store。
顶级的zip归档文件多个文件通常应该一个目录,因为如果不是这样,一些unarchiving公用工程(解压缩和7 z,但不是档案效用,Unarchiver, unar,或dtrx)不包含目录创建一个文件档案提取时,通常很难找到的文件,如果多个这样的档案提取的同时,很难告诉哪些文件属于哪个档案。
Archive Utility only creates a __MACOSX directory when you create an archive where at least one file contains metadata such as extended attributes, file flags, or a resource fork. The __MACOSX directory contains AppleDouble files whose filename starts with ._ that are used to store OS X-specific metadata. The zip command line utility discards metadata such as extended attributes, file flags, and resource forks, which also means that metadata such as tags is lost, and that aliases stop working, because the information in an alias file is stored in a resource fork.
通常,您可以丢弃特定于OS x的元数据,但要查看元数据文件包含什么,可以使用xattr -l。Xattr还包括资源叉和文件标志,因为即使它们实际上没有作为扩展属性存储,也可以通过扩展属性接口访问它们。Archive实用程序和zip命令行实用程序都会丢弃acl。
zip -r "$destFileName.zip" "$srcFileName" -x "*/\__MACOSX" -x "*/\.*"
-x "*/\__MACOSX":忽略你提到的__MACOSX。 - x”* / \。*":忽略任何隐藏文件,如. ds_store。 如果变量以空格命名,则引用该变量以避免文件。
此外,您可以构建Automator Service,使其易于在Finder中使用。 如果需要,请检查下面的链接查看详细信息。
Github
另一个可以与Automator工具一起使用的shell脚本(参见benedikt关于如何创建脚本的回答)是:
while read -r f; do
d="$(dirname "$f")"
n="$(basename "$f")"
cd "$d"
zip "$n.zip" -x \*.DS_Store -r "$n"
done
不同之处在于,这段代码直接压缩选定的文件夹,而不包含macOS特定的文件(而不是先压缩后删除)。