Home » Questions » Computers [ Ask a new question ]

Why do I get files like ._foo in my tarball on OS X?

Why do I get files like ._foo in my tarball on OS X?

When I tar certain files in OS X:

Asked by: Guest | Views: 109
Total answers/comments: 2
Guest [Entry]

"OS X's tar uses the AppleDouble format to store extended attributes and ACLs.

$ touch file1 file2 file3
$ xattr -w key value file1
$ chmod +a 'admin allow delete' file2
$ ls -le@ *
-rw-r--r--@ 1 lauri staff 0 May 25 07:09 file1
key 5
-rw-r--r--+ 1 lauri staff 0 May 25 07:09 file2
0: group:admin allow delete
-rw-r--r-- 1 lauri staff 0 May 25 07:09 file3
$ tar -cf 1.tar *
$ tar -tf 1.tar
./._file1
file1
./._file2
file2
file3

OS X's tar also knows how to convert the ._ members back to native formats, but the ._ files are usually kept when archives are extracted on other platforms. You can tell tar to not include the metadata by setting COPYFILE_DISABLE to some value:

$ COPYFILE_DISABLE=1 tar -cf 2.tar file*
$ tar -tf 2.tar
file1
file2
file3

The copyfile functions are described in man copyfile
ls -l@ shows the keys and sizes of extended attributes, ls -le prints ACLs
xattr -l lists the keys and values of extended attributes
xattr -c clears all extended attributes (-d can't be used alone)
chmod -N deletes ACLs
Zip files created on OS X use a __MACOSX folder to store similar metadata

Information stored as extended attributes:

Resource forks (resource forks have been extended attributes since 10.4)

Custom icons set in Finder and the images of Icon\r files
Metadata in PSD files
Objects stored in scpt files, AppleScript Editor window state, descriptions of scripts

Information about aliases (aliases stop working if extended attributes are removed)
Quarantine status or source URLs of files downloaded from the internet
Spotlight comments
Encoding of files saved with TextEdit
Caret position of files opened with TextMate
Skim notes"
Guest [Entry]

"The ._ files are resource forks as mentioned in other answers. However, there's a better way to get rid of them when using tar:

export COPYFILE_DISABLE=true
tar cvf foo.tar foo

There's also a dot_clean utility for cleaning up these files (I think it's usually used for external storage)."