You posted in a comment that you are working on a Mac OS X system. This is an important clue to the purpose of these ._*
files.
These ._*
archive entries are chunks of AppleDouble data that contain the extra information associated with the corresponding file (the one without the ._
prefix). They are generated by the Mac OS X–specific copyfile(3) family of functions. The AppleDouble blobs store access control data (ACLs) and extended attributes (commonly, Finder flags and “resource forks”, but xattrs can be used to store any kind of data).
The system-supplied Mac OS X archive tools (bsdtar
(also symlinked as tar
), gnutar
, and pax
) will generate a ._*
archive member for any file that has any extended information associated with it; in “unarchive” mode, they will also decode those archive members and apply the resulting extended information to the associated file. This creates a “full fidelity” archive for use on Mac OS X systems by preserving and later extracting all the information that the HFS+ filesystem can store.
The corresponding archive tools on other systems do not know to give special handling to these ._*
files, so they are unpacked as normal files. Since such files are fairly useless on other systems, they are often seen as “junk files”. Correspondingly, if a non–Mac OS X system generates an archive that includes normal files that start with ._
, the Mac OS X unarchiving tools will try to decode those files as extended information.
There is, however an undocumented(?) way to make the system-supplied Mac OS X archivers behave like they do on other Unixy systems: the COPYFILE_DISABLE environment variable. Setting this variable (to any value, even the empty string), will prevent the archivers from generating ._*
archive members to represent any extended information associated with the archived files. Its presence will also prevent the archivers from trying to interpret such archive members as extended information.
COPYFILE_DISABLE=1 tar czf new.tar.gz …
COPYFILE_DISABLE=1 tar xzf unixy.tar.gz …
You might set this variable in your shell’s initialization file if you want to work this way more often than not.
# disable special creation/extraction of ._* files by tar, etc. on Mac OS X
COPYFILE_DISABLE=1; export COPYFILE_DISABLE
Then, when you need to re-enable the feature (to preserve/restore the extended information), you can “unset” the variable for individual commands:
(unset COPYFILE_DISABLE; tar czf new-osx.tar.gz …)
The archivers on Mac OS X 10.4 also do something similar, though they use a different environment variable: COPY_EXTENDED_ATTRIBUTES_DISABLE
You can't use W
with t
.
mkdir tmp
echo bdb > tmp/a
echo bdb > tmp/b
tar cvf archive.tar tmp
tmp/
tmp/a
tmp/b
ls -l archive.tar
-rw-r--r-- 1 tony tony 10240 Jun 23 05:57 archive.tar
tar tvf archive.tar
drwxr-sr-x tony/tony 0 2011-06-23 05:57 tmp/
-rw-r--r-- tony/tony 4 2011-06-23 05:57 tmp/a
-rw-r--r-- tony/tony 4 2011-06-23 05:57 tmp/b
tar tvWf archive.tar
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors
I believe t
alone is enough to test the archive.
Best Answer
You don't.
(Note: this doesn't work if your shell has current directory symbolic link tracking turned on and the current directory is accessed via a symbolic link.)
Yes, this isn't what you asked, but this is what you should do. Archives that expand a lot of files in the current directory are annoying: it puts the burden of creating a target directory for the file on each person who unpacks the archive, and if they accidentally unpack them in a non-empty directory, it's hard to clean up. Most of the time, an archive should create a single toplevel directory whose name is the base name of the archive.