LinuxCommandLibrary

fortune

Display a random quote or saying

TLDR

Print a quotation

$ fortune
copy

Print an offensive quotation
$ fortune -o
copy

Print a long quotation
$ fortune -l
copy

Print a short quotation
$ fortune -s
copy

List the available quotation database files
$ fortune -f
copy

Print a quotation from one of the database files listed by fortune -f
$ fortune [path/to/file]
copy

SYNOPSIS

fortune [-aefilnosw] [file ...]

PARAMETERS

-a
    Choose randomly from all fortune files.

-e
    Limit to short fortunes (under $FORTUNE_SHORT_LEN chars, default 80).

-f
    List available fortune files and exit.

-i
    Ignore case when classifying short/long fortunes.

-l
    Limit to long fortunes (over $FORTUNE_SHORT_LEN chars).

-o
    Limit to offensive fortunes (requires % flag in file).

-s
    Limit to short fortunes (under $FORTUNE_SHORT_LEN chars).

-w
    Wait for return key before exiting.

DESCRIPTION

The fortune command is a longstanding Unix utility that prints a random message, aphorism, joke, or philosophical quote from a database of fortune files. These files, typically found in /usr/share/games/fortunes/ or similar paths, contain categorized collections of short texts on topics like humor, literature, politics, and wisdom.

Without arguments, fortune selects randomly from the default set. Options allow filtering by length (short or long), offensiveness, or choosing from all files. It's often used in shell prompts, login scripts (e.g., /etc/motd), or combined with tools like cowsay for fun displays.

Each fortune file has a companion .dat index created by strfile, enabling efficient random access without loading entire files into memory. This design supports large collections while ensuring quick execution. Fortune adds whimsy to command-line interfaces and remains popular in Linux distributions via packages like fortune-mod.

CAVEATS

Requires fortune-mod or games package for files; offensive content may need separate install or % flag. Paths vary by distro (e.g., /usr/share/fortune). No network support.

FILE FORMAT

Fortunes are plain text with '%' separating entries. Use strfile file to build .dat index for random access.
Example: "A fool and his money... %"

COMMON USAGE

fortune | cowsay for ASCII art; fortune -s -o for short offensive quotes; add to .bashrc: fortune.

HISTORY

Developed by Ken Arnold in 1978 for BSD Unix as a fun utility. Ported to System V, Linux via fortune-mod package. Actively maintained with new quotes added over decades.

SEE ALSO

cowsay(1), strfile(8), figlet(1)

Copied to clipboard