[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TAR bug - seen under Linux, several versions

From: Akim Demaille
Subject: Re: TAR bug - seen under Linux, several versions
Date: 10 Oct 2000 10:16:09 +0200
User-agent: Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Channel Islands)

| Hello -


| there is a typical tar command which I have used for
| years under Solaris, NCR UNIX, and many other
| UNIX operating systems.
| tar -ft <filename>
| I just figured out today that the following command works:
| tar -t -f <filename>
| but this is very inconsistent with the normal syntax since
| the following also works under linux:
| tar -xvf <filename>
| tar -tf <filename>
| This problem has been dogging me for months and
| I never thought that merely reversing the options to
| make the "f" work at the end would work... or
| breaking out the switches to multiple "-" options.
| If you can please make the command line parser
| work in other directions (-ft as well as -tf), that
| would be great since it will help me out with a variety
| of programs that I will need to make sure work under
| Linux as well as other standard SVR4 systems.

Maybe you missed the GNU tar documentation.  I include the relevant
part below for convenience.  In short, it is the ``Solaris syntax''
which is inconsistent, and does not comply with the GNU standards.


The Three Option Styles

   There are three styles for writing operations and options to the
command line invoking `tar'.  The different styles were developed at
different times during the history of `tar'.  These styles will be
presented below, from the most recent to the oldest.

   Some options must take an argument.  (For example,
`--file=ARCHIVE-NAME' (`-f ARCHIVE-NAME') takes the name of an archive
file as an argument.  If you do not supply an archive file name, `tar'
will use a default, but this can be confusing; thus, we recommend that
you always supply a specific archive file name.)  Where you _place_ the
arguments generally depends on which style of options you choose.  We
will detail specific information relevant to each option style in the
sections on the different option styles, below.  The differences are
subtle, yet can often be very important; incorrect option placement can
cause you to overwrite a number of important files.  We urge you to
note these differences, and only use the option style(s) which makes
the most sense to you until you feel comfortable with the others.

* Menu:

* Mnemonic Options::            Mnemonic Option Style
* Short Options::               Short Option Style
* Old Options::                 Old Option Style
* Mixing::                      Mixing Option Styles

Mnemonic Option Style

   Each option has at least one long (or mnemonic) name starting with
two dashes in a row, e.g. `--list'.  The long names are more clear than
their corresponding short or old names.  It sometimes happens that a
single mnemonic option has many different different names which are
synonymous, such as `--compare' and `--diff'.  In addition, long option
names can be given unique abbreviations.  For example, `--cre' can be
used in place of `--create' because there is no other mnemonic option
which begins with `cre'.  (One way to find this out is by trying it and
seeing what happens; if a particular abbreviation could represent more
than one option, `tar' will tell you that that abbreviation is
ambiguous and you'll know that that abbreviation won't work.  You may
also choose to run `tar --help' to see a list of options.  Be aware
that if you run `tar' with a unique abbreviation for the long name of
an option you didn't want to use, you are stuck; `tar' will perform the
command as ordered.)

   Mnemonic options are meant to be obvious and easy to remember, and
their meanings are generally easier to discern than those of their
corresponding short options (see below).  For example:

     $ tar --create --verbose --blocking-factor=20 --file=/dev/rmt0

gives a fairly good set of hints about what the command does, even for
those not fully acquainted with `tar'.

   Mnemonic options which require arguments take those arguments
immediately following the option name; they are introduced by an equal
sign.  For example, the `--file' option (which tells the name of the
`tar' archive) is given a file such as `archive.tar' as argument by
using the notation `--file=archive.tar' for the mnemonic option.

Short Option Style

   Most options also have a short option name.  Short options start with
a single dash, and are followed by a single character, e.g. `-t' (which
is equivalent to `--list').  The forms are absolutely identical in
function; they are interchangeable.

   The short option names are faster to type than long option names.

   Short options which require arguments take their arguments
immediately following the option, usually separated by white space.  It
is also possible to stick the argument right after the short option
name, using no intervening space.  For example, you might write
`-f archive.tar' or `-farchive.tar' instead of using
`--file=archive.tar'.  Both `--file=ARCHIVE-NAME' and `-f ARCHIVE-NAME'
denote the option which indicates a specific archive, here named

   Short options' letters may be clumped together, but you are not
required to do this (as compared to old options; see below).  When short
options are clumped as a set, use one (single) dash for them all, e.g.
``tar' -cvf'.  Only the last option in such a set is allowed to have an

   When the options are separated, the argument for each option which
requires an argument directly follows that option, as is usual for Unix
programs.  For example:

     $ tar -c -v -b 20 -f /dev/rmt0

   If you reorder short options' locations, be sure to move any
arguments that belong to them.  If you do not move the arguments
properly, you may end up overwriting files.

   ---------- Footnotes ----------

   (1) Clustering many options, the last of which has an argument, is a
rather opaque way to write options.  Some wonder if GNU `getopt' should
not even be made helpful enough for considering such usages as invalid.

Old Option Style

     _(This message will disappear, once this node revised.)_

   Like short options, old options are single letters.  However, old
options must be written together as a single clumped set, without
spaces separating them or dashes preceding them(1).  This set of
letters must be the first to appear on the command line, after the
`tar' program name and some white space; old options cannot appear
anywhere else.  The letter of an old option is exactly the same letter
as the corresponding short option.  For example, the old option `t' is
the same as the short option `-t', and consequently, the same as the
mnemonic option `--list'.  So for example, the command `tar cv'
specifies the option `-v' in addition to the operation `-c'.

   When options that need arguments are given together with the command,
all the associated arguments follow, in the same order as the options.
Thus, the example given previously could also be written in the old
style as follows:

     $ tar cvbf 20 /dev/rmt0

Here, `20' is the argument of `-b' and `/dev/rmt0' is the argument of

   On the other hand, this old style syntax makes it difficult to match
option letters with their corresponding arguments, and is often
confusing.  In the command `tar cvbf 20 /dev/rmt0', for example, `20'
is the argument for `-b', `/dev/rmt0' is the argument for `-f', and
`-v' does not have a corresponding argument.  Even using short options
like in `tar -c -v -b 20 -f /dev/rmt0' is clearer, putting all
arguments next to the option they pertain to.

   If you want to reorder the letters in the old option argument, be
sure to reorder any corresponding argument appropriately.

   This old way of writing `tar' options can surprise even experienced
users.  For example, the two commands:

     tar cfz archive.tar.gz file
     tar -cfz archive.tar.gz file

are quite different.  The first example uses `archive.tar.gz' as the
value for option `f' and recognizes the option `z'.  The second
example, however, uses `z' as the value for option `f'--probably not
what was intended.

   Old options are kept for compatibility with old versions of `tar'.

   This second example could be corrected in many ways, among which the
following are equivalent:

     tar -czf archive.tar.gz file
     tar -cf archive.tar.gz -z file
     tar cf archive.tar.gz -z file

   As far as we know, all `tar' programs, GNU and non-GNU, support old
options.  GNU `tar' supports them not only for historical reasons, but
also because many people are used to them.  For compatibility with Unix
`tar', the first argument is always treated as containing command and
option letters even if it doesn't start with `-'.  Thus, `tar c' is
equivalent to `tar -c': both of them specify the `--create' (`-c')
command to create an archive.

   ---------- Footnotes ----------

   (1) Beware that if you precede options with a dash, you are
announcing the short option style instead of the old option style;
short options are decoded differently.

Mixing Option Styles

   All three styles may be intermixed in a single `tar' command, so
long as the rules for each style are fully respected(1).  Old style
options and either of the modern styles of options may be mixed within
a single `tar' command.  However, old style options must be introduced
as the first arguments only, following the rule for old options (old
options must appear directly after the `tar' command and some white
space).  Modern options may be given only after all arguments to the
old options have been collected.  If this rule is not respected, a
modern option might be falsely interpreted as the value of the argument
to one of the old style options.

   For example, all the following commands are wholly equivalent, and
illustrate the many combinations and orderings of option styles.

     tar --create --file=archive.tar
     tar --create -f archive.tar
     tar --create -farchive.tar
     tar --file=archive.tar --create
     tar --file=archive.tar -c
     tar -c --file=archive.tar
     tar -c -f archive.tar
     tar -c -farchive.tar
     tar -cf archive.tar
     tar -cfarchive.tar
     tar -f archive.tar --create
     tar -f archive.tar -c
     tar -farchive.tar --create
     tar -farchive.tar -c
     tar c --file=archive.tar
     tar c -f archive.tar
     tar c -farchive.tar
     tar cf archive.tar
     tar f archive.tar --create
     tar f archive.tar -c
     tar fc archive.tar

   On the other hand, the following commands are _not_ equivalent to
the previous set:

     tar -f -c archive.tar
     tar -fc archive.tar
     tar -fcarchive.tar
     tar -farchive.tarc
     tar cfarchive.tar

These last examples mean something completely different from what the
user intended (judging based on the example in the previous set which
uses long options, whose intent is therefore very clear).  The first
four specify that the `tar' archive would be a file named `-c', `c',
`carchive.tar' or `archive.tarc', respectively.  The first two examples
also specify a single non-option, NAME argument having the value
`archive.tar'.  The last example contains only old style option letters
(repeating option `c' twice), not all of which are meaningful (eg., `.',
`h', or `i'), with no argument value.

   ---------- Footnotes ----------

   (1) Before GNU `tar' version 1.11.6, a bug prevented intermixing old
style options with mnemonic options in some cases.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]