Clear Terminal History in Linux

Linux Clear History; How do I clear terminal history (clear bash history) in Linux? How can I remove command line history or delete typed commands from the terminal? Is it possible to search and view terminal history?

Those 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 use Linux to clear 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 bash 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 the following command and then press Enter.
    history

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 steps 2 and 3.

Steps to Clear Terminal History in Linux

Clearing terminal or bash history in Linux is also easy. Simply perform the following steps, repeating for each user you want Linux to clear history for:

  1. login with the user account whose terminal history you plan to clear.
  2. Open a terminal window Ctrl + Alt + T
  3. Type the following command and then press Enter.
    history -cw
  4. Repeat the process if necessary for each user account.

Clear Bash History - Clear Terminal History Linux

Now you also know how to delete typed commands and clear bash history for any user. Again, remember to repeat this process for each user to wipe or clear history for all users.

Alternate method to Clear Bash History

This method might work better to clear bash history, if you you find that command history seems to return each time after logging back in.

  1. Open a terminal window Ctrl + Alt + T
  2. Next, type the following code and then press Enter.
    cat /dev/null > .bash_history && history -cw
  3. Repeat for each user account.

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