Related
Summary
Ever thought your terminal could be a source of daily wisdom or humor?
What Is the fortune Command?
It is your digital fortune cookie that offers a slice of wisdom or a chuckle whenever you need it.
Why add fortunes to your terminal?
Its just for fun!
you might use them in your system’s message of the day.
Personally, I find the fortune command handy when I need some quick text to testregular expressionsin the terminal.
To use fortune, you first need to double-check it’s already present in your system.
Theoriginal version of fortunewas created for a Unix-like operating system called NetBSD.
However, if you’re using Linux, it’s possible for you to’t use that original version directly.
Instead, you have to use a modified version calledfortune-mod.
So, when you’re installing fortune on a Linux system, you’re actually installing the fortune-mod package.
This version has been adapted specifically to work on Linux.
On all major Linux systems, you’re free to install fortune via default package manager.
However, it also comes with several options that let you enhance your experience.
Let’s check out some of them:
Option
Description
-a
This option includes both offensive and inoffensive fortunes.
-s
This option tells fortune to only display short quotes.
-f
Print a list of files that will be searched, without actually printing a fortune.
-e
Using this option gives all files an equal shot.
By default, longer files have a higher chance of being selected.
For example, if you want to see fortunes about love, you could typefortune -m love.
-n
Set the maximum length for a fortune to be considered short.
The default is 160 characters.
Anything longer fortune will classify as “long.”
That’s right, it’s a straightforward process.
In this way, you’re not bound to the predefined messages.
To try it out, simply open your terminal and create a plain text document using yourfavorite text editor.
Once your file is ready, you better convert it to a format that fortune can use.
This location can vary, but it often looks like “/usr/share/games/fortunes/” or “/usr/local/share/games/fortunes/”.
Finally, you’re able to use the fortune command to get fortunes from your customs file.
Every time you initiate the command, one of your hand-crafted fortunes will appear.
This fun command displays anASCII artcow in your terminal that says whatever you input.
There’s no need for argumentsjust provide some text, and you’re good to go.
You’ve got a cow dispensing wisdom right there in your terminal.
Just what you always wanted!
But waitthere’s more!
it’s possible for you to also change the character delivering your fortune.
If yes, then you oughta add a fortune command to the end of your~/.bashrc file.
The first thing you better do is to edit your shell configuration file.
Forbash shell, the configuration file is likely ~/.bashrc, and forzsh, it’s ~/.zshrc.
After saving changes, press Ctrl+X to exit the editor.
Another clever use for fortune isgenerating random numbers.
To accomplish this, you’ll need to make your own fortune file, as explained above.
There are severalfun Linux commandsthat can brighten your day, much like the classic fortune command.
Some that I find particularly amusing is thefake Linux hacking commands.