I am looking for a way to make it so that my ubuntu bash shell has the same kind of history completion as you get with csh in FreeBSD.

The behavior is that on the command line if i start to type something, and hit the up/down arrow, the history is searched for commands that started with what I have started typing

for example, if history contained

 1  ls -al
 2  yes
 3  ls -altr
 4  ls
 5  history

and i type ls and hit the up/down arrow, it would cycle through ls ls -al and ls -altr

How can i implement the same behaviour in ubuntu bash?

  • You could use csh on ubuntu :)
    – rici
    Sep 18, 2013 at 16:02

1 Answer 1


You should be able to do this by rebinding the arrow keys in your bash profile. By default the up- and down- arrows are bound to previous-history and next-history; I believe the behaviour you seek is history-search-backward and history-search-forward, which be default are not bound to any key.

The following commands will do the rebinding:

bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'

(assuming your terminal emulator does (one of) the standard mappings of arrow keys.)

previous-history and next-history are, by default, also bound to ctrl+P and ctrl+N but in my quick experiment there seemed to be a slight interoperability issue between next-history and history-search-backward It might just be an issue with the version of readline I have installed.

bash also offers reverse incremental history search (ctrl+R; ctrl+S is forward incremental search), which is somewhat equivalent, but doesn't anchor the history search at the beginning of the line. (Also, you have to remember to type it first.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.