I have a tarfile with 3 files in it, file1, file2, file3. When I use the Python tarfile module to view the files in the tarfile, the module shows 6 files, the three that I have, and it prepends an underscore to each of them. I am not sure why.
infile = '/Users/myname/Downloads/tt/testing.tar.gz'
outdir = '/Users/myname/Downloads/tt/out'
tar_flag = tarfile.is_tarfile(infile)
if tar_flag:
tar_obj = tarfile.open(infile, 'r')
name_list = tar_obj.getnames()
for name in name_list:
print name
tar_obj.close()
This prints the following:
./._file1
./file1
./._file2
./file2
./._file3
./file3
However, when I check the contents of the tarfile using the tar command, there are only 3 files in the tar file:
$ tar tvf testing.tar.gz
drwxr-xr-x 0 myname staff 0 Nov 7 10:20 ./
-rw-r--r-- 0 myname staff 518458 Jun 4 08:37 ./file1
-rw-r--r-- 0 myname staff 1050412 Oct 20 14:16 ./file2
-rw-r--r-- 0 myname staff 132463 Nov 7 10:08 ./file3
Also, when I extract the tar file, there are only 3 files in it.
I am not sure why tarfile module is prepending the _ and showing the filenames twice?
This is not a tar
-specific issue but rather about your OS. From your paths I assume you are using a Mac computer.
The files with the ._
prefix are the AppleDouble resource fork files for storing macOS's extended file attributes (including those normally manipulated with the xattr
command). You will also see such files appearing when you copy files to an external FAT32/ExFAT drive.
After unpacking the files, since your Mac uses HFS+ or APFS which supports those extended attributes, those files are instead stored directly in the filesystem.
This is another question about these files.