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

后端 未结 8 1595

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:30

    you could probably use the gzip -t option to test the files integrity

    http://linux.about.com/od/commands/l/blcmdl1_gzip.htm

    from: http://unix.ittoolbox.com/groups/technical-functional/shellscript-l/how-to-test-file-integrity-of-targz-1138880

    To test the gzip file is not corrupt:

    gunzip -t file.tar.gz
    

    To test the tar file inside is not corrupt:

    gunzip -c file.tar.gz | tar -t > /dev/null
    

    As part of the backup you could probably just run the latter command and check the value of $? afterwards for a 0 (success) value. If either the tar or the gzip has an issue, $? will have a non zero value.

提交回复
热议问题