How to clear all entered commands in Terminal?
Solution 1
This should work (at least for bash):
$ history -c
Followed by quitting the terminal.
EDIT: Chris Page notes in the comments that quitting the terminal is unnecessary, as there is also a command to clear scrollback in most terminals. On Mac, e.g., this is under View > Clear Scrollback
or ⌘K
Solution 2
For Mac Terminal user
delete commands history with the following command
$ echo '' > ~/.bash_history
For Mac zsh user
delete zsh command history with the following command
$ echo '' > ~/.zsh_history
Solution 3
You can clear all your history on Mac from the edit menu of the terminal, edit > clear scrollback or just enter 'alt + command + k'.
Related videos on Youtube
Comments
-
Billjk over 1 year
How does one clear all the entered commands in terminal? I am not talking about the
clear
command, which merely clears the screen. I want to clear all the commands that I have entered , so the window would completely clean. I've tried:1. Quitting Terminal 2. Restarting my computer 3. The clear command
I am thinking there must be some way, because I've probably entered in about 50 million commands, and there are only 505 in my history.
-
deed02392 about 12 yearsThe command history is stored in a file, that's why it is persisting. I'm sorry I don't know where that file is in macs but on *nix systems it is usually in
~/
as a dot-file, named depending on what shell you're using. -
lupincho about 12 yearsIn bash, $HISTFILESIZE determines how many commands are kept, typically 500, with older ones being replaced by newer ones. That's why you don't see all commands you've entered. Cameron already said how to clean the history.
-
Cameron about 12 years@deed02392, the name is similar on mac, e.g. for bash, it is ~/.bash_history
-
-
Chris Page about 12 yearsQuitting Terminal or closing the terminal window/tab should be completely unnecessary to clear the shell command history.
-
Cameron about 12 yearsThe part about quitting the terminal was because the poster wanted to know how to make the window "completely clean". Just clearing the history will only make the history go away, but you can still see what was executed during that login just by scrolling up in most terminal emulators. AFAIK, the only way to get rid of that information is to quit the terminal.
-
Chris Page about 12 yearsView > Clear Scrollback erases the scrollback text.