What does func (N) means in man pages? [duplicate] - linux

For example: man(1), find(3), updatedb(2)?
What do the numbers in parentheses (Brit. "brackets") mean?

It's the section that the man page for the command is assigned to.
These are split as
General commands
System calls
C library functions
Special files (usually devices, those found in /dev) and drivers
File formats and conventions
Games and screensavers
Miscellanea
System administration commands and daemons
Original descriptions of each section can be seen in the Unix Programmer's Manual (page ii).
In order to access a man page given as "foo(5)", run:
man 5 foo

The section the command is documented in the manual. The list of sections is documented on man's manual. For example:
man 1 man
man 3 find
This is useful for when similar or exactly equal commands exist on different sections

The reason why the section numbers are significant is that many years ago when disk space was more of an issue than it is now the sections could be installed individually.
Many systems only had 1 and 8 installed for instance. These days people tend to look the commands up on google instead.

As #Ian G says, they are the man page sections. Let's take this one step further though:
1. See the man page for the man command with man man, and it shows the 9 sections as follows:
DESCRIPTION
man is the system's manual pager. Each page argument given
to man is normally the name of a program, utility or func‐
tion. The manual page associated with each of these argu‐
ments is then found and displayed. A section, if provided,
will direct man to look only in that section of the manual.
The default action is to search in all of the available sec‐
tions following a pre-defined order ("1 n l 8 3 2 3posix 3pm
3perl 5 4 9 6 7" by default, unless overridden by the SEC‐
TION directive in /etc/manpath.config), and to show only the
first page found, even if page exists in several sections.
The table below shows the section numbers of the manual fol‐
lowed by the types of pages they contain.
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 conven‐
tions), e.g. man(7), groff(7)
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]
A manual page consists of several sections.
2. man <section_num> <cmd>
Let's imagine you are Googling around for Linux commands. You find the OPEN(2) pg online: open(2) — Linux manual page.
To see this in the man pages on your pc, simply type in man 2 open.
For FOPEN(3) use man 3 fopen, etc.
3. man <section_num> intro
To read the intro pages to a section, type in man <section_num> intro, such as man 1 intro, man 2 intro, man 7 intro, etc.
To view all man page intros in succession, one-after-the-other, do man -a intro. The intro page for Section 1 will open. Press q to quit, then press Enter to view the intro for Section 8. Press q to quit, then press Enter to view the intro for Section 3. Continue this process until done. Each time after hitting q, it'll take you back to the main terminal screen but you'll still be in an interactive prompt, and you'll see this line:
--Man-- next: intro(8) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
Note that the Section order that man -a intro will take you through is:
Section 1
Section 8
Section 3
Section 2
Section 5
Section 4
Section 6
Section 7
This search order is intentional, as the man man page explains:
The default action is to search in all of the available sections follow‐
ing a pre-defined order ("1 n l 8 3 2 3posix 3pm 3perl 5 4 9 6 7" by default, unless overrid‐
den by the SECTION directive in /etc/manpath.config)
Why did they choose this order? I don't know (please answer in the comments if you know), but just realize this order is correct and intentional.
Related:
Google search for "linux what does the number mean in parenthesis after a function?"
SuperUser: What do the parentheses and number after a Unix command or C function mean?
Unix & Linux: What do the numbers in a man page mean?

Note also that on other unixes, the method of specifying the section differs. On solaris, for example, it is:
man -s 1 man

It indicates the section of the man pages the command is found in. The -s switch on the man command can be used to limit a search to certain sections.
When you view a man page, the top left gives the name of the section, e.g.:
User Commands printf(1)
Standard C Library Functions printf(3C)
So if you are trying to look up C functions and don't want to accidentally see a page for a user command that shares the same name, you would do 'man -s 3C ...'

Wikipedia details about Manual Sections:
General commands
System calls
Library functions, covering in particular the C standard library
Special files (usually devices, those found in /dev) and drivers
File formats and conventions
Games and screensavers
Miscellanea
System administration commands and daemons

Related

how to create a general manual for linux?

I am working in a company where they use lots of tools and commands for linux (internal and external)
I would like to create a custom manual, with examples per tool.
Thought of using info tool for this:
info CompanyName tool1
info CompanyName tool2
info CompanyName tool3
..
and the output of each should be a simple text of examples and comments added by me.
But as far as I know, the info in Linux is created for a specific tool and not for a your customized needs.
Any idea what would be the best way to achieve the above?
Currently I am using sublime with tab per tool and every once and then I update the sublime tab with the new examples.
Any advice will be most appreciated.
For what it's worth, I am not a fan of info pages. I prefer the good old Unix man pages and it is very simple to write them. You can simply open any man page in an editor, look at it's source and just copy it to suit your needs.
On most systems the man pages are found in a directory like /usr/share/man/{man1,man2,man3,man4,man5,man6,man7,man8}/, or you can use the -w option of the man command to see the location of any man page and then open it. For example
$ man -w ls
/usr/share/man/man1/ls.1.gz
$ vim /usr/share/man/man1/ls.1.gz
You can see how it is written, and mimic it to write your own man page. In order for anyone to be able to read the man page written by you, the man page has to be installed in one of the directories where the man utility searches for man pages. On Linux, you can usually see this list of directories by running the manpath command (on other systems it might be different and you will have to see the man page of the man command itself). If you store your man pages in one of these directories then any one can read it by using the man utility.
As per POSIX the man utility also respects the environment variable MANPATH, so if you store your man page in a non-standard location, you can set the MANPATH variable, so that man can look it up. Or you can also modify the /etc/man.conf file to add your man page directory to the search path of man.
Now, man pages use a macro language to do the mark up. Linux systems tend to use man(7) macro syntax, for which you can see the manual here
There is another modern macro set for writing man pages, called mdoc(7), which is used extensively in the BSD family of operating systems. You can see its manual here

UNIX man command to find list of man sections

I'm working on a lab that is supposed to help us better navigate the command line on a Linux system, but I'm getting stuck on man pages.
We are supposed to use the man command to find a list of the man page sections, adn I can't seem to figure out how to do this. I've tried entering
man man
but that doesn't give me any information on the individual sections. I've also tried looking on Google to find what command I should use, but no luck there either.
Can anybody point me in the right direction?
apropos -r '.*'
This will list all manual pages. A script to chop this up into lists by section is a follow-up homework assignment.

Description to my file using man command

I created a small project using C to make some commands in Linux terminal.
I want to add a description to my project to call it when I use man command. Such as if my project name is hello.c, I want when I write command man hello.c to print the description I wrote for my project. Where do I write this description?
I saw this but don't know where or how I write the description.
There are several great tutorials for doing so:
How to write a man
page
Creating your own manpage
How to write a UNIX man page.
Pick one, and hack away.
If you feel that you are stuck somewhere, take a look at man pages from FreeBSD utilities like cat, echo, etc

Finding where Linux functions are defined

Is there a good database for Linux where I can search for a function name and it tells me which header it is defined in? Googling doesn't always work for me and there aren't always man pages.
Using manpages
For basic C functions, the manpages should work.
man 2 read
man 3 printf
Section 2 is for system calls (direct to the kernel), and section 3 is for standard C library calls. You can generally omit the section, and man will figure out what you need on its own.
Note that you may need to take extra steps to get development-related manpages on your system. For example, on my Debian system, I had to do apt-get install manpages-dev glibc-doc.
Using library-specific references
For non-basic C functions, you should check the documentation of the library you're using (e.g., GNU's docs for libstdc++, doc.qt.io for Qt, library.gnome.org for GNOME projects like GTK, and so on).
Using the web
linux.die.net is a good online mirror of web pages.
LSB Navigator (as described in this answer) looks cool. I did not know about that.
Using grep
Sometimes it's just easiest to search /usr/include yourself. grep works for this, but ack is much better. For example, if I'm trying to find the header that contains getRootLogger:
cd /usr/include
# Debian calls 'ack' ack-grep. Your system may differ.
# Add \b before and after to only match a complete word.
ack-grep '\bgetRootLogger\b'
ack will return a nicely formatted and colorized list of matches.
You can wrap this up in a function and put it in your .bashrc file (or equivalent) for easy use:
function findheaderfor() {
ack-grep \\b$1\\b /usr/include /usr/local/include
}
Try the man pages, I use them a lot. You get the files you need to include.
Sometimes you want to pass a section number. Here are some examples :
man 2 socket
man 2 accept
man 3 fopen
man sem_post
2 is for system call related functions
3 is for function from the C library.
If there is no ambiguity, the section number is not needed
If you are looking for kernel function definition or kernel source navigation, you should definitely try lxr.linux.no
Sure, have you tried "man" in Linux?
For C functions, you may want to do "man 3 ".
You could use LSB Navigator (use search field in the top-right corner). However, most functions, about which you will find header information there, have manpages as well.

What is the meaning of man pages contaning e.g. git-branch(1)

Duplicate: https://stackoverflow.com/questions/587676/why-do-programs-in-unix-like-environments-have-numbers-after-their-name/
For instance, if I type:
man ps
...and then scroll to the very end I see something like this:
SEE ALSO
kill(1), w(1), kvm(3), strftime(3), sysctl(8)
How am I supposed to interpret this? I know that kill is another command but what's the meaning of (1)? Is there anything to this?
The git man page is riddle with these:
git-add(1), git-am(1), git-archive(1)
What is someone trying to tell me?
To access the man page for a given numbered section, type man number command
From man man
Executable programs or shell
commands
System calls (functions provided by the kernel)
Library calls (functions within program libraries)
Special files (usually found in /dev)
File formats and conventions eg /etc/passwd
Games
Miscellaneous (including macro packages and conven‐tions), e.g.
man(7), groff(7)
System administration commands> (usually only for root)
Kernel routines [Non standard]
So for example,
man 1 printf
Will give you the page for the shell printf command, whereas
man 3 printf
Will give you the page for the C library call.
The man pages are divided into sections, e.g. for system calls, commands, macros etc. mainly to prevent name conflicts, e.g. when a system call has the same name as a command.
One example for this is sleep:
man 1 sleep
versus
man 3 sleep
Section 1 is reserved for user commands.
The contents of man are divided into several sections:
Commands available to users
Unix and C system calls
C library routines for C programs
Special file names
File formats and conventions for files used by Unix
Games
Word processing packages
System administration commands and procedures
So kill(1) is about a command but strftime(3) is about a C routine.
Man pages are divided into sections. For example section 1 has commands and 2 has system calls.
If you run man kill it finds kill(1) which is the command.
If you run man 2 kill it shows you the system call also named kill.
Same goes for crontab(1) and crontab(5).
As other say, man pages are divided into sections. git-branch(1) refers to the man page named git-branch in the section 1 of manual. You access this specific man page with one of the two commands (depending of your flavour of man):
man 1 git-branch
or
man -s 1 git-branch
Moreover, some items can appear in several sections, with different meanings, e.g., printf(1) and printf(3). Typing:
man printf
displays man page for the first item found, depending of the order of your MANPATH environment variable. You can reorder MANPATH for changing your priority of sections or use:
man -a printf
for displaying all man pages for printf.

Resources