Forced to use Zsh by macOS Catalina? Let’s fix our “history” command first

How to have a long history list to find previous commands easier

Rand Grey
Rand Grey
Dec 8, 2019 · 2 min read

I have a long history using the “history” command in Linux. It is like a poor man’s GitHub gist. What did I do to find a specific file? How did I compress that directory again? The history command (used with grep) means you only have to remember part of your command. For example, history 1 | grep find will give you an instant recall of all your favorite find commands.

With macOS Catalina arriving on my new laptop, I needed to setup my history settings again. I used to do this in bash, but now Apple has made the Zsh the default shell. A few things have changed.


The file /etc/zshrc contains your machine’s default settings for the history command. The following are the defaults and what I changed mine to:

# File: /etc/zshrc
# Save command history
HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history
HISTSIZE=2000
SAVEHIST=1000

You can see in your current terminal shell that the values match /etc/zshrc:

% echo $HISTFILE
/Users/me/.zsh_history
% echo $HISTSIZE
2000
% echo $SAVEHIST
1000

Here is what I prefer instead of the defaults. Make it big… real big:

% cat .zshrc
HISTSIZE=99999
HISTFILESIZE=999999
SAVEHIST=$HISTSIZE

You can edit your own ~/.zshrc file to add in the above 3 lines.

We’re close to having history setup. But, if you run the history command by itself, you still only see the last 16 lines. While it is interesting what I did 5 minutes ago, I often want to see what I did 5 weeks ago. I want to see something really old in history and I will follow it with a grep. What did I do to download that repo last month?

% history | grep "git clone"

Ahh, I forgot that I need to add the 1 parameter in order to start from the beginning of history. My command changes to look as follows.

% history 1 | grep "git clone"

I don’t want to always have to type the 1. The solution is to alias my history command. Add the following to your ~/.zshrc file.

alias history="history 1"

Some people don’t like to alias the default behavior of a built-in shell command, so they may shorten to “hist” as follows. I create a new command to use called “hist” that will always run history 1. Instead of the above alias, use the following:

alias hist="history 1"

So my new command for history with a grep becomes:

% hist | grep "git clone"

You now have a shorter and more powerful command than the default “history” command. It’s quicker, easier, and more seductive. 😏

Rand Grey

Written by

Rand Grey

Just one of many fans of Charles Dickens.

Mac O’Clock

The best stories for Apple owners and enthusiasts

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade