Posted in Bash Linux
Bash tips and tricks
Richard posted some nice tips about bash history..
I’ll post his tips here in a shorter version
The following snippets of code must be added to your .bashrc file.
You open two terminals, when closing them, history of only one of both is saved ?
This is the fix, that will merge/append histories from both terminals in the history :
shopt -s histappend
PROMPT_COMMAND=’history -a’
Avoiding spelling mistakes (like /ect instead of /etc) :
shopt -s cdspell
Disable duplicate entries in history (this is the default under Ubuntu) :
export HISTCONTROL="ignoredups"
I’m adding a new one, same as above. ignorespace won’t store in history every command started by a space. Nice when you need to type sensitive info at the CLI.
export HISTCONTROL=ignoredups:ignorespace
Remove ls, fg, bg and exit commands from history :
export HISTIGNORE="&:ls:[bf]g:exit"
Multiple line commands split up in history :
shopt -s cmdhist
Comments
Leave Comment
Please consider visiting the partners below if you enjoyed this article :If this post saved you time and money, please consider checking my Amazon wishlist.







Philip Paeps
And the best bash tip of all? Replace it with tcsh. I’ve been told good things about zsh too, but I’ve been using tcsh for about ten years now and it never caused my teeth to hurt in the way bash did. tcsh has been designed to be a nice interactive shell. bash clumsily tries to add interactivity on top of sh.
Trust me, tcsh rules.
Not suitable for scripts (POSIX defines /bin/sh for scriping), but excellent for interactive use!