tar -cvfz command results in error message unless I omit the hyphen before 'cvfz'
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
scott/
scott/netx/
scott/netx/locks/
scott/netx/locks/netx_running
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.).
Related videos on Youtube
user784637
Updated on September 18, 2022Comments
-
user784637 over 1 year
Possible Duplicate:
sudo tar cvpzf exiting with failure due to previous errorWhen 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?-
Admin over 12 yearsThere's no errors before that message, it's some verbose stdout of all the files in that directory
-
Admin over 12 yearshave you seen this ? askubuntu.com/questions/78043/…
-
Admin over 12 yearsYeah 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 over 12 yearsYou're correct, my syntax was incorrect. Placing the
f
option last did the trick