I want to do 2 things with a tar.gz file:
- Check for failure
- If successful - check number of files extracted
I found this for the 1st option. I now run my command like this: tar -xvzf bad_file.tar.gz && echo ok || echo fail
and it echos all the errors + fail at the end, which is what I want.
For the 2nd part, I used to use tar -xvzf bad_file.tar.gz | wc -l
which worked fine, but returned number of files, even if an error occurred.
Example for the 2nd part (I opened the file in an editor and just removed a line):
[root@zt avi]# tar -xvzf damaged_file.tar.gz | wc -l
gzip: stdin: invalid compressed data--crc error
gzip: stdin: invalid compressed data--length error
tar: Unexpected EOF in archive
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now
3
How can I combine these 2 commands?
--no-ignore-command-error
instead – CIsForCookies Oct 15 '18 at 07:54