How to check if a Unix .tar.gz file is a valid file without uncompressing?

understack picture understack · Jan 4, 2010 · Viewed 192.1k times · Source

I have found the question How to determine if data is valid tar file without a file?, but I was wondering: is there a ready made command line solution?

Answer

Rob Wells picture Rob Wells · Jan 4, 2010

What about just getting a listing of the tarball and throw away the output, rather than decompressing the file?

tar -tzf my_tar.tar.gz >/dev/null

Edited as per comment. Thanks zrajm!

Edit as per comment. Thanks Frozen Flame! This test in no way implies integrity of the data. Because it was designed as a tape archival utility most implementations of tar will allow multiple copies of the same file!