Introduction: Why Clearing Your Terminal History Matters on macOS
If you spend any meaningful amount of time in the macOS Terminal, your command history quietly grows in the background — storing every command you’ve typed, including sensitive ones. Database passwords, API keys passed as arguments, SSH connection strings, sudo commands — all of it sits there in plain text, waiting to be scrolled through by anyone who has access to your machine or your shell history file.
Whether you’re a developer, sysadmin, or just a power user who values privacy, knowing how to clear your Terminal history on macOS is a fundamental skill. It’s also a point of confusion for many users switching from Linux, where the go-to command is history -c. On macOS, things work a little differently depending on which shell you’re using, and that difference trips people up constantly.
This guide covers everything you need to know: how Terminal history works on macOS, the correct commands to clear it, the differences between Bash and Zsh (the default shell since macOS Catalina), and some best practices for keeping your history clean going forward.
How macOS Terminal History Works
Before diving into how to clear your history, it helps to understand where that history actually lives. macOS Terminal history is managed by your shell, not by the Terminal app itself. The two shells you’ll most commonly encounter are:
- Zsh (Z Shell) — the default since macOS Catalina (10.15). History is saved to
~/.zsh_history - Bash — the previous default, still available. History is saved to
~/.bash_history
Every time you open a Terminal session, your shell loads the history from that file. Every time you close a session (or when certain conditions are met), it writes new commands back to that file. This means that clearing history is a two-step problem: you need to clear it from the active session in memory and from the persistent history file on disk.
The Linux vs macOS Difference: history -c vs history -p
If you’re coming from an Ubuntu or Linux background, your first instinct will be to run history -c to clear your command history. That works perfectly in Bash on Linux. But on macOS — especially in Zsh — the behavior is different.

In macOS’s default Zsh shell, history -c is not a valid option in the same way. Instead, the Zsh equivalent for purging the in-memory history is history -p. As you can see in the screenshot above, this is the command you’d reach for when working in a Zsh session on macOS.
Here’s a quick comparison to make this clear:
- Linux / Bash:
history -c— clears the in-memory history list - macOS / Zsh:
history -p— purges the internal history list for the current session - macOS / Bash:
history -c— also works if you’re running Bash on macOS
This distinction matters because many tutorials written for Linux don’t translate directly to macOS’s default Zsh environment, and running the wrong command either produces an error or silently does nothing useful.
How to Clear Terminal History on macOS: Step by Step
Step 1: Check Which Shell You’re Using
Before running any commands, confirm which shell is active in your Terminal session. Run this:
echo $SHELL
If you see /bin/zsh, you’re in Zsh. If you see /bin/bash, you’re in Bash. This determines exactly which commands and file paths apply to you.
Step 2: Clear In-Session History (Zsh)
If you’re using Zsh (the macOS default), run the following to purge the current session’s in-memory history:
history -p
This removes the history from the active session so it can no longer be recalled with the up arrow key or the history command. However, it does not automatically clear the history file on disk.
Step 3: Clear In-Session History (Bash on macOS)
If you’re running Bash on macOS, use the familiar Linux-style command:
history -c
Again, this clears the in-memory history for the current session only.
Step 4: Delete the History File on Disk
To make sure your history is gone permanently — including entries from previous sessions — you need to wipe the history file itself. Choose the appropriate command for your shell:
For Zsh:
rm -f ~/.zsh_history
For Bash:
rm -f ~/.bash_history
Removing the file ensures that no previous commands are reloaded the next time you start a Terminal session. If you prefer to truncate rather than delete the file entirely, you can also use:
> ~/.zsh_history
This overwrites the file with nothing, leaving an empty file in place rather than removing it.
Step 5: Prevent the Current Session from Writing History
After clearing the in-memory history, you may want to prevent any new commands in the current session from being written to disk when the session closes. In Zsh, you can do this by unsetting the relevant environment variables:
unset HISTFILE
This tells Zsh not to save the session history to any file when the Terminal window is closed. Once you open a new session, normal history saving resumes.
Clearing Terminal History via the macOS Terminal Menu
If you’re not comfortable working purely in the command line for this task, macOS’s Terminal app also offers a graphical option. Here’s how to use it:
- Open Terminal
- In the menu bar, click Shell
- Select Import… or look for history-related options depending on your macOS version
However, it’s worth noting that the Terminal app’s menu doesn’t offer a dedicated “Clear History” option in most versions of macOS. The most reliable approach remains using the shell commands described above. The Terminal menu’s Edit → Clear Scrollback option only clears the visible buffer on screen — it does not clear your command history.
Using the fc Command as an Alternative
Zsh inherits a powerful built-in called fc (Fix Command) that gives you additional control over your history. While it’s primarily used to edit and re-run previous commands, you can combine it with other techniques for history management.
To list your current history in a numbered format, you can run:
fc -l
And to delete a specific history entry by number (useful if you only need to remove one sensitive command rather than wiping everything):
fc -d [number]
This is particularly useful when you’ve accidentally typed a password in plain text as a command and want to surgically remove just that entry rather than nuking your entire history.
Automating History Clearing: Shell Configuration Options
Disable History Entirely in Zsh
If you’d rather not accumulate history at all, you can configure your shell to never save it. Open your Zsh configuration file:
nano ~/.zshrc
Then add the following lines:
unset HISTFILESAVEHIST=0HISTSIZE=0
Save the file and restart your Terminal. From this point on, no history will be written to disk. Keep in mind this is an all-or-nothing approach — you lose the convenience of recalling previous commands entirely.
Set a Smaller History Size
A more balanced approach is to limit how many commands are stored. In your ~/.zshrc, set:
HISTSIZE=50SAVEHIST=50
This keeps a rolling window of only the last 50 commands, which reduces exposure without completely sacrificing the convenience of history recall.
Exclude Sensitive Commands from History
Zsh supports a feature that lets you prevent specific patterns from being saved. Add this to your ~/.zshrc:
setopt HIST_IGNORE_SPACE
With this option enabled, any command you type with a leading space will not be saved to history. This is a great habit to develop: whenever you’re about to type a command with a sensitive argument (like a password or token), prefix it with a space.
Privacy-conscious macOS users might also be interested in reading about whether Apple Intelligence can run fully local on-device in macOS Tahoe — because keeping sensitive data off external servers applies to AI features just as much as it does to your Terminal history.
Verifying That Your History Has Been Cleared
After running your chosen clearing commands, it’s good practice to verify the result. Simply run:
history
If the history was successfully cleared from the current session, this command should return nothing (or a very short list if new commands were run after clearing). To verify the history file on disk is empty or gone:
cat ~/.zsh_history
If the file no longer exists or is empty, you’re done. If it still contains entries, the session may have written history to disk before you deleted the file, or a new session has already started rebuilding it. In that case, repeat the deletion step.
Privacy and Security Considerations
Understanding why you might need to clear your Terminal history goes hand-in-hand with good security hygiene. Here are some common scenarios where this matters:
- Shared machines: If multiple people use the same macOS account (in an office or lab setting), your commands are visible to anyone who opens Terminal.
- Sensitive credentials: Developers sometimes accidentally paste API keys, passwords, or tokens directly into the Terminal. Clearing history removes that exposure.
- Handoff before selling or returning a device: Before wiping or handing off a Mac, clearing shell history is part of a thorough cleanup alongside erasing personal files.
- Screen sharing or recordings: If you’re recording a tutorial or sharing your screen, a quick
history -pbefore starting keeps your previous commands out of the recording.
For users who are serious about keeping their command-line activities private — especially when connecting through VPNs or working with sensitive server infrastructure — combining history hygiene with a solid VPN solution adds another layer of protection. If you’re exploring privacy tools across platforms, the Proton suite on Linux offers a comprehensive look at privacy-first tools that complement this kind of mindset.
Quick Reference: macOS Terminal Clear History Commands
Here’s a concise reference you can bookmark for quick access:
- Clear in-session history (Zsh / macOS default):
history -p - Clear in-session history (Bash on macOS):
history -c - Delete Zsh history file:
rm -f ~/.zsh_history - Delete Bash history file:
rm -f ~/.bash_history - Prevent current session from saving history:
unset HISTFILE - Truncate (empty) Zsh history file without deleting:
> ~/.zsh_history - Remove a single history entry by number (Zsh):
fc -d [number] - Check which shell you’re using:
echo $SHELL
Conclusion
Clearing your Terminal history on macOS is straightforward once you understand the key difference from Linux: on macOS with Zsh, you use history -p rather than history -c. That small but important distinction causes a lot of confusion for developers and sysadmins migrating from Linux environments or following Linux-focused tutorials.
Beyond the single command, truly clearing your history means addressing both the in-memory session list and the persistent history file on disk. A complete cleanup involves running history -p, deleting or truncating ~/.zsh_history, and optionally unsetting HISTFILE for the remainder of your session. For ongoing privacy, configuring your shell to ignore space-prefixed commands or limiting history size are practical habits worth building.
Whether you’re locking down a development machine, cleaning up before a screen share, or just practicing good security hygiene, managing your Terminal history is a small effort with meaningful privacy payoffs. Now that you know exactly how it works on macOS, it’s one less thing that should catch you off guard.
