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.).