HowTo: Clear BASH History

Sometimes you don’t want to leave Bash history, because it may contain some sensitive data like passwords.

This article may help you to control your Bash history file.

Clear Bash history completely

Type the following command to clear all your Bash history:

$ history -cw
Option Description
-c Clear the history list
-w Write out the current history to the history file

Remove a certain line from Bash history

Type the following command to remove a certain line (e.g. 352) from the Bash history file:

$ history -dw 352
Option Description
-d Delete specified line from the history

Clear current session history

Type the following command to clear the Bash history of the current session only:

$ history -r
Option Description
-r Read the current history file and append its contents to the history list

Don’t save command in Bash history

Execute a command without saving it in the Bash history:

$ <space>command

Put a space in front of your command and it won’t be saved in the Bash history.

Don’t save commands in Bash history for current session

Unsetting HISTFILE will cause any commands that you have executed in the current shell session not to be written in your bash_history file upon logout:

$ unset HISTFILE
Recommended Book

If you are new to shell programming, the book provides an excellent introduction, covering everything from the most basic to the most advanced features.

And if you've been writing shell scripts for years, it offers a great way to find out what the new shell offers.

It is full of practical examples of shell commands and tools that will make everyday use of Linux much easier.

3 Replies to “HowTo: Clear BASH History”

  1. Команда history -cw очищает только текущую историю, но при перезапуске терминала просто добавляет в историю ещё одну команду.

  2. Cat / dev / null> ~ / .bash_history && history -c && exit.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.