0

Sometimes I see -h is a manual for a application, and sometimes I find --help in the manual.

What is the difference between them? Is there any history/story about this?

0

4 Answers 4

3

The standard place for documentation about unix commands is the unix manual (aka "man pages") (sections 1 and 8), accessed via the man command. For instance, to get the documentation for the grep command, you'd use man grep.

Some commands also provide some built-in documentation if run with an option like -h or --help. This isn't nearly as standard, and how and whether this is provided varies a great deal between commands. As for the difference between -h and --help, that's mostly historical. The "standard" for command options in unix has evolved quite a bit over the decades.

When unix was first "born", different commands took options in completely different formats; this early chaos survives in a few commands like tar (which tends to assume its first argument is options whether or not it starts with -) and dd (which sort of treats all its arguments like long options without --).

But it didn't take long for a standard of sorts to appear: options started with a single dash, and consisted of a single letter or other character, and they had to come before any positional (non-option) parameters. This was before many commands included any built-in help, so commands from this era often use -h for something other than help (for instance, grep -h doesn't print filenames where grep would).

More recently, several additions to this "standard" have appeared: long options that start with a double dash (e.g. --help), allowing options to come after or in amongst the positional parameters, and using -- to indicate the end of options (so everything after that is a positional parameter, even if it starts with dash). Some commands use these new option styles, some don't.

Also recently, some commands have included/added built-in help. How this gets invoked depends, basically, on the whim of the command's developer(s), along with whether -h already had some other meaning (as in cases like grep). So some commands take -h for help, some take --help, some both, and some neither.

Ironically, the best way to find out how to get the built-in help for a command (if it exists), is to read its man page. Here's an excerpt from man grep:

 -H      Always print filename headers with output lines.

 -h, --no-filename
         Never print filename headers (i.e. filenames) with output lines.

 --help  Print a brief help message.
0

Typically --help is used, but if -h works too, developers have probably included it to make it quicker to type.

It's not standard however and very dependent on the command - vim uses both for example, and bash only uses --help.

As such, if you're using Linux, man command is typically the definitive help guide.

You might also enjoy reading this answer for more info on command line arguments.

0

-h short attribute is intended to save time of user which types a command(s), sometimes very long;

--help attribute is intended for bash scripts (which should be easy to understand by many users). In this example -h is obvious but sometimes there are a lot of attributes so using -j, -i -g in bash script is correct - bash script will execute correctly, but your colleague from work probably will kill you :)

-1

It really depends on the specific program. There may be no difference between them. --help may provide more verbose text than -h .

Not the answer you're looking for? Browse other questions tagged .