I am learning Linux. I was surprised to see that the parameter order seems to matter when making a tarball.
tar -cfvz casual.tar.gz snapback.txt bucket.txt
gives the error:
tar: casual.tar.gz: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
But if I issue the command like this:
tar -cvzf casual.tar.gz snapback.txt bucket.txt
the tarball is created without errors
Can anyone explain to me why the parameter order matters in this example or where I can find that information to learn why myself? I tried it the way I did in my first example that received an error with the logic of putting the required parameters c and f first followed by my other parameters.
I want to completely absorb Linux, which includes understanding why things like this occur. Thanks in advance!
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:
tar
, ps
works differently depending on whether there is a minus at the start)xargs -ifoo
is different from xargs -i foo
)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
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments