0

I know this way only:

tar --full-time -tvf /path/to/file.tar.gz

But it makes tar to scan all the archive and it is time consuming if it is a very big one. My question is maybe there is a way to scan only beginning, only header of some sort just as it happens in other formats like *.7z or *.rar ?

  • 2
    There's no table of contents in a tar archive. The metadata for each file is before the file. – Barmar Apr 3 '15 at 19:55
  • That command will not work with that file (assuming that the file extension is correct). You need an a, as it is compressed. Also, because it is compressed the program can to skip, it must read every byte (if there is any redundancy in a compressed file, then it is not compressed well). – ctrl-alt-delor Apr 3 '15 at 22:01
  • a ?, 1) what does it do ? I can't find it on man page ( gnu.org/software/tar/manual/tar.html ), there is an -A option but for concatenating archive at the end. 2) what I wrote in question works. – rsk82 Apr 3 '15 at 22:48
2

The short answer is "no."

7Zip, RAR, zip, et al., are all dual-function programs/file formats. They compress individual files, then archive the compressed results. That results in portions of the file that are not compressed, but that, in turn, allows programs to get to individual files.

gzip (the .gz part) is different. It compresses a single byte stream only. The byte stream is provided by tar. bzip2 (.bz2) does the same thing, though with a different algorithm. tar is the archiver program, and gzip is the compression program. In order to get to the archive at all, the stream must first be decompressed. That can only happen by going through the entire file. Then, and only then, can tar get to the individual pieces of the archive.

The reason you don't see the gzip step here is that it has been built into tar, not directly per se, but by tar knowing to pipe its output stream to gzip.

| improve this answer | |
1

No, it's not possible. See Wikipedia for a description of the format of a tar file. Basically, it's just an alternating sequence of file header and file contents. There's no table of contents at the beginning, all the information about each file is in its file header.

The header includes the file size, so when just listing the contents the reader may be able to skip reading all the contents blocks by seeking to the beginning of the next header. However, if the tar file is compressed that isn't possible, because it first has to uncompress the contents so it can skip the appropriate number of uncompressed bytes.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.