How to Clear Terminal History

How do I clear terminal history? Can I remove command line history or delete typed commands from the terminal? Is it possible to search and view terminal history? These are just a few questions new Linux users commonly ask.

In Linux, by default, up to the last 500 command lines a user types in the terminal window are saved into a hidden .bash_history file. The previously typed commands can be readily accessed or searched and viewed by using the up and down arrow keys on your keyboard. This makes it really easy to retrieve and reuse your recently used commands.

However, maybe you want to delete or clear that terminal command history and start fresh? The following segment explains the process of viewing and then optionally deleting, clearing, or removing the terminal history; also known as bash command history.

How to View Terminal History

To view the complete history of commands that have been typed into the terminal “for the logged in user”,

  1. First, login to the user account whose history you want to view.
  2. Then, press Ctrl + Alt + T to open a terminal window.
  3. Next, from the terminal, type history and then press Enter.

There you have it, the steps to view terminal command line history. To view typed commands for a Linux root user, just change to root. I.E. sudo su, and then repeat the steps above.

Steps to Clear Terminal History

Clearing bash history is also easy. Simply perform the following steps, repeating for each user you want to clear command history for.

  1. First, login with the user account whose terminal history you plan to clear.
  2. Then, open a terminal window Ctrl + Alt + T
  3. Next, type history -c and then press Enter.
  4. Repeat the process if necessary for each user account.

Clear Terminal History

Now you also know how to delete typed commands and clear terminal history.

If you found this segment useful, you might also want to learn how to mount an NTFS partition in Linux.