Possible Duplicate:
sudo tar cvpzf exiting with failure due to previous error

When I run the command

tar -cvfz backup.tar.gz somedirectory

I get the following sterr

tar: Exiting with failure status due to previous errors

However when I omit the preceding hyphen from -cvfz everything seems to work just fine. Is there a known reason for why the hyphen is preventing me from tar'ing my files?

marked as duplicate by Marco Ceppi Jan 9 '12 at 5:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    What are the previous errors? – psusi Jan 9 '12 at 3:37
  • There's no errors before that message, it's some verbose stdout of all the files in that directory – user784637 Jan 9 '12 at 3:43
  • have you seen this ? askubuntu.com/questions/78043/… – viyyer Jan 9 '12 at 3:44
  • Yeah I read that before I posted this question because it didn't mention the hyphen. Someone mentioned the hyphen on superuser but it was only as an afterthought. I wanted a more detailed explanation of why including the hyphen causes problems. – user784637 Jan 9 '12 at 3:47

I'm not sure why tar cvfz works, when accourding to a quick scan of the man page and my experience, a hyphen is standard practice. Maybe it's a BSD compatibility thing (like ps).

At any rate, your syntax is incorrect. -f takes the next argument as the filename to compress to. In this case, that filename is z, which isn't what you expected. Here's a sample of the output so you can see what I mean:

$ tar -cvfz test.tar.gz scott
tar: test.tar.gz: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

An ls shows a file called z. The file command reveals that it's an uncompressed tar archive. It's uncompressed because the -z argument wasn't passed. And the error message came from trying to add the non-existant file test.tar.gz to the archive.

Simply reorder the options and you'll be OK:

tar -czvf test.tar.gz some/directory

If you always make the -f the last argument, you'll be fine. By the way, remember that short options (one-letter options) that take arguments don't normally require a space between the option and the argument.

EDIT: By the way, if the form without the hyphen is a BSD-compatibility thing or something like that, then it's likely that the way that tar is invoked in such an environment is different, and doesn't require the f flag to specify the input file, but works more like cp or something. But this is just speculation based on comparison with ps (q.v.).

  • You're correct, my syntax was incorrect. Placing the f option last did the trick – user784637 Jan 9 '12 at 4:11

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