Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

By default, for many kinds of errors tar prints a message to stderr and then continues on its way -- the errors it calls "recoverable" errors, typically errors that relate to a single file or archive member, like permissions problems.

Sometimes this behavior is really obnoxious. E.g., if I'm untarring an archive and the disk is full, then I may get something like this:

tar: python-lib/PyML/classifiers/ext/_cgist.so: Wrote only 2048 of 10240 bytes
tar: python-lib/PyML/classifiers/ext/_csmo.so: Cannot write: No space left on device
tar: python-lib/PyML/classifiers/ext/_csvmodel.so: Cannot write: No space left on device
tar: python-lib/PyML/classifiers/ext/_knn.so: Cannot write: No space left on device
tar: python-lib/PyML/classifiers/ext/_libsvm.so: Cannot write: No space left on device
tar: python-lib/PyML/classifiers/ext/_mylibsvm.so: Cannot write: No space left on device
tar: python-lib/PyML/classifiers/ext/cgist.py: Cannot write: No space left on device
tar: python-lib/PyML/classifiers/ext/csmo.py: Cannot write: No space left on device

that can go on for thousands of lines in a big archive. If this happens in a script, I'd much rather tar just exited promptly so I can give a prompt error to the user.

Is there any way to force tar to exit on the first error it sees? I don't see it in a scan of tar --help. Any sane recipe for a wrapper script to accomplish this purpose would also be gratefully accepted.

share|improve this question

migrated from stackoverflow.com May 30 '12 at 8:19

This question came from our site for professional and enthusiast programmers.

1 Answer 1

One way is to redirect the standard error output to /dev/full, e.g.:

tar ... 2>/dev/full

This will cause tar to fail when it tries to output a warning message into stderr.

share|improve this answer
    
+1 Nice. Never even heard of /dev/full. Useful tip. –  trojanfoe May 30 '12 at 8:14
    
Clever idea, but it doesn't work. At least not with GNU tar 1.22, the version I have on hand. Stracing the tar process confirms that it cheerfully continues on after each write to standard error fails. Have you actually tried this idea? What version of tar? –  Greg Price May 30 '12 at 21:44
    
I tried with other applications. tar probably just ignores the error. There need to be a pipe so that SIGPIPE is sent to tar in case of error to knock it off. –  Maxim Yegorushkin May 31 '12 at 8:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.