Skip to main content
2 of 5
edited title
Martin Vegter
  • 848
  • 81
  • 257
  • 449

bash_history: comment out dangerous commands: `#`

To prevent logging dangerous commands in bash history, I have added following line to my .bashrc file:

HISTIGNORE='rm *:mv *:cp *:cat*>*:pv*>*' 

this works well, but it has a side effect: I cannot see the complete history of commands executed on a machine. Let's say I have several machines for experiments, and I want to be able to see all commands executed. I would use the bash internal history to display executed commands, and perhaps grep for today's date:

history | grep Sep-28 

What I would like do have is to log dangerous commands as well, but put a # at the beginning of the line, so that if I happen to execute the command from history by mistake, no damage would be done.

I have no idea if this is possible. Any comment would be greatly appreciated.

Martin Vegter
  • 848
  • 81
  • 257
  • 449