LINUXMAKER, OpenSource, Tutorials

So the BASH history can be deleted

Sometimes it is necessary for different aspects to delete the history of the bash history or to remove parts of it. For example, this can be very useful if you have inadvertently typed sensitive data such as passwords into the bash.
Surely you could edit the ".bash_historie", but it is also more efficient without leaving a trace.

Delete the BASH history completely

The entire content of the history can be removed with the following command:

$ history -cw

Attribute Function
-c

This attribute deletes the history list

-w

This attribute writes the current history into the history

Remove a single line from the history of the BASH history

The attribute reads the current history file and appends its content to the history list

$ history -d 420

Attribute Function
-d

The attribute, together with the line number, triggers the relevant line from the bash history

Remove only the current session history

If only the current session disappears from the history, then with this command happens.

$ history -r

Attribute Function
-r

The attribute reads the current history file and appends its content to the history list

Avoid storing the command in the BASH history

It is also possible to avoid storing a command in the history by inserting a space before the command.

$ <space> command

Avoid storing commands in the bash history in the current bash session

Unless HISTFILE is disabled, all commands in the current bash session until logout are not written to the logged-in user's .bash _history. To do this, the following command must be issued at the beginning of the bash session:

$ unset HISTFILE