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
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.
Sign up to join this communityIf 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.
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.
You have to write following in terminal step wise: -
Then close terminal using Cmd ⌘ + Q and then reopen again.
The command that has worked for me in zsh
is
history -p
p = purge
So what you have to do is:
Hope this helps!
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.