0

Is there anyway to create a textfile that functions the same way the man command works in unix? Essentially creating a formatted textfile that serves the same purpose as the manual from Unix. Is there anyway that I could use the grep or sed command to essentially pull command information from this Manual text file?

If anyone has any resources or any tips for how I could get started or learn how to do this that would be helpful.

2 Answers2

1

Manually man man, my man.

man man

:-)

visibleman
  • 3,175
  • 1
  • 14
  • 27
1

Man pages are stored in a man directory often under /usr/share, you can use manpath to find the directories used by your distribution. This directory is usually divided into sub directories man1, man2,... etc corresponding with the man sections and the files are named program_name.1 (where 1 is the section number). For example the man file for cat could be found in /usr/share/man/man1/cat.1.

These files are written using troff (a typesetting language) with the man macro package. You can view these files directly however they are kind of confusing if you do not understand troff syntax. You can use the command

nroff -man man_file.1

to view the typeset version of the manual, in fact the man command basically just finds the man file you are looking for and runs it through nroff and less. You can mimic this functionality with pipes:

nroff -man man_file.1 | less

Some systems compress their man files in which case you will need to use gunzip first:

gunzip -c man_file.1.gz | nroff -man | less

Therefore to search the man file you can just pipe this output to grep, sed, or even into a file for further processing. One thing to note is that the output of nroff will include some escape sequences for formatting on a terminal, so it might look messy if opened in a text editor, although it will still work with programs like sed.

You can find more information about troff from the following links:

  • Groff The GNU implementation of troff (used on most systems).
  • Troff Resources A collection of papers on troff and its various preprocessors.
  • Unix Text Processing A book on troff and other unix based text processing.
Tucker
  • 36
  • 4