Unexpected files showing up with tar on OS X 10.6.4

Solution 1:

They're resource forks. The Mac's filesystem supports multiple forks, and some Mac files have two, a data fork and a resource fork. Most file systems don't support multiple forks, so tools will split the resource fork into a separate file prefixed with ._.

Solution 2:

I think you'll find that those files (or directories) came packaged within the .tar.gz file. Not normal, but any file can go into a tar.

Solution 3:

Behaviour

For the sake of clarity about the issue, the following MWE illustrates what is happening:

cas$ tar --version
bsdtar 2.6.2 - libarchive 2.6.2
cas$ mkdir o
cas$ touch o/a o/b
cas$ tar cv o > /dev/null
a ./._o
a o
a o/._a
a o/a
a o/._b
a o/b

So each file and directory has a ._ file added to the tar file in the same directory, as mipadi said. This tar, let's call it mactar, avoids collisions by ignoring files beginning ._ in the input, e.g, with:

mkdir p && touch p/._a p/._b
cas$ tar cv p p/._b > /dev/null
a ./._p
a p

the existence of the p/._a file is simply ignored by tar, and so is the p/._b file, even though that is explicitly included in the CLI invocation. Thus, no collisions can occur.

Controlling tar

If you have a Unix background, you likely are unhappy about this behaviour. The mactar lacks the expected documentation: the man page is for the regular Free BSD tar and does not mention this idiosyncrasy.

However, the generation of the files for the meta forks can be disabled by setting an environment variable, so: export COPYFILE_DISABLE=true.

History

I'm not quite clear on the timing, but OSX began with the regular Free BSD tar, then Apple circulated an additional utility, tar_hfs that was the ancestor of mactar, and then, I think with Leopard, changed /usr/bin/tar to be mactar.