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

后端 未结 8 1559

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条回答
  •  萌比男神i
    2020-11-30 20:31

    > use the -O option. [...] If the tar file is corrupt, the process will abort with an error.

    Sometimes yes, but sometimes not. Let's see an example of a corrupted file:

    echo Pete > my_name
    tar -cf my_data.tar my_name 
    
    # // Simulate a corruption
    sed < my_data.tar 's/Pete/Fool/' > my_data_now.tar
    # // "my_data_now.tar" is the corrupted file
    
    tar -xvf my_data_now.tar -O
    

    It shows:

    my_name
    Fool  
    

    Even if you execute

    echo $?
    

    tar said that there was no error:

    0
    

    but the file was corrupted, it has now "Fool" instead of "Pete".

提交回复
热议问题