fortunes: Fortune cookies for all
April 1st, 2007 edited by TinchoEntry submitted by Gaurav Vaidya. DPOTD needs your help, please contribute !
Fortune cookie programs store long lists of quotes, sayings, aphorisms, adages, IRC transcripts, and any other text which might be interesting. Since time immemorial (okay, okay, since 1979) Unix users have added fortune cookies to their .bashrc
(or equivalent) files, displaying a random quote every time a terminal is created. Quotes are drawn from subjects and sources of interest to geeks, from William Shakespeare to Douglas Adams, from Ambrose Bierce to Ziggy, from Linus Torvalds to the Fortune editors themselves.
On Debian/Ubuntu, the fortune cookie program of choice is available through the package fortunes.
Usage
The program is ridiculously simple to run: executing /usr/games/fortune
(or /usr/bin/fortune
) displays a pithy quote:
"I assure you the thought never even crossed my mind, lord." "Indeed? Then if I were you I'd sue my face for slander." -- Terry Pratchett, "The Colour of Magic"
Or perhaps something insightful:
It's hard to tune heavily tuned code. :-) -- Larry Wall in <199801141725.JAA07555@wall.org>
Or even self-referential:
This fortune would be seven words long if it were six words shorter.
Although the program works fine without any arguments, the following
may be helpful:
-o
- Display only offensive fortunes (you will need to install the offensive fortunes first; they are available in the fortunes-off package).
-a
- Display both offensive and non-offensive fortunes.
-w
- Wait for a while after displaying the comment, but before exiting. The amount of time waited depends on the number of characters in the fortune displayed; longer quotes will be ‘waited for’ longer. Very nice for scripting; for instance, running
while true; do fortune -w; done;
in a Bourne shell will display fortune after fortune, with a convenient pause after each one. My preferred script,while true; do echo === `date` ===; fortune -w; echo; done;
will do the same, except with a time-stamp at the top of each fortune.
Installing
To install, you will need to install the fortunes package. This package contains 15,000 quotes itself, and depends upon fortune-mod, which contains the executables, and fortunes-min, which contain other fortunes. These packages have been available in Debian and Ubuntu since long ago.
Other packages (available for both Debian and Ubuntu) allow you to install quotes in Chinese, Bulgarian, Portuguese, Czech, Slovak, German, Esperanto, Spanish, French, Gaelige (Irish), Italian, and Polish, as well as Debian hints and BOFH excuses.
The quotes used in this submission are from fortune-mod version 9708.
April 1st, 2007 at 7:53 am
Nice package indeed!
But are there any equivalents for other languages, say french for example?
I believe every language must some nice quotes.
April 1st, 2007 at 9:58 am
There are Italian fortunes, even offensive ones.
See the full language list:
http://packages.debian.org/cgi-bin/search_packages.pl?keywords=fortunes&searchon=names&subword=1&version=stable&release=all
April 1st, 2007 at 9:59 am
Jean-François Prévost :
knarf@glop:~ $ apt-cache search fortune french
fortunes-fr - French fortunes cookies
April 1st, 2007 at 3:35 pm
I’d just like to add a plug for ‘fortune disclaimer’, which I contributed.
It works great in your login script on systems where you have to have a lengthy management-dictated piece of legalese in /etc/motd.
April 1st, 2007 at 6:18 pm
Thanks for the fortune tips! Here’s another: Adding this little script to /etc/cron.daily/ gives ssh users a new fortune each day:
#!/bin/sh
/usr/games/fortune > /etc/motd
April 1st, 2007 at 11:46 pm
If you get a little program called cowsay (apt-get install cowsay), you could add this to your /etc/bash.bashrc to have a random ASCII character pop up with a fortune in your terminals:
if [ !$COWPATH ]
then
COWPATH=’/usr/share/cowsay/cows/’
fi
cow_file_length=`ls -1 $COWPATH | wc -l`
RANDOM=$$ # initialized the random seed with the process id of this script
let “random_line = $RANDOM % $cow_file_length + 1″
cow=`ls -1 $COWPATH | head -n $random_line | tail -n 1`
fortune -a | cowsay -n -f $cow
April 8th, 2007 at 3:59 pm
Yeah with cowsay, can be execute like this:
cowsay `fortune`
or summon different cow,
cowsay -f tux `fortune`
source.
August 15th, 2008 at 12:13 pm
root@box:/# crontab -l
# m h dom mon dow command
00 * * * * (/usr/games/fortune bofh-excuses | tail -n 1 > /etc/motd)