Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

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
share|improve this question

marked as duplicate by Gilles Aug 28 at 15:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
It is not specific to git or tar. Not sure what it means either, but I have seen it is on other commands too. –  Kevdog777 Aug 28 at 10:22
2  
Related: Single dashes - for single-character options, but double dashes -- for words? [unix.stackexchange.com/questions/21852/… –  lgeorget Aug 28 at 10:30

4 Answers 4

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.

share|improve this answer
    
I guess it's pretty simple. 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 at 11:49

It's a convention:

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

share|improve this answer
    
Please note that -abc could also be a long GNU-style option (abc). –  John WH Smith Aug 28 at 10:26
    
@JohnWHSmith While we're at it, the dashes can be completely optional. Some things use positional syntax (eg apt-get) with or instead of dash-based arguments. How a command works is really up to that command. –  Oli Aug 28 at 10:30
1  
@JohnWHSmith No, it cannot be a long GNU-style option. Some programs (even some GNU programs) use custom option parsers, and as Oli noted, they can do anything they like, but GNU-style option parsing will always treat -abc as three single-letter options. –  hvd Aug 28 at 13:10
    
And then you have Java which has everything with a single dash and the wonderful -Dfancy.option.string=something. –  Zeke Sonxx Aug 28 at 14:58
    
@Zeke Ugh! Don't you remind me of that. –  syntaxerror Aug 29 at 11:52

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:

  • some programs such as git allow using a single minus sign before a first letter of a long option. In such case, this option will be expanded to the long option starting with this letter just as if two minus signs and a full option name were provided. For example:

$ git pull -r

is equivalent to:

$ git pull --rebase

  • some programs such as GNU date act similar to git, but only expand a partial long name option if they are preceded by a two minus signs:

$ date --s

is equivalent to:

$ date --set

  • some programs such as mutt or git allow to omit a whitespace after an option and before a value:

$ mutt -f/var/mail/user

is equivalent to:

$ mutt -f /var/mail/user

  • some programs such as GUN rm allow grouping single options. For example:

$ rm -rv dir

is equivalent to:

$ rm -r -v dir

  • some programs that take options that take parameters use empty double minus option to mark the end of options. For example, if you would like to use touch command to create a file that starts with a minus sign you would have to do this:

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

share|improve this answer
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
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.