fortune
Display a random quote or saying
TLDR
Print a quotation
Print an offensive quotation
Print a long quotation
Print a short quotation
List the available quotation database files
Print a quotation from one of the database files listed by fortune -f
SYNOPSIS
fortune [ -a | -l | -o ] [ -e | -s | -i ] [ -c | -f | -w ] [ -D file ] [ -m pattern ] [ -n number ] [ -N number ] [ -F file ] [ -x ] [ -u ] [ percentfile ... ]
PARAMETERS
-a, --all
Consider all fortune files, including potentially offensive ones, not just the 'good' ones.
-c, --censored
Censor offensive fortunes. This is the default behavior.
-e, --equal-chance
Give all fortunes an equal chance of being picked, regardless of their file size. Useful for small files.
-f, --offend
Include offensive fortunes in the selection, but they are not chosen exclusively.
-l, --long-only
Print only long fortunes. A 'long' fortune is typically more than 160 characters.
-o, --off
Only print offensive fortunes. This option overrides -c.
-s, --short-only
Print only short fortunes. A 'short' fortune is typically 160 characters or less.
-i, --insensitive
Perform a case-insensitive match when using the -m option.
-m pattern, --match pattern
Print fortunes that contain the specified regular expression pattern.
-w, --wrap
Wrap long lines of text to fit the terminal width, useful for readability.
-F file, --fortune-file file
Read fortunes from the specified file instead of the default databases.
-x, --exclude
Exclude specific fortune files or directories from consideration.
-u, --unbuffered
Turn off output buffering. Useful for scripts that need immediate output.
-D file, --directory file
Read fortunes from the specified directory, treating it as a collection of fortune files.
-n number, --number number
(Deprecated) Show a specific fortune by its 0-indexed number within the selected files.
-N number, --nth number
(Deprecated) Show the number-th fortune (1-indexed) within the selected files.
percentfile ...
Specify a list of fortune files or directories along with their percentage chances of being selected. E.g., 'literature%20 science%80'.
DESCRIPTION
The fortune command is a classic Unix utility that displays a random message, often called a 'fortune', from a database of quotations. These messages can vary widely, from humorous jokes and puns to insightful sayings, historical quotes, or short stories. It's commonly used by users in their shell startup scripts (like .bashrc or .profile) to provide a fresh, entertaining, or thought-provoking message each time they log in or open a new terminal. The command reads from pre-compiled fortune databases, typically located in system directories like /usr/share/games/fortune/. Users can choose to include or exclude categories of fortunes, such as offensive content, or filter fortunes based on length or specific patterns. It serves as a simple yet effective way to inject a bit of randomness and fun into the command-line experience.
CAVEATS
The -n and -N options are deprecated and may not work as expected or be removed in future versions. The variety and nature of fortunes depend entirely on the installed fortune databases on the system. Some distributions may not include offensive fortunes by default.
FILES
Common locations for fortune databases include /usr/share/games/fortune/ and /usr/local/share/games/fortune/. Users can also create their own fortune files, typically stored in their home directory, like ~/.fortune.
CUSTOM FORTUNES
To create custom fortune files, simply put each fortune on a new line, separating fortunes with a '%' character on a line by itself. Then, run strfile on your custom file to create the necessary .dat index file for fortune to read it efficiently.
HISTORY
The fortune command is one of the oldest and most beloved utilities in the Unix ecosystem, originating from the early BSD distributions. Its primary purpose was to provide a bit of lightheartedness and entertainment in the command-line environment. The accompanying strfile utility was developed specifically to efficiently store and retrieve these textual fortunes, allowing for quick access to large databases. Over the decades, it has remained a staple for many users, often appearing in login messages or shell prompts.
SEE ALSO
strfile(1), mkstr(1), datamaker(6)