Enabling Autocomplete by reverse searching history in Linux

Mar 13th, 2010 | By | Category: Linux / Freebsd

Being a FreeBSD user I just got used to a very nice feature that would allow me to autocomplete commands based on my history.  So for example if 15 commands ago I had typed ‘cat filenames1 > filename2’ and I wanted to retype that command I could just type ‘cat’ and then press up and it would go through my history and bring up the last command I typed starting with ‘cat’ until I got back to the desired command, only bringing up those in my history starting with ‘cat’ of course.

Unfortunately this isn’t the way it works in linux, in linux pressing up, no matter how much you’ve typed so far will just take you back through the command history.  Sure you can press ctrl-r but I couldn’t be bothered to figure that out.  Besides there is a much cooler way to go about it.

what you  do is to edit /etc/inputrc:
vi gedit /etc/inputrc

somewhere around line 40 is the following:

# alternate mappings for “page up” and “page down” to search the history
#”\e[5~”: history-search-backward
#”\e[6~”: history-search-forward
Uncomment those lines, close term and open an new one and viola!  It works the same but with page up and down instead.  Beauty!  If you didn’t know about this at all go in there and turn it on right now because man this is a time saver and a half.  You’ll thank me later!

Tags: , , , , , ,

4 Comments to “Enabling Autocomplete by reverse searching history in Linux”

  1. Andrew says:

    Thanks a bunch, I had this on another build of fedora but somehow it was not on another one … thanks again!

  2. IpsumJ says:

    in some system it is in the ~/.bashrc

  3. Berikato says:

    Tnxs dude I used to work with this in FreeBSD but i didn’t noticed it also could be done in linux in such a similar way. just awesome 🙂

  4. admin says:

    I know, I was in the exact same boat. You really never appreciate something fully like that until it’s gone and then it feels like you’ve lost the function of a finger or something. Just imagine how I feel now that I’ve gone from Debian into Windows.. Ugh, it’s like I both my arms tied behind my back 🙂

Leave a Comment