checking intergrity of tar or gz(gz'ipped file)/ tar or gz file is complete or incommplete

Some times we used to take the file which is tar/gz'ipped file and still putting in place by other process(ftp connection).



in this case we get in-complete file with gunzip failled or tar failled cases saying file is incomplete, last line corrupted and some file errors on different systems.


we can use a -t option with gunzip/tar to find its validity.


Test the gz file:

gunzip -t test.tar.gz


To test the tar file inside :

gunzip -c test.tar.gz | tar tf test.tar.gz


Check the value of $? , if we gets 0 (success) value.
we get non zero value if the file is corrupted tar or corrupted gzi'pped file.