How to use the command 'fortune' (with examples)
The fortune
command is a simple, light-hearted utility available on Unix-like operating systems. It prints random, often witty or humorous, quotations known as “fortune cookie” sayings. These quotations may come from various sources, like literature, famous personalities, or cultural references. It serves as a delightful way to start your terminal sessions with some interesting snippets and can be a fantastic source of amusement or inspiration. The versatility of fortune
allows users to customize their experience, generating sayings of different moods or lengths, and even specifying particular databases of quotes.
Use case 1: Print a quotation
Code:
fortune
Motivation:
Using this command is an excellent way to inject a touch of humor or wisdom into your day. Whether you’re staring at code, working late nights, or simply taking a coffee break, a quick, random fortune can provide a refreshing change of pace and provoke thought or laughter with minimal effort.
Explanation:
This simple command calls fortune
with no arguments, which is the default form of usage. When run, it selects a random quotation from its database of hidden gems, known for being entertaining or thought-provoking. These quotes are akin to the messages found in fortune cookies, hence the name.
Example output:
You cannot run away from a weakness; you must sometimes fight it out or perish.
-- Robert Louis Stevenson
Use case 2: Print an offensive quotation
Code:
fortune -o
Motivation:
There are times when you might want to explore quotations that push the boundaries of traditional propriety, perhaps for intellectual curiosity or just a sharper edge of humor. The -o
option provides access to a collection of quotations that might be considered off-color or offensive.
Explanation:
The -o
flag is specified to instruct fortune
to select its output from its database of offensive quotes. These are separate from the regular ones as they might be inappropriate for all audiences. This ensures that users are aware of the nature of the content they are requesting.
Example output:
America! Love it or give it back.
Use case 3: Print a long quotation
Code:
fortune -l
Motivation:
This is beneficial when you’re in the mood for a more substantial piece of writing. Longer quotations often contain richer insights or more intricate humor, offering a deeper or more nuanced narrative than shorter snippets.
Explanation:
The -l
option stands for “long,” meaning fortune
will seek quotations longer than those it would typically produce. This option offers a deeper engagement with the content for those moments when you have a little extra time to read.
Example output:
The surest way to corrupt a youth is to instruct him to hold in higher esteem
those who think alike than those who think differently.
-- Friedrich Nietzsche
Use case 4: Print a short quotation
Code:
fortune -s
Motivation:
When you only have a second to spare but still want a quick philosophical kick or humorous jolt, a short quotation is perfect. It provides a brief but potentially significant distraction or reflection.
Explanation:
The -s
option tells fortune
to select a short quote, typically one-liners or brief passages that won’t take more than a moment to read. They’re concise, punchy, and easy to digest.
Example output:
All work and no play makes Jack a dull boy.
Use case 5: List the available quotation database files
Code:
fortune -f
Motivation:
This variant of the command would be particularly useful for more advanced users who are interested in understanding the scope of quotations available to them. By listing the databases, users can refine their experience by selecting specific sources rather than relying on random selection.
Explanation:
The -f
option, short for “files,” lists all the databases of quotations available to fortune
. This command reveals which databases contain the quotes that fortune
pulls from, which can be numerous and varied, depending on the system’s fortune installation.
Example output:
100.00% /usr/share/games/fortunes
50.00% funny
25.00% literature
12.50% wisdom
12.50% love
Use case 6: Print a quotation from one of the database files
Code:
fortune path/to/file
Motivation:
This example caters to users who prefer their fortunes to originate from a specific thematic database, allowing for a more personalized and directed experience. Whether interested in funny, philosophical, or motivational themes, users will have better control over the nature of the output.
Explanation:
Here, fortune
takes an additional command-line argument specifying the path to a particular database file. This option overrides the random selection process and sources the quotation directly from the designated file. Users often choose this method after identifying specific areas of interest via the fortune -f
command.
Example output:
If selecting from the “literature” database:
It is nothing to die; it is frightful not to live.
-- Victor Hugo
Conclusion:
The fortune
command may seem like a mere toy, but it brings joy, insight, and even a bit of edge into everyday computing tasks. With various options, users can tailor their experience to suit their current mood or curiosity. Whether you’re in the market for profound thoughts, sharp witticisms, or even a touch of the bawdy, fortune
accommodates, offering something for everyone.