Monday, January 28, 2008

Make fortune files from the whatis database in FreeBSD

Fortune is a neat way to help learn bits of information so why not turn the whatis database into a fortune file to help discover some of the less used FreeBSD commands (or any other section of the man pages)?

If the whatis database does not exist run "makewhatis" as root, or if you don't have root access run "makewhatis -o whatis" to make your own personal copy. You also need the games distribution files installed.

Ok let's make fortunes...

To make the whole whatis database into a fortune file:

$ cat /usr/share/man/whatis | sed 's/$/\
\%/g' > whatis-fortune

$ /usr/games/strfile whatis-fortune whatis-fortune.dat


[Note that the sed command is split over two lines, type it exactly as shown.]

To make just one man section into a fortune file, section 1 in this example:

$ cat /usr/share/man/whatis | egrep "^.+\(1\) +- " | sed 's/$/\
\%/g' > whatis1-fortune

$ /usr/games/strfile whatis1-fortune whatis1-fortune.dat


Naturally substitute 1 with any man section number to make a different fortune file.

Test it with "fortune whatis1-fortune".

If everything is happy you can put it in your .profile (under the freebsd-tips fortune line of course) with the full path to the fortune files if you didn't put them in /usr/share/games/fortune.

No comments: