Tar command in mac os x adding “hidden” files, why? [closed]

て烟熏妆下的殇ゞ 提交于 2020-05-09 17:58:44

问题


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.

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:

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.

Where does that ./._Test.txt file come from? I don't see it when doing an ls -a

Upon inspecting the tar contents it seems to be some binary data, but I have no idea where it comes from.


回答1:


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.




回答2:


You can add the following to your bashrc file -

export COPYFILE_DISABLE=true

Or, you can add this option to your tar command at the extraction time

tar -xzpvf x.tar --exclude="._*"



回答3:


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.




回答4:


This is the way OSX stores the file system forks when the target file system does not support them.

See: http://en.wikipedia.org/wiki/Fork_(file_system)



来源:https://stackoverflow.com/questions/8766730/tar-command-in-mac-os-x-adding-hidden-files-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!