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

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

Rand Grey
Mac O’Clock

--

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

--

--