There is no widespread standard. There's some consistency e.g. in GNU programs, but you need to check each program's documentation.
Quoting Wikipedia, emphasis mine:
In Unix-like systems, the ASCII hyphen–minus is commonly used to specify options. The character is usually followed by one or more letters. An argument that is a single hyphen–minus by itself without any letters usually specifies that a program should handle data coming from the standard input or send data to the standard output. Two hyphen–minus characters ( -- ) are used on some programs to specify "long options" where more descriptive option names are used. This is a common feature of GNU software.
Usually, hyphens indicate a predefined argument. I think it's used to differentiate them from e.g. file names or other labels you might use as arguments. That's not always the case, though (see below).
You'll often find the same argument available both as short and long option, as e.g. in ls.
Some programs use a single hyphen for one-character options, and two hyphens for multi-character options, but not all (GNU find
comes to mind). Some programs have optional hyphens or skip them altogether (tar
or BSD ps
come to mind).
Sometimes long options (--foo
) require arguments, while short options (-f
) don't (or at least imply a specific default argument).
Short options (e.g. cut -d ' '
) can have arguments , while long options (e.g. ls --all
) don't necessarily have them.
To set a particular behavior of a program, you sometimes need to use a short option, for others you need to use a long option, and for some you have a choice.
On a related note, some programs can handle no whitespace between an option and its argument, while others can't.
As I wrote at the beginning, there just is no common behavior or standard. Often you can trace similar behavior to the same library used for argument parsing, but you probably don't want to read the sources to find this out.
You really cannot infer one program's argument syntax from another's.
If you also consider Windows, it gets even worse: While the Windows command line calls traditionally use /f
(at least most of the time, single characters) for options, with :
as the separator between options and their value (see e.g. here); cross-platform utilities are widespread (such as those you mention) and bring along the more common hyphen syntax for arguments, with all the inconsistencies mentioned above.
GNU came along with their convention of using two dashes for "long" options, which I happen to prefer, but many older utilities, such as those bundled with the X Window System, as well as ImageMagick (e.g.,
– TheDudeAbides – 2019-01-23T00:09:18.520convert
,mogrify
) have "long" options using only a single dash. For example:xterm -fn 6x10 -geometry 80x24+30+200
. Abbreviations are supported, provided they're distinct (e.g.,-g
or-geom
for-geometry
). See X(7) for other examples.10> Doesn't it make sense for everyone to stick to one standard – yes. Do all programmers stick to standards and keep consistency? No. Many programmers can't even maintain consistency within their programs :) That being said, the consensus would be to use one dash only for one-letter options, and two dashes for all that are actually words, e.g.
-i
vs.--input
or-n
--dry-run
. – slhck – 2011-12-28T07:44:43.9431@slhck Heys thanks for the help =) By that convention then, does it mean that the
-dtd
should really have been--dtd
? Effectively what I was wondering about is what does the dash (and double-dash) trying to signify ? – Pacerier – 2011-12-28T07:50:36.8406For bonus points: programs conforming to the Gnu standards for
--long-options
will accept any unique abbreviation as well. So, for a program with options--file-in
and--file-out
, you could use--file-o=foo
or--file-i=foo
, which can save some typing for--very-long-optional-parameters
. – BRPocock – 2011-12-28T14:41:14.530