Skip to content

Start Terminal sessions with a possibly-witty quote

Really long-time Unix users—as in mainframe-based Unix—are probably familiar with fortune. This silly little program grabs a random line from a collection of files holding quotes, sayings, jokes, etc. The Unix I used many decades ago would print an entry from fortune each time you started a new session. Here are some examples of what might greet me each time…

"It's a dog-eat-dog world out there, and I'm wearing Milkbone underware."
-- Norm, from _Cheers_

Mobius strippers never show you their back side.

All constants are variables.

Years ago, I had set up my Mac's Terminal to output a fortune each time I opened a new session (window). At some point, though, I forgot to set it up on a new system, so it was gone. While fortune isn't included in macOS' Unix core by default, there are many ways to get it back, and it's relatively simple to do so. Here's one way…

You can find fortune in both MacPorts and Homebrew; as I use Homebrew, that's the method I'll cover here. Once you have Homebrew installed, it's trivial to install fortune:

brew install fortune

After a bit of time, fortune will be installed, and ready for use. If you run it at the command line, you'll get a random quote:

$ fortune
Decision maker, n.:
The person in your office who was unable to form a task force
before the music stopped.

There are many command line options, including the ability to read from files not included with fortune; use man fortune (or even better, my tip to view man pages in Preview) to see everything that it can do.

To see a new fortune each time you open a new Terminal session, you need to edit your user's .profile file. This file needs to live in the top level of your user's folder; experienced Terminal users probably already have one, but if you don't, here's how to create it:

$ cd
$ open -e .profile

The first command, cd with nothing following, insures that you're in your home directory before creating the file. The second command opens a new empty file and opens it in TextEdit; you just need to add one line:

fortune

If you'd like the fortune to have some whitespace, you can surround it with a couple blank lines:

echo ""
fortune
echo ""

Save the changes, quit TextEdit, then close Terminal and open a new window, and you should be greeted with a random quote or joke or observation.

You can do a ton of stuff in a .profile file; so much so that I'm not going to get into it at all—but a web search can be enlightening.

I'll just leave you with the fortune I received this morning, when opening Terminal to help write this hint…

Truth has always been found to promote the best interests of mankind...
- Percy Bysshe Shelley

4 thoughts on “Start Terminal sessions with a possibly-witty quote”

    1. True - though cowsay will also have to be installed via Homebrew/MacPorts.

      -rob.

Comments are closed.