6

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.

1 Answer 1

4

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.

3
  • +1 Nice. Never even heard of /dev/full. Useful tip.
    – trojanfoe
    May 30, 2012 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, 2012 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. May 31, 2012 at 8:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .