X
    Categories: Linux

6 steps to create linux man page

Normally we always use linux man page for any help or to get all the details with all options. why don’t we create our customized linux man page. To create linux man page we can use nroff utility. Normally man files are created using troff. troff is a bit difficult to use. So that’s Here we will learn to create linux MAN page for our custom binaries/programs using the command line tool nroff which is very easy to learn.

Follow below steps to create linux man page:

Step 1: Write a manual page in using vi. Use Man format only. for example I have written sample man page using vi for sample command “mycommand”.

[root@rhel1 ~]# cat mycommand
MYCOMMAND(1) User Commands

NAME
mycommand - this is test command for man page creation

SYNOPSIS
mycommand [OPTION]... [FILE]...

DESCRIPTION
List information about the FILEs (the current directory by
default). Sort entries alphabetically if none of -cftuvSUX nor
--sort.

Mandatory arguments to long options are mandatory for
short options too.

-a, --all
do not ignore entries starting with .

-A, --almost-all
do not list implied . and ..

--author
with -l, print the author of each file
[root@rhel1 ~]#

Step 2: use below command to create linux man page.

[root@rhel1 ~]# nroff -e -man mycommand|more -s
MYCOMMAND(1) User Commands

NAME
mycommand - this is test command for man page creation

SYNOPSIS
mycommand [OPTION]... [FILE]...

DESCRIPTION
List information about the FILEs (the current directory by
default). Sort entries alphabetically if none of -cftuvSUX nor
--sort.

Mandatory arguments to long options are mandatory for
short options too.

-a, --all
do not ignore entries starting with .

-A, --almost-all
do not list implied . and ..

--author
with -l, print the author of each file

--More--

Following are options details:

-e --> Produce equally-spaced words in adjusted lines, using full terminal resolution.

-man --> Macro name

Step 3: Rename it and give extension 1 to 8, any no. & then compress it with gzip.

[root@rhel1 ~]# mv mycommand mycommand.3
[root@rhel1 ~]# gzip mycommand.3
[root@rhel1 ~]# ll
-rw-r--r--. 1 root root 367 Dec 31 17:00 mycommand.3.gz
drwxr-xr-x. 2 root root 4096 Dec 31 16:36 p
[root@rhel1 ~]#

Step 4: Create man/man3 directory under your home directory.

$ mkdir -p $HOME/man/man3

Note: Here I renamed the file with the extension. 3, that’s why I created the man3 directory.

Step 5: Move gzip file in $HOME/man/man3  and use updatedb.

[root@rhel1 ~]# mv mycommand.3.gz $HOME/man/man3
[root@rhel1 ~]# updatedb

Please note that , The system stores its man pages at /usr/share/man/ directory , however to give example with all the details I have used non default location.

Step 6: Then use below command to open the created MAN page.

[root@rhel1 ~]# man -M $HOME/man mycommand
MYCOMMAND(1) User Commands

NAME
 mycommand - this is test command for man page creation

SYNOPSIS
 mycommand [OPTION]... [FILE]...

DESCRIPTION
 List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort.

 Mandatory arguments to long options are mandatory for short options too.

 -a, --all
 do not ignore entries starting with .

 -A, --almost-all
 do not list implied . and ..

 --author
 with -l, print the author of each file

(END)

Here -M is used to give path of man files. If you don’t want to use -M option every time you can add below “MANPATH” entry in “/etc/man.config” file as below, since /etc/man.config stores the details about linux man page.

[root@rhel1 ~]# cat /etc/man.config |grep MANPATH
# when MANPATH contains an empty substring), to find out where the cat
# MANPATH manpath_element [corresponding_catdir]
# MANPATH_MAP path_element manpath_element
# Every automatically generated MANPATH includes these fields
MANPATH /usr/man
MANPATH /usr/share/man
MANPATH /usr/local/man
MANPATH /usr/local/share/man
MANPATH /usr/X11R6/man
MANPATH /root/man

In above section we have added /root/man or $HOME/man MANPATH entry. Now you can use man command without any option as below.

[root@rhel1 ~]# man mycommand

MYCOMMAND(1) User Commands

NAME
mycommand - this is test command for man page creation

SYNOPSIS
mycommand [OPTION]... [FILE]...

DESCRIPTION
List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort.

Mandatory arguments to long options are mandatory for short options too.

-a, --all
do not ignore entries starting with .

-A, --almost-all
do not list implied . and ..

--author
with -l, print the author of each file

(END)

 

Related Post