3

I'm wondering what's the difference between "man 3 command" vs "man command"?

I read in wiki (http://en.wikipedia.org/wiki/Man_page) that man 3 is used in Linux in section 3 of the man pages. And section 3 refers to Library functions, covering in particular the C standard library.

I tried "man 3 ls" and got this:

No entry for ls in section 3 of the manual

I wonder when to use man 3 and when to use man and do they serve difference purposes?

Thanks.

  • 6
    Try man man. I don't get your question, you do state that section 3 is for library functions - ls isn't a library function. – Mat Apr 11 '13 at 17:32
  • I'm confused about the layout(?) of the man page.. abarnert's answer clear things up – user2157668 Apr 11 '13 at 17:43
11

man 3 ls will only show you a man page for ls in section 3 of the manual. Section 3 covers library functions; since there's (probably) no library function named ls, it won't find anything.

The man command without a section number searches the sections in a predefined order that I don't remember, but it's likely to be close to numerical order starting at 1. So man ls will find the ls man page in section 1, which covers user commands.

The sections (on my Ubuntu system) are:

   1   Executable programs or shell commands
   2   System calls (functions provided by the kernel)
   3   Library calls (functions within program libraries)
   4   Special files (usually found in /dev)
   5   File formats and conventions eg /etc/passwd
   6   Games
   7   Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
   8   System administration commands (usually only for root)
   9   Kernel routines [Non standard]

Specifying the section can be useful for things that exist with the same name in more than one section. For example, man printf will show you the man page for the printf user command in section 1; to see the man page for the printf function, use man 3 printf. You'll often see these man pages referred to as printf(1) and printf(3), respectively.

Stealing Borrowing from abernert's answer, it's common to see a user command (section 1) that's a wrapper for a system call (section 2) or library call (section 3) with the same name; chown and chmod are good examples of this.

| improve this answer | |
3

As your question says, section 3 is for library functions, covering the C standard library. There is no ls function in the C standard library, so when you ask for its manpage, there is none.

I can see why you might be confused. In many cases, there's a tool that just wraps up some C or POSIX function in a simple command-line executable. For example, the chmod tool (in section 1) basically just parses your arguments and calls the chmod POSIX function (in section 2) on each file. So, you can type man 1 chmod to get documentation on the tool, and man 2 chmod to get documentation on the library function that the tool uses. If you just type man chmod, it will pick section 1 over section 2, so you'll get the tool.

But this isn't always true. For example, the main function ls uses is probably readdir. So, you can look up the tool with man 1 ls, and look up the function with man 3 readdir. In this case, man readdir will probably do the same thing as man 3 readdir, because there's nothing in a higher-priority section with the same name.

| improve this answer | |
  • Yeah, that's what I'm confused about.. very clear explanation. Thanks!! – user2157668 Apr 11 '13 at 17:42
1

Some of the pages exist in different entries in man. Then to get to the specific one you may often want to use which section you wish to see. For example see whatis find. You will be referenced to three different pages. Try to use each of the section ids it outputs in parenthesis.

| improve this answer | |
0

Occasionally, when you're reading man pages, or are searching for a particular page with man -k, you may get two similarly named pages, but in different libraries:

[mini-nevie:~] nevinwilliams% man -k route
route(4)                 - kernel packet forwarding database
route(8)                 - manually manipulate the routing tables

Then to read each man page, you do:

man 4 route

to read the first, and

man 8 route

to read the second.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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