fortune

Print a random quotation (“fortune cookie”) from a database of sayings.

Category: Fun quotes terminal motd cowsay-friendly

Install

# RHEL / Alma / Rocky (often via EPEL)
sudo dnf install epel-release
sudo dnf install fortune-mod

# Debian / Ubuntu
sudo apt install fortune-mod fortunes

# openSUSE
sudo zypper install fortune

# Arch
sudo pacman -S fortune-mod

What it does

fortune prints a randomly selected quote from “fortune files”. It’s often used for a little terminal personality (login message, shell startup, MOTD), or piped into other fun tools like cowsay.

How it works (mechanical)

  • Reads precompiled “fortune database” files (typically under /usr/share/games/fortunes).
  • Selects an entry at random (optionally filtered by length or pattern).
  • If the program is installed but you see “no fortunes found”, you likely need to install the fortunes data package too.

Quick Start

# Print a random fortune
fortune

# Short fortunes only
fortune -s

# Long fortunes only
fortune -l

# Pick from a specific fortune file (example)
fortune literature

10 Practical Examples

  1. Basic use
    fortune
  2. Short fortune (good for prompts)
    fortune -s
  3. Long fortune
    fortune -l
  4. Show the source file name
    fortune -f
  5. Pick from one category/file
    fortune wisdom
  6. Match a pattern (regex)
    fortune -m 'linux|unix'
  7. Weight multiple sources
    # 80% 'wisdom', 20% 'science'
    fortune 80% wisdom 20% science
  8. Pipe into cowsay
    fortune | cowsay
  9. Pipe into lolcat (if installed)
    fortune -s | lolcat
  10. Use at login (bash)
    # Add to ~/.bashrc
    fortune -s

Notes & Gotchas

  • “No fortunes found” usually means the quote databases aren’t installed. Install the fortunes data package for your distro.
  • Content varies: some fortune sets include jokes, quotes, pop culture, etc. If you’re adding it to login scripts, choose the databases you’re comfortable displaying.
  • Determinism: it’s intentionally random; for reproducible output you’d need to control randomness externally.

Historical Context

The original fortune idea comes from classic UNIX/BSD “games” utilities: small programs that add personality and delight to the terminal. On many Linux distributions, the common implementation is fortune-mod, a widely packaged fork/port.

Modern Equivalent

There isn’t a strict “modern replacement” — fortune is already lightweight and still fun. Modern terminal personalization often pairs it with tools like cowsay, prompt frameworks, or MOTD generators.

Related Commands

  • cowsay — speak the fortune with ASCII art.
  • lolcat — colorize fortune output.
  • figlet / toilet — big banner text for MOTD.
  • motd tooling — distro-specific message-of-the-day scripts.