IAnswerable

Get More Out of Your Shell History

09 Apr 2026

You typed that exact docker run command with the eleven flags three weeks ago. It’s in your history. You’re just not searching it right.

Reverse search is the one habit worth building

Press Ctrl-r and start typing. Bash and zsh both search backward through history for a matching command as you type. Press Ctrl-r again to cycle to the next older match. Enter runs it, or hit the right arrow to edit it first.

Most people know this exists and still don’t use it because the default history size is too small for it to be reliably useful. Fix that first.

Raise your history limits

In ~/.zshrc or ~/.bashrc:

HISTSIZE=50000
SAVEHIST=50000
HISTFILE=~/.zsh_history

Default HISTSIZE on most systems is 500-1000, which is nothing — a couple days of normal work. 50,000 lines costs you a few megabytes of disk and gets you years of history.

Stop duplicate commands from crowding out real history

setopt HIST_IGNORE_ALL_DUPS   # zsh
HISTCONTROL=ignoreboth:erasedups   # bash

Without this, ls and cd .. — the commands you run 40 times an hour — push out the actually useful, rare commands you’ll want to Ctrl-r search for later.

Share history across terminal tabs in real time (zsh)

setopt SHARE_HISTORY
setopt INC_APPEND_HISTORY

Without SHARE_HISTORY, each open terminal tab only sees commands from its own session until it closes. With it, a command you ran in one tab is searchable from another tab immediately.

History expansion: reuse the last command’s arguments

mkdir new-project
cd !$

!$ expands to the last argument of the previous command — here, new-project. !! reruns the entire previous command, most commonly seen as:

sudo !!

when you forgot sudo the first time.

Filter history by what you actually ran, not everything

history | grep docker

That searches whatever’s currently in memory for this session — fine most of the time, but it won’t see everything if HISTSIZE was raised recently and the in-memory list hasn’t caught up. Search the file directly for the full picture:

grep 'docker run' ~/.zsh_history

Or, if you use fzf, bind it to Ctrl-r for fuzzy interactive search instead of exact substring match — this is the single biggest upgrade over stock reverse search:

brew install fzf
$(brew --prefix)/opt/fzf/install

Once installed, Ctrl-r opens a fuzzy-searchable, scrollable list of history instead of the terse inline prompt bash gives you by default.

Timestamp your history so you can tell when you ran something

HIST_STAMPS="yyyy-mm-dd"   # zsh (in oh-my-zsh) or:
setopt EXTENDED_HISTORY    # raw zsh
HISTTIMEFORMAT="%F %T "    # bash

Without this, history just shows commands with no dates, and you can’t tell whether that terraform apply was yesterday or four months ago.

Ignore commands you never want recorded

HISTIGNORE="ls:cd:pwd:exit:clear"   # bash
HISTORY_IGNORE="(ls|cd|pwd|exit|clear)"   # zsh

Keeps trivial navigation commands out of your searchable history entirely, rather than just deduping them.

The setting most worth changing today

If you change nothing else, raise HISTSIZE and turn on dedup. A small history file with duplicates crowding it out is why Ctrl-r feels useless — it’s not that the feature doesn’t work, it’s that there’s nothing worth finding in there yet.