How to Clear Terminal History on Raspberry Pi 4

, , , ,

For those serious about security on their Raspberry Pi 4 computers, regularly clearing the terminal history or bash history is advisable.

A chronological history of your entered terminal commands is automatically retained, which is great when you need to repeat or lookup a prior command. However, this can also become a security concern. What if someone gains access to your machine, opens a terminal window, and browses through your terminal history? If you are human, no doubt you will have (at some point) accidentally entered a password in a non-password field.

This article will show you how to quickly and easily clear the history of your terminal window.


Clear Terminal History on Raspberry Pi 4

Close all open Terminal windows (this is a must). Then open a new Terminal window and enter the following command.

history -c && history -w

The history -c command will clear the present history cache while the history -w command writes the present terminal window history (which is completely empty after clearing the terminal history cache with history -c) to the ~/.bash_history file on your Raspberry Pi 4. The && operator simply combines these two commands so you truly get a clean history file.

Once the above command has been processed, close the Terminal window by clicking the close button (X) at top right. If you enter the “exit” command to close the Terminal window it will be saved in history. Now reopen the Terminal window and press the up or down arrow keys to reveal that there is no history available.

There are all sorts of other helpful tutorials online covering how to selectively edit your Terminal history, automate the clearing of your Terminal history or even disabling the Terminal history. But I have found this quick and easy clear and write method sufficient for my needs as I hope it is for yours.



I welcome your thoughts, questions or suggestions on my article on how to clear the terminal history on Raspberry Pi 4.

You may support my work by sending me a tip using your Brave browser or by sending me a one time donation using your credit card.

Let me know if you found any errors within my article or if I may further assist you by answering any additional questions you may have.