Creating Custom Man Pages
Man pages have been the primary source for UN*x documentation for a long time. Whenever I create a script that's going to be around for a while, I create documentation in the form of a section 1 man page. This stops my cell phone from ringing on the weekends when the junior sysadmins are looking for my notes.
Some people I know tend to shy away from writing man pages because they believe it's too difficult to learn how to correctly format man pages using troff or groff. Lucky for me, there's a much easier way to get the job done.
Marc Vertes (mvertes@free.fr) has written an excellent GNU AWK script called txt2man, which can run on almost any UN*X-like system, and can convert a flat ASCII text file to the correct man page format. txt2man (currently version 1.5.5-1) is distributed by the Fedora Project and is available from the EPEL Repository. The authors home page is http://mvertes.free.fr/txt2man/.
Once you've downloaded and installed the correct txt2man package for your system, you can get down to the business of creating a man page. First, get your information together into a single ASCII text file. You will still have to apply a specific formatting to your file, but nothing as complicated as troff/groff.
At the command line, type txt2man -h to view the built-in documentation, which will describe what to add to your file so that it gets correctly formatted later. The best example of how to format your text is actually the displayed help itself.
Using the command:
$ txt2man -h 2>&1 | txt2man -T
will display the built-in help and pipe it through txt2man to produce a formatted man page and preview it with the default pager. The same command, without the "-T" option, will display the troff/groff formatted output itself. If we redirect the output of the command to a file:
$ txt2man -h 2>&1 | txt2man > txt2man.1
and use gzip to compress the resulting file:
$ gzip txt2man.1
we can view the file as a regular man page:
$ man ./txt2man.1.gz
Notice I specified section 1 for my man page. By default, man will look for System Administration commands in section 8 and General Commands in section 1.
Now, all we need to do is copy our new man page to the appropriate directory for our system, as specified in the $MANPATH environment variable, or maybe in /etc/man.conf, depending on your UN*X/Linux distribution. On my RHEL5 systems, I keep my user generated man pages in /usr/local/man:
$ cp ./txt2man.1.gz /usr/local/man
Finally, I update the whatis database with:
# /usr/sbin/makewhatis
and now my man page is available to all users.
Pete Vargas Mas is an avid indoorsman and a Linux Consultant in the Washington DC Metro area. Pete is a RHCE and a MCITP, which so far has not caused any eddies in the space-time continuum. He spends most of his time these days herding 529 Linux servers.
Trending Topics
| OpenLDAP Everywhere Reloaded, Part I | May 23, 2012 |
| Chemistry the Gromacs Way | May 21, 2012 |
| Make TV Awesome with Bluecop | May 16, 2012 |
| Hack and / - Password Cracking with GPUs, Part I: the Setup | May 15, 2012 |
| An Introduction to Application Development with Catalyst and Perl | May 14, 2012 |
| Cryptocurrency: Your Total Cost Is 01001010010 | May 09, 2012 |
- OpenLDAP Everywhere Reloaded, Part I
- Strip DRM from WMV File
- Validate an E-Mail Address with PHP, the Right Way
- Boot with GRUB
- Why Python?
- A Statistical Approach to the Spam Problem
- Chapter 16: Ubuntu and Your iPod
- Why Hulu Plus Sucks, and Why You Should Use It Anyway
- Building an Ultra-Low-Power File Server with the Trim-Slice
- Science the GNU Way, Part I
- Editorial Standards?
4 hours 7 min ago - Great one
5 hours 41 min ago - Common form in many
6 hours 3 min ago - Awsome
11 hours 6 min ago - Euro 2012 Coupon Codes - Get 20% Off Pavtube TiVo Converter
3 days 9 hours ago - Euro 2012 Big Sale: 20% Off Instant Savings on TiVo Converter
3 days 9 hours ago - MakeMKV works as well, though
3 days 10 hours ago - Euro 2012 Big Sale: 20% Off Instant Savings on TiVo Converter
3 days 10 hours ago - Awesome
4 days 8 hours ago - Who worries approx the
4 days 10 hours ago





Comments
sudo txt2man -h 2>&1 |
sudo txt2man -h 2>&1 | txt2man | gzip -c > /usr/local/man/txt2man.1.gz
DocBook XML
I've noticed that at least one popular project writes its man page source in DocBook. DocBook XML has a wrapper called refentry used for encapsulating man pages. Projects can configure their makefiles to use a tool such as docbook2x or xsltproc to generate the man page. With tools like this you can actually generate multiple output formats.
Man pages for debian
I use Gmanedit in gnome to create man pages.
I know your hat is Red, but i'd like to add that according to debian policies, manpages for debian should be zipped with gzip -9 txt2man.1
Other Tools
I use Perl's POD (Plain, Old Documentation). It has headings, lists, in-line markup like bold and italic and limited hyper-links. Since most distros come with Perl already install, it's available to you right now.
References: