Ubuntu – Creating a Fortunes file

command linefortune

How can I create a fortunes file and add it to the fortune* command on the shell?

*Fortune – "console command to print a random, hopefully interesting, adage."

Best Answer

This is explained in the manpages for fortune(6) and (especially) strfile(1).

Basically, you create a text file that contains your "fortune cookies" separated by a line that contains a single % sign and nothing else. Each fortune cookie can be 1 or more lines (including empty lines). A random example from one of the default fortune cookie files:

A day for firm decisions!!!!!  Or is it?
A few hours grace before the madness begins again.
A gift of a flower will soon be made to you.
A long-forgotten loved one will appear soon.

Buy the negatives at any price.
A tall, dark stranger will have more fun than you.

Then you use the strfile utility to create a binary search index (see its manpage for extra options). When you put both the text file and the binary index file in /usr/share/games/fortunes/, your new fortune cookies should be available.