Bash tips and tricks

categories:

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




Thanks for reading this post!


Did you find an issue in this article?

- click on the following Github link
- log into Github with your account
- click on the line number containing the error
- click on the "..." button
- choose "Reference in new issue"
- add a title and your comment
- click "Submit new issue"

Your feedback is much appreciated! 🤜🏼🤛🏼

You can also drop me a line below!