Why do we use double hyphen in tar --anchored
and single hyphen in tar -b
?
I mean to say why some command line options have single hyphen (-) while some others have double (--)?
Also a git
example:
git commit --amend
git commit -a
Why do we use double hyphen in tar --anchored
and single hyphen in tar -b
?
I mean to say why some command line options have single hyphen (-) while some others have double (--)?
Also a git
example:
git commit --amend
git commit -a
A single dash for one (or many) abbreviated arguments:
command -abc
A double for single, unabbreviated arguments:
command --alice --barry --catherine
It's important to note that this only a convention. Any command can take any arguments in any style (provided they're escaped from the shell), regardless of dashes. If our example command
here was programmed to accept them, the following could be valid synonyms of the above examples:
command abc
command alice barry catherine
These are probably horrible examples but what I'm trying to get across is it's a convention of a way to handle arguments as non-positional arguments. Some things don't want it. Some things just use single dashes. Some thing use characters other than dashes (I've seen cross-compiled Windows apps still using /
)... It really doesn't make that much difference.
-abc
could also be a long GNU-style option (abc
).
– John WH Smith
Aug 28 '14 at 10:26
apt-get
) with or instead of dash-based arguments. How a command works is really up to that command.
– Oli
Aug 28 '14 at 10:30
-abc
as three single-letter options.
– hvd
Aug 28 '14 at 13:10
-Dfancy.option.string=something
.
– Zoey Mertes
Aug 28 '14 at 14:58
Traditionally, long options (more than one letter) are written with two dashes, and short ones (one letter) with a single dash. Not all programs respect this however.
One of the oldest references I could find for this is : http://www.gnu.org/fun/jokes/long-options.html.
tar
(= "tape archiver", think of QIC-80 and friends) is a VERY old command from the beginnings of UNIX, and in the old days, there were only those said -X options. I've scoured the man page, and I can't remember any tar
option being available from the old days that took 2 dashes. Hence, there is a rule of thumb that all of the latter ones are commands which were added much later during recent years.
– syntaxerror
Aug 29 '14 at 11:49
As other guys already said, this is a convention started by GNU project to use a single minus sign for short, that means one letter long options and a double minus sign for long options, that means options that are longer than one letter. This convention is well established and used by many projects outside GNU but when it was introduced it confused some people accustomed to using short options exclusively. However, there is more to that:
$ git pull -r
is equivalent to:
$ git pull --rebase
$ date --s
is equivalent to:
$ date --set
$ mutt -f/var/mail/user
is equivalent to:
$ mutt -f /var/mail/user
$ rm -rv dir
is equivalent to:
$ rm -r -v dir
$ touch -- -file
It all depends on how a particular piece of software parses its options.
Also note as "-"
signs that you refer to as hyphens are known as minus for most Unix users, mainly because there are programs take option that start with plus sign (X for example). See here.
rmdir --ignore-fail-on-non-empty {directory} ...
The double dash (--) is before the full word, otherwise just use a single letter with one dash in the beginning (-).
Looking at other manuals, e.g. rmdir
manual, it shows a table of the options you can use:
-p
--ignore-fail-on-non-empty
-f, --force
-r, -R, --recursive
-v, --verbose
git
ortar
. Not sure what it means either, but I have seen it is on other commands too. – Kevdog777 Aug 28 '14 at 10:22-
for single-character options, but double dashes--
for words? [http://unix.stackexchange.com/questions/21852/single-dashes-for-single-character-options-but-double-dashes-for-words?rq=1] – lgeorget Aug 28 '14 at 10:30