Home > Linux > Making the bash (history) a better place

Making the bash (history) a better place

One thing that I always miss in the default installation of current distributions is the proper handling of the bash history.

Missing history data

Everyone who works with more than one session on the same machine will know this. You come back the next day and want to rerun a command from the day before, maybe it was quite tricky or you’re just too lazy to write it again. You search the history but can’t find it. Thats because one session overwrites all other concurrent ones when it ends.

The easy fix for that is to add the following to your ‘/etc/bash.bashrc’ (or equal) file. You might want to add it only to your own users ‘~/.bashrc’ file.

shopt -s histappend

Duplicate history data

Another annoyance is that you might use a command over and over again, but then you want to go back to the command you used right before. But cursor-key up brings you only the repeated command again and again. To stop the history of saving duplicate entries you just need to add this line to the '.bashrc' file:

export HISTCONTROL=ignoreboth

Larger size of history

One more thing you might want to do is to up the limit of the lines that the history saves. The default is 500, which, to be honest, isn't that big! Sometimes you just need that command you remembered you ran a month ago, but its gone now. So, increase the history size!

export HISTSIZE=10000

Auto-completion history

This one is the most important one to me. There are commands that you use every day, and you don't wanna type them in day after day after day. So you just need to search the history. You can do that with CTRL-r, but thats not as quick and not as easy as the method I'm used to use. Start entering your command and press page-up or page-down to scroll through all commands that started like what you entered right before. To activate this functionality you need to add (or uncomment, debian and ubuntu already have that in the file) these two lines to your '/etc/inputrc' file, or of course to your users '.inputrc' file:

"\e[5~": history-search-backward
"\e[6~": history-search-forward

Once you are used to this stuff you never want to miss it again!

As a note, Linux Commando is a good source for more things that make your command line experience easier!

About these ads
Categories: Linux Tags:
  1. 13.04.2008 at 7:41 pm

    I have no problem with these kinds of changes. and I reckon that we should do it. I primarily use Zsh for my own personal stuff, and it works awesome with it’s completion , which far surpasses bash, as zsh will even complete to machines where you have ssh keys setup.

    I digress, if that’s what you’d like to have then let me know and I’ll add it to the /etc/bashrc.

  2. 13.04.2008 at 8:05 pm

    I will give that Zsh a look.

    Would be cool if we change it, everyone has his own preferences, but if you’re cool with these changes we make em! :-)

  3. 14.04.2008 at 2:33 pm

    I’ll post a correct link, as this is the main page now. http://zsh.sourceforge.net/

  4. Wulf
    07.12.2008 at 12:22 pm

    Check out he following webpage:

    http://www.onerussian.com/Linux/bash_history.phtml

    or just download this:

    http://www.onerussian.com/Linux/.files/.bashrc_history

    …this works great for me and I love the timstamps.

  1. 29.10.2009 at 1:19 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: