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.

Terminal window showing the manual page for the Mutt email client on Linux

Why add fortunes to your terminal?

Its just for fun!

you might use them in your system’s message of the day.

Four hard drivers sticking out of a rack-mount server that’s being used as a NAS.

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.

Linux terminal with Tux depicted as a fortune teller.

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.

Running fortune command in Linux terminal.

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.

Adding fortunes text to a plain text file using nano text editor in Linux terminal.

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.

Converting plain text file to fortune supported file using strfile command.

-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.

Listing all fortune source files using the -f option of fortune command.

-n

Set the maximum length for a fortune to be considered short.

The default is 160 characters.

Anything longer fortune will classify as “long.”

Displaying random saying from your newly created fortune file.

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.

Piping fortune output to cowsay command to display random saying along with ASCII art.

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.

Tux displays random statements using fortune and cowsay commands.

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.

Making the ouptut of fortune and cowsay colorful using the lolcat command.

You’ve got a cow dispensing wisdom right there in your terminal.

Just what you always wanted!

But waitthere’s more!

Adding fortune command along with cowsay to the end of bashrc file.

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.

Random fortune appearing on a Linux terminal after being launched.

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.

Adding new fortune command with tux ASCII art to the end of bashrc file.

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.

Viewing the file using the cat command.