macos Mac zip 压缩没有 __MACOSX 文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10924236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mac zip compress without __MACOSX folder?
提问by Scott B
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.
当我使用 Mac OSX 中的内置 zip 压缩器压缩文件时,会在解压缩的 zip 中创建一个名为“__MACOSX”的额外文件夹。
Can I adjust my settings to keep this folder from being created or do I need to purchase a third party compression tool?
我可以调整我的设置以防止创建此文件夹还是需要购买第三方压缩工具?
UPDATE: I just found a freeware app for OSX that solves my problem: "YemuZip"
更新:我刚刚找到了一个适用于 OSX 的免费软件应用程序来解决我的问题:“ YemuZip”
UPDATE 2: YemuZip is no longer freeware
更新 2:YemuZip 不再是免费软件
采纳答案by sinuhepop
When I had this problem I've done it from command line:
当我遇到这个问题时,我是从命令行完成的:
zip file.zip uncompressed
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 answeris 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.
编辑,经过多次否决:我使用这个选项有一段时间了,我不知道我在哪里学的,所以我不能给你一个更好的解释。克里斯约翰逊的回答是正确的,但我不会删除我的。正如一条评论所说,OP 的要求更准确,因为它在没有这些文件的情况下进行压缩,而不是从压缩文件中删除它们。我也觉得更容易记住。
回答by Chris Johnson
Can be fixed after the fact by zip -d filename.zip __MACOSX/\*
可以事后修复 zip -d filename.zip __MACOSX/\*
回答by pompalini
Inside the folder you want to be compressed, in terminal:
在您要压缩的文件夹内,在终端中:
zip -r -X Archive.zip *
Where -X means: Exclude those invisible Mac resource files such as “_MACOSX” or “._Filename” and .ds store files
其中 -X 表示:排除那些不可见的 Mac 资源文件,例如“_MACOSX”或“._Filename”以及 .ds 存储文件
Note:Will only work for the folder and subsequent folder tree you are in and has to have the *
wildcard.
注意:仅适用于您所在的文件夹和后续文件夹树,并且必须具有*
通配符。
回答by Adil Hussain
This command did it for me:
这个命令为我做了:
zip -r Target.zip Source -x "*.DS_Store"
Target.zip
is the zip file to create. Source
is the source file/folder to zip up. And the _x
parameter specifies the file/folder to not include. If the above doesn't work for whatever reason, try this instead:
Target.zip
是要创建的 zip 文件。Source
是要压缩的源文件/文件夹。并且该_x
参数指定要不包括的文件/文件夹。如果上述方法由于某种原因不起作用,请尝试以下操作:
zip -r Target.zip Source -x "*.DS_Store" -x "__MACOSX"
回答by benedikt
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).
我正在使用这个 Automator Shell 脚本来修复它。它显示为上下文菜单项(右键单击 Finder 中显示的任何文件)。
while read -r p; do
zip -d "$p" __MACOSX/\* || true
zip -d "$p" \*/.DS_Store || true
done
- Create a new Service with Automator
- Select "Files and Folders" in "Finder"
- Add a "Shell Script Action"
- 使用 Automator 创建新服务
- 在“查找器”中选择“文件和文件夹”
- 添加“Shell 脚本操作”
回答by SabU
The unwanted folders can be also be deleted by the following way:
也可以通过以下方式删除不需要的文件夹:
zip -d filename.zip "__MACOSX*"
Works best for me
最适合我
回答by Jian Jason
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.
-x "*/\__MACOSX"
:忽略你提到的 __MACOSX。-x "*/\.*"
:忽略任何隐藏文件,例如 .DS_Store 。- 如果变量以空格命名,则引用该变量以避免文件。
Also, you can build Automator Service to make it easily to use in Finder. Check link below to see detail if you need.
此外,您可以构建 Automator Service 以使其在 Finder 中轻松使用。如果需要,请查看下面的链接以查看详细信息。
回答by nisetama
The zip
command line utility never creates a __MACOSX
directory, so you can just run a command like this:
该zip
命令行实用程序绝不会创建一个__MACOSX
目录,这样你就可以运行如下命令:
zip directory.zip -x \*.DS_Store -r directory
In the output below, a.zip
which I created with the zip
command line utility does not contain a __MACOSX
directory, but a 2.zip
which I created from Finder does.
在下面的输出中,a.zip
我使用zip
命令行实用程序创建的不包含__MACOSX
目录,但a 2.zip
我从 Finder 创建的包含目录。
$ 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
does not exclude .DS_Store
files inside directories but -x \*.DS_Store
does.
-x .DS_Store
不排除.DS_Store
目录内的文件,但排除-x \*.DS_Store
。
The top level file of a zip archive with multiple files should usually be a single directory, because if it is not, some unarchiving utilites (like unzip
and 7z
, but not Archive Utility, The Unarchiver, unar
, or dtrx
) do not create a containing directory for the files when the archive is extracted, which often makes the files difficult to find, and if multiple archives like that are extracted at the same time, it can be difficult to tell which files belong to which archive.
包含多个文件的 zip 存档的顶级文件通常应该是单个目录,因为如果不是,则某些取消存档实用程序(例如unzip
和7z
,但不是存档实用程序、The 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.
Archive Utility 仅__MACOSX
在您创建存档时创建一个目录,其中至少一个文件包含元数据,例如扩展属性、文件标志或资源分支。该__MACOSX
目录包含 AppleDouble 文件,其文件名以._
用于存储 OS X 特定元数据的开头。该zip
命令行实用程序丢弃元数据,诸如扩展属性,文件标志和资源叉,这也意味着元数据如标签丢失,并且别名停止工作,因为在一个别名文件中的信息被存储在资源派生。
Normally you can just discard the OS X-specific metadata, but to see what metadata files contain, you can use xattr -l
. xattr
also includes resource forks and file flags, because even though they are not actually stored as extended attributes, they can be accessed through the extended attributes interface. Both Archive Utility and the zip
command line utility discard ACLs.
通常,您可以丢弃特定于 OS X 的元数据,但要查看元数据文件包含哪些内容,您可以使用xattr -l
. xattr
还包括资源分叉和文件标志,因为即使它们实际上并未存储为扩展属性,但可以通过扩展属性接口访问它们。存档实用程序和zip
命令行实用程序都丢弃 ACL。
回答by Alejandro Pablo Tkachuk
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
用于删除基于正则表达式的内容。所以你可以像这样使用它:
zip -d filename.zip __MACOSX/\*
回答by Xian Shu
do not zip any hidden file:
不要压缩任何隐藏文件:
zip newzipname filename.any -x "\.*"
with this question, it should be like:
有了这个问题,它应该是这样的:
zip newzipname filename.any -x "\__MACOSX"
It must be said, though, zip command runs in terminal just compressing the file, it does not compress any others. So do this the result is the same:
但是必须说,zip 命令在终端中运行只是压缩文件,它不会压缩任何其他文件。所以这样做结果是一样的:
zip newzipname filename.any