The commands you type into your Linux terminal are always logged somewhere. You may have noticed that you can press the up arrow on your keyboard to retrieve commands you’ve executed in the past. This is a convenient feature when you need to recall a past command, but can also be a potential privacy concern.
In this tutorial, you will learn how to view the terminal history in Linux, and how to clear the terminal history and past commands.
View and Clear Terminal Hisory
Example 1. To view all of your past commands simply type:
Example 2. To clear the current terminal history, use the
$ history -c
Now the cache has been cleared, and running the
history command won’t show any recently run commands.
Example 3. The commands you use are also stored in the
bash_history file. You can view the file with this command:
$ cat ~/.bash_history
This file contains a bigger cache than what the
history command displays.
Example 4. To fully delete the terminal history from
bash_history, execute the next command:
$ cat /dev/null > ~/.bash_history
Example 5. To make sure you clear all of your terminal history, it’s recommended that you run both commands. We’ll also append the
exit command since this is common to run right before signing out of a terminal session such as SSH:
$ cat /dev/null > ~/.bash_history && history -c && exit