首页 > OSX > 见鬼故事之插入OSX的U盘被塞入._开头的文件

见鬼故事之插入OSX的U盘被塞入._开头的文件

  最近发现了一件奇怪的事情,我刚下载到硬盘的的git项目,所有的文件都改莫名其妙的更改,还发现有很多._开头的文件,而且被修改的文件在sourcetree上面还看不到有什么改变,只显示被改变了。
  
  事出反常必有妖,我就开始追查一下具体的原因。
  首先说下,我的电脑硬盘空间不足,就插了一个外置的U盘,是exFat格式的,莫非与这个有关?
  根据ls后面带的@标识知道文件还有一些扩展的属性。

➜  assets git:(master) ✗ ls -al
total 0
drwxrwxrwx@ 3 afantree  staff  102  4 11 10:37 .
drwxrwxrwx@ 5 afantree  staff  170  4 11 10:26 ..
drwxrwxrwx@ 3 afantree  staff  102  4 11 10:37 shaders
drwxrwxrwx@ 3 afantree  staff  102  4 11 10:37 ._shaders

  查看下扩展属性发现有一个Key为Mac_Metadata的值。

➜  assets git:(master) ✗ xattr -l shaders                              
Mac_Metadata:
00000000  F6 01 00 00 14 00 00 00 00 00 00 00 FF 41 FF FF  |.............A..|
00000010  00 00 00 00                                      |....|
00000014

  查了一下,发现

Before Mac OS X, the Mac OS used ‘forked’ files, which have two components: a data fork and a resource fork. The Mac OS Standard (HFS) and Mac OS Extended (HFS Plus) disk formats support forked files. When you move these types of files to other disk formats, the resource fork can be lost.

With Mac OS X, there is a mechanism called “Apple Double” that allows the system to work with disk formats that do not have a forked file feature, such as remote NFS, SMB, WebDAV directories, or local UFS volumes. Apple Double does this by converting the file into two separate files. The first new file keeps the original name and contains the data fork of the original file. The second new file has the name of the original file prefixed by a “._ ” and contains the resource fork of the original file. If you see both files, the ._ file can be safely ignored. Sometimes when deleting a file, the ._ component will not be deleted. If this occurs you can safely delete the ._ file.
  原来还真是我选错了硬盘格式的问题。

解决办法

  怎么也容忍不了乱七八糟的东西存在,我把有用的东西copy出来,重新格式化了这个U盘,选择了HPS+的格式。
  copy出来的文件,执行下面的命令来删除._开头的文件。

find . -name "._*"|xargs rm 

  还有就是每个文件的扩展属性被修改的问题,也得矫正过来,执行下面的命令:

find . -exec echo {} \; -exec xattr -d Mac_Metadata {} \;

  这下完美解决了这个问题。

  1. 还没有评论
评论提交中, 请稍候...

留言


可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Trackbacks & Pingbacks ( 0 )
  1. 还没有 trackbacks