Posted in Bash Linux

Bash tips and tricks

November 26, 2007 - 2 comments

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

Philip Paeps

November 26, 2007 - 16:04

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!

Sébastien Wains

November 26, 2007 - 23:35

Hey Philip, thanks for the tip.. gonna check that out !

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.

Before submitting, some rules :
- Is your comment related to the article ?
- You're having a problem ? Have you checked Google, other howtos, docs, manpages ?
- You're still having the problem ? Have you raised log verbosity, checked traces, ran tcpdump ?
- Have you checked your configuratoin for typo ?
Unless your comment is providing additional info or respect the rules above, DON'T comment.
If you don't understand what you are doing, I urge you to read the documentation, I'm not your free Level 1 helpdesk guy.