I was just asked to write an article about how to simulate
on systems that don't have it.
I have to confess that
I've never faced this problem.
But I was able to come up with a
Your mileage may vary - particularly since different UNIX
implementations have different ways of storing their manual pages.
The solution has two parts.
First, you need a script that builds an
index; that's better than grep
ping through every manual page in the
Not always (50.6
Then you need an apropos
alias that automatically searches
your index file.
Here's the script to build the index file:
# manindex: Generate a list of topic lines that you can grep through.
# Then create 'apropos' and other aliases to search the list.
# Run this periodically-once a month should suffice
mandir=/usr/share/man # where the manual pages are stored
manlist="cat1 cat2 cat3" # list particular directories you care about
rm -f $indexfile
for directory in $manlist
# the sed command turns filenames into "manual page" names
# e.g., converts sed.1.z to sed.
# BUG: won't handle names like a.out.4.Z correctly
for manpage in `ls | sed -e 's/\..*$//g'`
# use man to unpack the manual page; it might be compressed
# use col to strip garbage characters
# egrep looks for spaces, manual page name, and dash
man $manpage | col -b -x | egrep "^ +$manpage.* - " | uniq
done > $indexfile
This script goes through every directory in which manual pages are
It strips all suffixes from the filenames, and then uses
to print the actual manual page.
This is better than trying
to look at the raw manual pages themselves because some vendors don't
provide the raw manual pages.
If you let man
give you the page you
want, you'll always find it.
command strips out boldfacing, underlining, and other monstrosities
that will confuse grep
looks for lines
to put in the index.
It's not as fussy as the BSD catman
program (which mkindex
is emulating), so it will find a fair
number of lines that don't belong; but we think this is only a mild
Before you can use this script
you'll have to substitute definitions for three variables:
The top-level directory in which manual pages are stored.
, but it may be different on your system.
Subdirectories containing the manual pages you care about.
probably want the directory in which user-level commands are stored,
as a minimum.
This level of directory naming may be radically
different on different systems.
I think this script is flexible
enough to handle all the variations I can remember; if it can't,
you'll have to hack it up a bit.
The file in which you want to keep your index (the output of this script).
to run for a long time; several minutes or
more, depending on how thorough you want to be.
Fortunately, you don't need to do this very
often: once to get started, and then once a month (or so) to pick up
any "stray" manual pages that someone else may have added.
If you want
to speed the task up, remember that you can skip any sections of the
manual that you're not interested in by defining manlist
For example, if you're not interested in section 2 of
the manual, just leave cat2
out of the list.
Once you've created the index, the rest of the problem is easy.
make yourself an apropos
and add it to your .cshrc
alias apropos "grep -i \!$ /home/mike/manindex.txt"
Here's what its output looks like:
acctcom - search and print process accounting file(s)
egrep - search a file for a pattern using full regular expressions
fgrep - search a file for a character string
fmlgrep - search a file for a pattern
grep - search a file for a pattern
pathconv - search FMLI criteria for filename
As I pointed out, this isn't perfect.
But I think it's a reasonable