Whether the order matters depends on whether you start the options with a minus
$ tar -cfvz casual.tar.gz snapback.txt bucket.txt
tar: casual.tar.gz: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
$ tar cfvz casual.tar.gz snapback.txt bucket.txt
snapback.txt
bucket.txt
This unusual behavior is documented in the man page
Options to GNU tar can be given in three different styles.
In traditional style
...
Any command line words that remain after all options has
been processed are treated as non-optional arguments: file or archive
member names.
...
tar cfv a.tar /etc
...
In UNIX or short-option style, each option letter is prefixed with a
single dash, as in other command line utilities. If an option takes
argument, the argument follows it, either as a separate command line
word, or immediately following the option.
...
tar -cvf a.tar /etc
...
In GNU or long-option style, each option begins with two dashes and
has a meaningful name
...
tar --create --file a.tar --verbose /etc
tar
, which is short for "tape archive" has been around before the current conventions were decided on, so it keeps the different modes for compatibility.
So to "absorb Linux", I'd suggest a few starting lessons:
- always read the man page
- minor differences in syntax are sometimes important
- the position of items - most commands require options to be the first thing after the command name
- whether a minus is required (like
tar
, ps
works differently depending on whether there is a minus at the start)
- whether a space is optional, required, or must not be there (
xargs -ifoo
is different from xargs -i foo
)
- some things don't work the way you'd expect
To get the behavior you want in the usual style, put the output file name directly after the f
or -f
, e.g.
$ tar -cvzf casual.tar.gz snapback.txt bucket.txt
snapback.txt
bucket.txt
or:
$ tar -c -f casual.tar.gz -z -v snapback.txt bucket.txt
or you could use the less common but easier to read GNU long style:
$ tar --create --verbose -gzip --file casual.tar.gz snapback.txt bucket.txt
f
stands for file, and expects you to give it some filename. Assume you want to also give theH
parameter, to set the format. Out oftar -c -H pax -f my.pax file
,tar -cH my.pax -f pax file
,tar -cHf my.pax pax file
,tar -cHf pax my.pax file
etc. only one is really clear. But if you just switch position liketar -cf my.pax -H pax file
it is equaly clear and valid. Just switch position of the arguments too!