Guide

How to view and search Mac command history

The Mac terminal remembers what you type, but finding that one complex curl command or ssh flag from last week can be incredibly frustrating. Here is how to use the built-in native command history, its limitations, and how power users never lose a command again.

⚡ Recommended Mac App

Looking for a native Mac app to search & organize terminal commands across all tabs?

L2Cache automatically captures terminal commands, code snippets, and AI prompts with instant offline FTS5 search, zero cloud tracking, and Touch ID encryption.

Get L2Cache for Mac ↗

Updated September 2026 · By the team behind L2Cache

If you spend any time in the macOS Terminal (or iTerm2/Warp), you know the feeling: you finally get a Docker build command or an ffmpeg script working perfectly with 10 different flags. A week later, you need to run it again, but you can't remember the flags.

macOS has built-in ways to recall these commands, but they have their quirks. Let's look at the standard ways to find your Mac terminal history, and then how to fix the workflow permanently.

1. Use the `history` command

The simplest way to see what you've typed recently is the native history tool.

  1. Open your Terminal app.
  2. Type history and press Return.

You will see a numbered list of your most recently executed commands. If you want to re-run a specific command, you can type an exclamation mark followed by the number (e.g., !142) and press Return.

To search the list directly, you can pipe it into grep: history | grep docker

Mac Terminal History Grep

2. Reverse Search (Ctrl+R)

Scrolling through a list is tedious. If you know a piece of the command, Reverse Search is much faster.

  1. In your terminal window, press Ctrl + R.
  2. Your prompt will change to (reverse-i-search)`':
  3. Start typing part of the command you remember.
  4. The terminal will autocomplete the most recent match. Press Ctrl + R again to cycle backwards to older matches.
  5. Press Return to execute it, or the right arrow key to edit it before running.
Mac Terminal Reverse Search

Where the built-in terminal history stops

While `Ctrl+R` is a lifesaver, the native `.zsh_history` file (where macOS stores these commands by default) has several major flaws for modern developers:

The gap

The built-in Mac terminal history is just a text file of raw commands. What developers really need is a way to capture, organize, and instantly retrieve complex CLI snippets without relying on brittle dotfiles.

3. Use a smart snippet and clipboard manager

Power users don't rely entirely on terminal history. Instead, when they write a command they know they'll need again, they save it to a snippet manager or rely on an intelligent clipboard history tool. This is where L2Cache comes in.

Never lose a terminal command

If you copy a command from StackOverflow or a coworker on Slack, L2Cache automatically saves it. If you build a complex script in your IDE, copying it means it's saved forever. You don't have to execute a command to keep it in your history.

Mac Terminal History in L2Cache

Directory-aware search & instant replay

L2Cache associates your terminal snippets and commands with their working directory. You can search and replay commands from the exact same directory or repository without having to manually retype flags or switch contexts.

AI-powered intelligence

L2Cache uses on-device Apple Intelligence to understand your snippets. It can automatically group your Terminal, Git, and Docker commands into smart albums. Instead of searching for an exact flag, you can search "that command to clear dns cache" and L2Cache finds it instantly.

Private by design

Terminal commands often contain AWS secrets, passwords, and API keys. L2Cache keeps your history strictly on your Mac. Sensitive copied items are detected automatically and locked behind Touch ID, ensuring your secrets don't sit in plain text.

The ultimate developer memory

L2Cache keeps an unlimited, searchable history of your commands, code, and snippets. Free while in early access — join now and keep it free for good.

Download L2Cache for Mac

macOS 13 Ventura or later · No credit card

Frequently asked questions

How do I see my command history on a Mac?

Open the Terminal and type the command history. This will print a numbered list of the most recent commands you have executed.

Where is the terminal history file located on Mac?

If you are using Zsh (the default since macOS Catalina), the history file is located at ~/.zsh_history. For Bash users, it is located at ~/.bash_history.

How do I search my previous commands in Mac terminal?

Press Ctrl + R inside your terminal to open the reverse-i-search prompt. Start typing part of the command, and it will find the most recent match. Press Ctrl + R again to cycle through older matches.

How does L2Cache compare to terminal history tools like Atuin or McFly?

Atuin and McFly are CLI-only shell daemons that hook into ~/.zshrc to log commands executed in that specific shell session. L2Cache is a native macOS menu bar app that captures developer snippets, terminal commands, Claude Code & Codex AI prompt sessions, and secrets across all apps and IDEs with biometric Touch ID encryption and sub-millisecond SQLite FTS5 search.

🤖 AI Coding Agent Session Viewer: Inspect and search past Claude Code & Codex CLI sessions with our Free In-Browser Claude Session Viewer Tool.
📊 Analytics Deep Dive: Read our guide on tracking Claude Code & Codex AI agent sessions with token analytics.