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
OptionDescription
-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
OptionDescription
-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
OptionDescription
-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
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
The Ultimate Bash Array Tutorial with 15 Examples
Viewed 13594 times since Sun, Sep 30, 2018
Dealing with Funny Files
Viewed 2884 times since Wed, May 30, 2018
How to get a password from a shell script without echoing - solutions
Viewed 14048 times since Fri, Feb 22, 2019
Linux: Repeat Command N Times – Bash FOR Loop
Viewed 3171 times since Mon, Feb 18, 2019
O’Reilly’s CD bookshelf
Viewed 13152 times since Wed, Jun 27, 2018
30 Handy Bash Shell Aliases For Linux / Unix / MacOS
Viewed 5024 times since Thu, Feb 11, 2021
10 Awk Tips, Tricks and Pitfalls
Viewed 6097 times since Wed, Aug 19, 2020
Transform XML to CSV Format | Unix String Pattern Manipulation The Ugly Way
Viewed 5921 times since Sun, Jan 9, 2022
awk printf
Viewed 15519 times since Wed, Aug 19, 2020
How to sort IP addresses in Linux
Viewed 4077 times since Thu, May 24, 2018