Shell – Difference between ‘man ls’ and ‘ls –help’

linuxshell

I use both man and --help in Bash programming to get help.
For example, to get information about usage of ls command, I may use

man ls 

Or

ls --help

Both give some what similar output. What is the difference between these two?

Best Answer

For one, --help is not a command, it is an argument that is often given to a command to get help using it. Meanwhile, man is a command, short for "manual". Manual pages are installed by many programs, and are a common way to find help about commands, as well as system calls, (e.g. fork()).

If a program installs a manual page, it can always be accessed via the man command, whereas --help is just a common convention, but need not be enforced—it could be just (and only) -h.

man also typically uses a pager, such as less, automatically, which can make viewing and searching through the information much easier.

Finally, you mention Bash programming in your question—none of this is unique to Bash. Bash doesn't care about the commands themselves or their arguments for the most part.