bwajda
bwajda

Reputation: 1

How to filter out writing certain commands in bash history file?

I would like to ignore some commands in bash history, for example exit, history...

I try HISTIGNORE="history:history :exit:exit " and it's not filtering out the commands.

How to make sure that the $HOME/.bash_history doesn't contains some specific bash commands?

Upvotes: 0

Views: 264

Answers (1)

storsan
storsan

Reputation: 100

If you want exact matches for the commands to be ignored:

$export HISTIGNORE="history:exit"

Put the above shell variable export in your .bashrc file so that the next time you login to bash the earlier HISTIGNORE setting continues to be effective.

If you don't want any lines beginning with the history command, like history -a then put this into your .bashrc file:

$export HISTIGNORE="history*:exit"

If you don't want any commands to be saved into the history, put:

$export HISTIGNORE="*"

Check your HISTIGNORE setting:

$echo "$HISTIGNORE"

From man bash:

Each colon-separated list of patterns is anchored at the beginning of the line and must match the complete line. (no implicit '*' is appended). Each pattern is tested against the line after the checks specified by HISTCONTROL are applied.

Upvotes: 0

Related Questions