Gentoo Wiki


This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other



Do you ever get bored logging in to the same old terminal every day? Wouldn't it be great if we could somehow make it more exciting? Whenever the fortune program is run it prints random amusing or interesting (hopefully) things in the terminal to brighten up your day. We can make this program run every time you log in...

Getting Started

Get Fortune

Thanks to Portage this part is easy:

#emerge fortune-mod-all

Or, for even more:

#emerge -va --noreplace `ls /usr/portage/games-misc|grep fortune`

Does It Work?

At a command prompt, invoke the program. You should get some interesting text:

$ fortune
Tell a man there are 300 billion stars in the universe and he'll believe you.
Tell him a bench has wet paint on it and he'll have to touch to be sure.

You do specific fortunes by passing the name of the topic, and you can use the '-o' parameter for offensive fortunes (you need 'offensive' in your USE flags when you emerged fortune for that to work). 'fortune -a' will choose from both the offensive and regular fortunes.

$ fortune kernelcookies
rio_dprintk (RIO_DEBUG_ROUTE, "LIES! DAMN LIES! %d LIES!\n",Lies);
$ fortune -o
"It was man, mortal bloody man, who created the myths...
 Religion is nothing but wish-fulfilling stories for the masses."
             [James Herbert, "Shrine"]

Make your own!

It's as easy as 1 2 3!

1. Create your own fortune file

File: ~/.fortune
I don't have any reason to take a shower anymore because there aren't any girls I like right now.
~ SlickC92
Pencils are like dogs.
~ Chase Quintana
Sometimes you turn into a girl unexpectedly... like Will.
~ CoolAJ86

2. Make a "dat" file

strfile -r .fortune

3. Fire away

fortune ~/.fortune

NOTE: You must give an absolute path.

Let the fun begin!

Add To Login

Simply add the line fortune to the bottom of your ~/.bashrc file. Here's mine:

File: ~/.bashrc
export PATH=$PATH:/usr/local/bin
export PS1="\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]"
alias ls='ls --color'

DISCLAIMER: Be aware that this can (and will) break scp and related commands.

Make sure you have something similar to this in your .bashrc:

File: ~/.bashrc
# Test for an interactive shell.  There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
if [[ $- != *i* ]]; then
   # Shell is non-interactive.  Be done now

Alternative solution: You can also put your interactive commands in .bash_profile

NOTE: If you have found the delay of fortune launching upon login too long you can also use a cronjob to write the /etc/motd file instead something like the following will work just fine:

*/5 * * * * /usr/bin/fortune > /etc/motd

Dancing the samba with fortunes

Send fortunes via Windows Messenging provided by Samba:

$ fortune | smbclient -M * -U GOD

(This might be a nice line for a nightly cronjob.) An endless loop to annoy people:

$ while [ true ]; do fortune | smbclient -M * -U GOD; done

Well, have fun annoying people. I'm not responsible for your actions and the results thereof (Like you eating lunch alone for the next three weeks). Source for Step 4:

The cow said it, I swear!

When you get tired of a plain fortune every time you open a new shell, you can always enchant your experience with cowsay, like this:

emerge cowsay
cowsay -d `fortune -o -s`

Now, your fortunes will be both offensive (if you have 'offensive' as a use-flag, that is), short AND told by a dead cow.

This is an example, don't mind the fortune:

/ If women ran the military complex, \
| would the missiles be shaped       |
\ differently?                       /
        \   ^__^
         \  (xx)\_______
            (__)\       )\/\
             U  ||----w |
                ||     ||

Put it in your e-mail!

Ever notice how the 1337 you know always have cool quotes in their e-mails to you and that they're different every time? Now you have the power to be 1337 too!!! Simply add a little cron here and a little tag line there, here a fortune, there a fortune, everywhere a fortune-mod:

Create a file with your standard greeting

File: ~/.signature.tag

Then create a nice little script that joins this with a fortune.

File: ~/bin/

echo `/usr/bin/fortune -n 150 -s politics` | cat ../.signature.tag - > ../.signature

Make a cron job to run the script every 5 minutes.

echo "#min    hour   date     mon     wkday   command" >> ~/crontab.cron
echo "*/5     *       *       *       *       $HOME/bin/" >> ~/crontab.cron
crontab ~/crontab.cron

Some mail programs will automatically pick up on the .signature file, thunderbird doesn't, but if you go into the account preferences you'll find a place to specify a signature file. Since thunderbird doesn't show dot-files by default I create a link.

ln -s .signature signature

Now you are teh 1337!!! Send some messages and show your friends that all your e-mails are belong to us!


If you don't have a ~/.bashrc file you can create one and add the fortune command all at once by going:

$ echo fortune >> ~/.bashrc
Retrieved from ""

Last modified: Fri, 05 Sep 2008 23:15:00 +0000 Hits: 32,487