I'm trying to clear the history of commands that have been run on Terminal, I found an article which said I can do it with rm ~/.bash_history

However, I am still able to see the previous commands that I've ran by pressing the up arrow

8 Answers 8


The correct command is history -c, as shown in the picture below.

history -c

  • 3
    In case anyone is here in 2020+ and is having a brain fart, it's ~/.zsh_history now!
    – Max
    Commented Jun 5, 2020 at 15:14
  • As @jksoegaard says, You'll need to close the terminal and open it again - after hitting the command. Commented Nov 19, 2020 at 6:21

If you are running zsh, you'll need to use this command to clear the Terminal history:

rm ~/.zsh_history

Alternatively, you can open your user folder in Finder, press Command + Shift + . to show all files, and manually drag the hidden .zsh_history file to the trash.

You might also want to check and clear the .zsh_sessions folder too, as it also might contain the history of previous Terminal sessions.


The command that has worked for me in zsh is

history -p

p = purge

  • 1
    It‘s more a matter of the shell used than the OS version, so in which shell are you running this?
    – nohillside
    Commented Mar 9, 2023 at 10:55
  • Yes, you are right, I should have mentioned that it is zsh the default shell.
    – anyway
    Commented Mar 9, 2023 at 14:12
  • mac os uses zsh by default since catalina support.apple.com/en-us/102360
    – bristweb
    Commented Feb 19 at 18:18

An easy way to accomplish this is to close all terminal windows, and then open a single new terminal window, where you run:

rm ~/.bash_history

You'll need to close the terminal and open it again. Now when you press arrow up, you'll only see the rm command, and not earlier commands.

  • 1
    I have used this method without problems. You just need to be aware that your current session's history will be saved when you close it. So close all sessions, and create a new one that will have no history to speak off - then clear the file. You can use history -c to the same effect ofcourse, but again if you have open sessions and close them afterwards, then their previous commands would be saved to history as well.
    – jksoegaard
    Commented Apr 30, 2017 at 21:22

You have to write following in terminal step wise: -

  1. cat > .zsh_history
  2. clear
  3. press return ⏎
  4. press Ctrl ^ + D

Then close terminal using Cmd ⌘ + Q and then reopen again.

  • What does this do, especially step 3 and 4?
    – nohillside
    Commented Oct 29, 2021 at 5:17
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Oct 29, 2021 at 13:26

So what you have to do is:

  • run "rm ~/.bash_history" (without quotation marks)
  • run "exit" command
  • quit Terminal and open it again You can check that your history is cleared by running "history" command. All that should be left is the "exit" command and "rm ~/.bash_history" command.

Hope this helps!

  • 3
    Welcome to Ask Different. This isn't much different than the answers already provided. It would be better if you edit one of the other answers, to add the 'exit' command, instead of creating a new answer with mostly recycled info. - From Review
    – fsb
    Commented Jan 16, 2019 at 21:04
  • Your chance to improve the answer for newer macOS versions, e.g.using zsh or even shell-independent with environment-variable $HISTFILE.
    – hc_dev
    Commented Dec 24, 2022 at 20:02

I found this on Udemy's Linux Mastery course.

history -r; history -w

history -r removes the terminal history temporarily for the current session. history -w removes it permanently.


None of these worked. History is deleted, yet every time I re-opened terminal, I still had access to my command history. It's a security risk, and the only indication you get is in case you cleanly exit a session: "Saving session... ...copying shared history... …saving history...truncating history files... ...completed."

The full answer is this: https://www.swiftforensics.com/2018/05/bash-sessions-in-macos.html

The history still gets saved to ~/.bash_history and recalled every time.

  • This basically is a link-only answer which will become useless once the link breaks (it also makes the answer not show up in search). Can you please include the relevant parts directly in your post, and leave the link for reference?
    – nohillside
    Commented Apr 20, 2023 at 19:55
  • 1
    There are several things here that caught my attention: 1) macOS uses Zsh, not Bash, as the default now. 2) The messages you’re seeing are not common, so we’ll need additional info about your environment. 3) This is more of a comment and 4) This seems to only promote the link you supplied.
    – Allan
    Commented Apr 20, 2023 at 19:55
  • @allan Ah right, the linked page doesn‘t actually explain how to delete the history.
    – nohillside
    Commented Apr 20, 2023 at 20:22

You must log in to answer this question.