Categories
Linux

Linux: removing commands from history

If you want to remove some commands from your bash history use the following command:

history -d 1001

where 1001 is the number of the history line. Of course this might add another problem: the command ‘history -d 1001’ is now added to your history.

How to avoid a command getting in your bash history?

If you want to execute a command and don’t want it to get in your history list (because it contains sensitive data, or you just don’t want to clutter your history), start the command with a space.

For this to work the environment variable $HISTCONTROL has to be set to ‘ignorespace’ or ‘ignoreboth’.

export HISTCONTROL=ignorespace