EDIT: It's been pointed out that this style is a GNU-ism, and that non-GNU based Unixes tend to use a single-dash syntax (in particular, OS X and BSD variants).
Despite it's GNU-ism status, many newly written Unix-style programs use this style:
--long-option
for long option names,
-s
for short (one-character) options,
-abc
for multiple short options without arguments (one character per option).
- Options with arguments:
--long arg
or --long=arg
for long options,
-s arg
, -sarg
or (optionally) -s=arg
for short options. This can be combined with other short options, as long as only the last one has an argument.
- The same "semantic" option can have several aliases, most commonly a short (quicker to type) one and a long (easier to remember) one.
Anybody that has used a Linux shell for any amount of time should be familiar with this style1, so it has the principle of least surprise on its side. Allowing grouping of multiple short options without being ambiguous with long options is also nice.
1For example, some of the programs using this style (on my Linux machine): ls
, grep
, man
, sed
, bash
, etc. (EDIT: these are apparently GNU-isms though, BSD and OS X machines don't use this style)
There are several libraries that can take care of parsing this for you (the most well-known being GNU's implementation of getopt), only needing you to specify what long and short options exist, whether they take an argument, and what to do when an option is found. (And of course, what to do for positional arguments, i.e. ones that don't start with -
and are not arguments to previous options)
find
is a very old program (or maybe more likely: a rewritten version of a very old program) that can't easily be changed to use a new command line syntax. Too many scripts would break, and too many users used to the old syntax would complain. javac
was likely influenced by gcc
and friends, which likewise follow an old syntax for historical reasons.