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

Problem
When I tar a directory in OS X Lion:

tar -cf foo.tar foo

It produces an extra file ._foo in the tarball:

._foo
foo

Cause
The extra file “._foo” is a Mac OS resource fork
It is created by tar on Mac OS X (Lion and earlier versions)

Solution
Set environment variable in your shell, before executing the tar command

COPYFILE_DISABLE=1 tar -cf foo.tar foo

Links