0

I downloaded a .gz file with anonymized Census data and around 1 GB compressed. I am unable to inspect it with tar:

$ tar -tf census.csv.gz 
tar: Unrecognized archive format
tar: Error exit delayed from previous errors.

but I can inspect and decompress it with gzip:

$ gzip -l census.csv.gz 
  compressed uncompressed  ratio uncompressed_name
   949332135    886077017  -7.2% census.csv
$ gzip -d census.csv.gz 

I can also extract the archive by double-clicking, which opens Archive Utility. I am more confused because the man page for tar says that it has the gzip method.

Can tar list and decompress .gz files?

Notes: gzip is /usr/bin/gzip on macOS High Sierra 10.13.5.

4
  • 1
    I think your confusion is that "tar" is an (uncompressed) format to put multiple files into a single file. Tar can optionally comress this tar file as part of it's job (making a tar.gz file or .the file) - the key being that gzip compresses a stream/single file while tar converts multiple files into 1 - this you would not typically use tar on a single file.
    – davidgo
    Commented Jul 2, 2018 at 11:15
  • @davidgo I think I see. Is tar able to decompress tar.gz files but not .gz files (without .tar)?
    – emonigma
    Commented Jul 2, 2018 at 11:36
  • That would seem right to me. (I'm not at my PC - so I can't be sure there is not done obscure switch to allow it - but I can say tar is not typically used for that purpose.
    – davidgo
    Commented Jul 2, 2018 at 11:39
  • Thanks @davidgo. Would you like to post an answer so I accept it?
    – emonigma
    Commented Jul 4, 2018 at 10:06

1 Answer 1

1

TAR is typically used to merge / demux multiple files to/from single archive (TAR comes from Tape Archive - i.e. working with a data stream to be written to or read from tape), and it can optionally work with a compressed archive (using gzip among other options), but it was not designed as a general purpose compression / decompression tool.

Similarly, GZIP generally only works on a single file (where it compresses more then 1 file, it does each one individually).

A tar.gz (or .tgz) indicates a group of files which have been combined into a single stream with TAR, and then gzipped. TAR can handle these files, but not general purpose single .gz files.

Read more at Wikipedia.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .