How to clear all entered commands in Terminal?

12,879

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'.

Share:
12,879

Related videos on Youtube

Billjk
Author by

Billjk

please delete me

Updated on September 18, 2022

Comments

  • Billjk
    Billjk over 1 year

    How does one clear all the entered commands in terminal? I am not talking about the clearcommand, 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
      deed02392 about 12 years
      The 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
      lupincho about 12 years
      In 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
      Cameron about 12 years
      @deed02392, the name is similar on mac, e.g. for bash, it is ~/.bash_history
  • Chris Page
    Chris Page about 12 years
    Quitting Terminal or closing the terminal window/tab should be completely unnecessary to clear the shell command history.
  • Cameron
    Cameron about 12 years
    The 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
    Chris Page about 12 years
    View > Clear Scrollback erases the scrollback text.