đź”— View fortune-files on GitHub

Why Fortune is cool

I once visited the famous punk club, CBGB in New York and was amazed by the layers of stickers and graffiti that covered every available surface. It was a tangible sign of how many amazing shows had been performed there over the decades. Everywhere you looked there was something new, overlapping in layers and scattered with graffiti in everything from pen to pocketknife to lipstick. Since 1979, fortune has been like the walls of that club. Unknown thousands have contributed to it over the years. Now fortune, aside from supplying fun little quotes, captures something of the rich hitorical sweep and culture of Unix (yes this includes Unix and Unix-like systems such as Linux, FreeBSD, macOS etc.)

a random Unix fortune.

UNIX was half a billion (500000000) seconds old on Tue Nov 5 00:53:20 1985 GMT (measuring since the time(2) epoch). – Andy Tanenbaum

run it again and get a different fortune

The famous politician was trying to save both his faces

and again

“Life, loathe it or ignore it, you can’t like it.” – Marvin, “Hitchhiker’s Guide to the Galaxy”

That’s the beauty of this simple, delightful program.

What is Fortune?

fortune is one of the simplest — and oldest — Unix programs. It works like this:

  • A text file contains fortunes (quotes, jokes, snippets), each separated by a single % on its own line.
  • The strfile program reads that file and creates a binary .dat index — this makes random lookups fast and efficient.
  • When you run fortune, it just picks an entry from that index and displays it.

That’s it — no AI, no databases, just plain text and a tiny bit of Unix cleverness that’s survived for nearly 50 years.

There are options and some tricks for creating your own, but at its essence, fortune is a perfect example of the Unix philosphy that programs should do one well and be able to chain together with other programs. That makes fortune, not just a quote generator, but a source of random-ish text that you can use in all sorts of creative ways.

Tour of my collection

I have compiled a few collections that I really enjoy:

  • rules - The Ferengi Rules of Acquisition from Star Trek Deep Space 9
  • deep-thoughts - Deep Thoughts by Jack Handey
  • rickmorty - sometimes you need a Rick Sanchez quote
  • oblique - Adaptation of Brian Eno’s Oblique Strategies. These are lateral thinking prompts that can be really helpful when you are stuck on a project
  • journal-prompts - A collection of 100+ journaling prompts to get the creative juices flowing.
  • grumble - my personal collection of quotes without a theme.

I allow these to pop up randomly for the most part but it’s really nice sometimes to be able to run fortune oblique and get something like:

Don’t stress one thing more than another

Since the fortunes live in plaintext next to the binary dotfile, it is easy to get statistics with grep and wc -l.

For instance, I did a number of searches for prominent people to see who had the most quotes:

cd /usr/share/games/fortunes
grep -i "Linus Torvalds" * 2>/dev/null | wc -l 

That yielded some shocking shortcomings. Linus Torvalds is quoted 152 times. Larry Wall, the creator of Perl, is quoted over 550 times! Poor Ken Thompson, the brilliant co-creator of Unix itself is only mentioned a handful of times. It was fun to explore and led me to add some quotes to my own collection to beef up those numbers! Luckily, once again, fortune is simple and fun to play with!

Install and Use

To get started, if fortune is not already installed (some distros include it, some don’t), just run:

# Debian / Ubuntu / Mint
sudo apt update
sudo apt install fortune-mod fortunes

# Fedora / RHEL / CentOS / Rocky
sudo dnf install fortune-mod fortune-mod-data

# Arch / Manjaro
sudo pacman -S fortune-mod

# macOS 
brew install fortune

Once complete, you should be able to run fortune and get a prompt. The fortunes package is often missing (I’m looking at you macOS) and needs to be installed so that you have the full collection of standard fortune dat files.

Installing system-wide vs local folder.

Once you have fortune installed, adding more like the ones from this collection, is easy. You can choose whether to install them system-wide or only for your user account.

System-Wide Place your fortune files in:

  • Linux: /usr/share/games/fortunes
  • macOS: `$(brew –prefix fortune)/share/games/fortunes

Installing system-wide requires sudo.

Local (User only) Make a folder for your fortunes

mkdir -p ~/.local/share/fortunes
cp myfile myfile.dat ~/.local/share/fortunes/

Then point fortune there by adding this to your .bashrc/.zshrc

export FORTUNE_PATH="$HOME/.local/share/fortunes"

Then reload (open a new terminal tab or source your startup file with a command like source .bashrc or source .zshrc)

Now fortune will pull from both system and personal fortunes.

Makefile magic

In order to make it as easy as possible to install and use my fortunes and any you might create, I have included a Makefile.

To use, simply run the following after cloning the github project to your local system:

make                # Compiles all fortune files into .dat
sudo make install   # Installs them into the correct fortune directory
make clean          # Removes all .dat files

Adding to your shell startup

You may want to display a random fortune from your shell startup files. Simply add the following to the end of your .bashrc, .zshrc or whichever file you are sourcing last if you have a complex startup.

Simply add fortune on a line by itself.

There are some switches you may want to be aware of. If you want to run a specific fortune each time add it like so:

fortune oblique

To choose only short fortunes, provide the -s argument like so: fortune -s

By default, most modern fortune packages try to keep potentially offensive fortunes separate. If you want to see those you can supply the -o argument, like fortune -o

Adding your own fortunes

fortune is one of those small, joyful tools that makes Unix feel alive — and it only gets better when you fill it with your own words, jokes, or wisdom. Luckily, making your own fortunes is easy! Simply open the fortune file (not the .dat) and add anything you like ensuring only that each line is separated by a % symbol. That might look like the following:

this is a fortune 
%
this is another fortune
% 
this is yet another fortune

Once you have finished editing, you’ll need to run strfile on simply use the Makefile.

Manually, you would just need to run: strfile my-fortunes my-fortunes.dat

you can then run `fortune ./my-fortunes or if you use my directory, simply run the Makefile like this:

make and sudo make install

Done! you should now have a fully working fortune file that anyone on your machine can use.

Conclusion

I am very fond of the fortune program. I have used it in shell startup for decades. I have displayed it using the wonderful GeekTool app on Mac and even in the output of my publish-adminjitsu script. It’s just ridiculously easy to use and it always makes me smile

In 1869 the waffle iron was invented for people who had wrinkled waffles.

Have a favorite quote, a missing collection, or an idea for a new fortune file?

📬 feedback@adminjitsu.com — Send me your best lines, corrections, or ideas.

Or, if you’re feeling fancy, open a pull request on the GitHub repo: https://github.com/forfaxx/fortune-files