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.

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?

share|improve this question
add comment

migrated from stackoverflow.com Dec 13 '11 at 6:30

This question came from our site for professional and enthusiast programmers.

5 Answers

up vote 4 down vote accepted

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.

share|improve this answer
4  
To find out which document man will show you for ls you can type man -w ls –  holygeek Dec 13 '11 at 4:52
    
@holygeek awesome, I didn't know that, actually. –  Andrew Marshall Dec 13 '11 at 4:54
    
I seldom do man man, but when I do, I always learn new stuff from it :) –  holygeek Dec 13 '11 at 5:00
    
@holygeek Do you happen to know how to find the names of each manual section from the terminal? I feel like I used to know and now it's escaping me and I can't find it in man man. –  Andrew Marshall Dec 13 '11 at 5:03
    
I'm afraid I don't understand what you mean by "names of each manual section". I'm guessing you want something like man foo|grep '^[A-Z]' (for that I don't know the command line switch that does it directly too)? or maybe man -wa foo? –  holygeek Dec 13 '11 at 5:06
show 1 more comment

In most scenarios man is more detailed than --help. help gives the command line options for a particular command. But man is a lot more detailed.

Plus man is a command-line tool in itself whereas --help is a command-line arg for a tool. Small difference.

share|improve this answer
add comment

In the first you asking the system to search the manual pages for help on the command. The second you are asking the command to provide its own help. The two will most certainly differ - usually the command provides a reminder of its options where as the man page is a detailed description.

share|improve this answer
add comment

man some_command is something you can expect to work on all Unix and Unix like OSes, unless the manual pages are not installed.

some_command --help is mostly a GNUism so it generally won't work with non GNU implementations.

GNU, which doesn't like manual pages for some reason, also introduced info some_command as third alternative.

share|improve this answer
add comment

I find --help usefull as it lets me call help up while im modding a command

For example

rsync -vPn ./* ./newfolder/.

Oh What is the dam flag for compress?

rsync -vPn --help ./* ./newfolder/. | less

I find the help command on flags sometimes very very usefull and less time consuming. With man ive gota type it in and the go back through my history to get back to the command I was in.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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