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

后端 未结 8 1530

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?

相关标签:
8条回答
  • 2020-11-30 20:51

    These are all very sub-optimal solutions. From the GZIP spec

    ID2 (IDentification 2)
    These have the fixed values ID1 = 31 (0x1f, \037), ID2 = 139 (0x8b, \213), to identify the file as being in gzip format.

    Has to be coded into whatever language you're using.

    0 讨论(0)
  • 2020-11-30 20:54

    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!

    0 讨论(0)
提交回复
热议问题