macos mac os x 中的 Tar 命令添加“隐藏”文件,为什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8766730/
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
Tar command in mac os x adding "hidden" files, why?
提问by Joris Mans
I am writing my own tar archiver. All works fine inside my app (even reading tars generated with other tools) however I cannot get my tar files to work with 3rd party tar file readers. So I tried building a tar file on the command line, building one with my code and binary comparing the two.
我正在编写自己的 tar 归档程序。在我的应用程序中一切正常(甚至读取使用其他工具生成的 tar)但是我无法让我的 tar 文件与 3rd 方 tar 文件阅读器一起使用。所以我尝试在命令行上构建一个 tar 文件,用我的代码和二进制文件比较两者来构建一个。
But there seems to be an issue:
但是好像有一个问题:
I have a textfile called Test.txt which I want to add to my tar, so I run the following command in the terminal:
我有一个名为 Test.txt 的文本文件,我想将它添加到我的 tar 中,因此我在终端中运行以下命令:
tar -c -f x.tar Test.txt
When doing this:
这样做时:
tar -tf x.tar
I get the following list:
我得到以下列表:
./._Test.txt
Test.txt
This is in the Terminal on Mac OS X Lion.
这是在 Mac OS X Lion 的终端中。
Where does that ./._Test.txt
file come from? I don't see it when doing an ls -a
那个./._Test.txt
文件从哪里来?我在执行 ls -a 时看不到它
Upon inspecting the tar contents it seems to be some binary data, but I have no idea where it comes from.
检查 tar 内容后,它似乎是一些二进制数据,但我不知道它来自哪里。
采纳答案by blahdiblah
It's a representation of the file's resource fork/extended attributes.
它是文件资源分支/扩展属性的表示。
Try ls -l@ Test.txt
and xattr -l Test.txt
to see what extra stuff OSX tacked on to the file.
尝试ls -l@ Test.txt
并xattr -l Test.txt
看看有什么额外的东西OSX上涨到文件。
回答by jaypal singh
You can add the following to your bashrc file -
您可以将以下内容添加到您的 bashrc 文件中 -
export COPYFILE_DISABLE=true
Or, you can add this option to your tar
command at the extraction time
或者,您可以tar
在提取时将此选项添加到您的命令中
tar -xzpvf x.tar --exclude="._*"
回答by mdm
As of bsdtar 3.0.3 - libarchive 3.0.3
(and perhaps earlier) there's a new (Mac OS X specific) option to the bsdtar
command called --disable-copyfile
to suppress the creation of ._
files.
从 bsdtar 3.0.3 - libarchive 3.0.3
(也许更早)开始,该bsdtar
命令有一个新的(Mac OS X 特定的)选项,--disable-copyfile
用于禁止创建._
文件。
回答by al01
This is the way OSX stores the file system forks when the target file system does not support them.
这是 OSX 在目标文件系统不支持文件系统分支时存储文件系统分支的方式。