Skip to main content

Module 10: Advanced & Security

Lesson 104: fortune Command

In this lesson, you'll learn how to use the fortune command to display random quotes, witty sayings, and fortune messages in your terminal, and how to combine it with other commands to create a more personalized and entertaining command-line experience.

The fortune command reads from a collection of text databases called fortune cookie files, stored in /usr/share/games/fortunes/ (or /usr/share/fortune/ depending on your distribution).

Each file contains a set of quotes or sayings separated by a % delimiter. When you run fortune, it picks one entry at random and prints it to the terminal.

While it may seem like a novelty, fortune has a long history in Unix culture. It was commonly added to shell startup files so every new terminal session greeted the user with a random quote, which many sysadmins still do today.

Installation

sudo apt install fortune          # Debian/Ubuntu/Mint

Or:

sudo dnf install fortune-mod      # Fedora/RHEL 9+

Or:

sudo yum install fortune          # RHEL/CentOS 7/8

Or:

sudo pacman -S fortune-mod        # Arch Linux

Or:

sudo apk add fortune              # Alpine Linux

Or:

sudo zypper install fortune       # OpenSUSE

Or:

sudo emerge -a sys-apps/fortune   # Gentoo Linux

Syntax

fortune [OPTIONS] [CATEGORY] [FILE]

Options

Option Description
-a Include offensive fortunes from the off subdirectory
-c Show the category (source file) the fortune came from
-e Give equal probability to all fortune files regardless of size
-f List all fortune files and their percentage probability
-l Show only long fortunes
-s Show only short fortunes
-n <chars> Set the threshold between short and long (default: 160 characters)
-i Case-insensitive pattern matching (used with -m)
-m <pattern> Display fortunes matching a regular expression pattern
-o Show only fortunes from the offensive (off) files
-w Wait before exiting (one second per line of the fortune)

1. Display a Random Fortune

fortune
The most likely way for the world to be destroyed, most experts agree,
is by accident. That's where we come in; we're computer professionals.
We cause accidents.
        -- Nathaniel Borenstein

Running fortune without arguments picks a random quote from all available non-offensive fortune databases. The output varies every time, which is the entire point.

2. Show Which Category the Fortune Came From

Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’