Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On a FreeBSD machine that I've used, the up arrow key brings up the previous command BASED on the letters already typed. However on a CentOS machine that I'm using, the up arrow key simply bring up the immediate previous command.

Anyone knows if there is anyway to set it like FreeBSD's up arrow key for CentOS?

Thanks a lot.

share|improve this question

migrated from Sep 1 '09 at 22:30

This question came from our site for professional and enthusiast programmers.

What shell are you using? – Rob Jones Sep 1 '09 at 21:21
Needs to be moved to superuser. – Vineet Reynolds Sep 1 '09 at 21:37

The behavior you're describing is based on your shell.

The default shell in CentOS is bash: you can confirm this by typing the following:

$ echo $SHELL

If it is, then you can get similar functionality to your FreeBSD shell (most likely ksh) by hitting CTRL-r. You'll see something like this:


Simply start typing and you'll get the commands you've previously run based on what you've typed.

For example, in this terminal, when I type CTRL-r s I get this:

(reverse-i-search)`s': sudo port install ruby

You can then scroll up or down with the arrow key to go through all the commands that match your search criteria (in this case, 's').

share|improve this answer
Thanks! Hehe, I actually know about Ctrl+r. But, it searches for pattern right? So, if I type p, all the previous commands that CONTAINS "p" will show. What I really want is the command that STARTS with "p" (like the behavior in csh). The latter proves to be faster for me at least. – Dave Sep 1 '09 at 21:42
Honestly, I just use Bash Completion to cheat around that :). – mando Sep 1 '09 at 21:51

The default shell under FreeBSD is CSH. There should be a package for it in CentOS (consult your package-manager for this).

HOWTO: Download and Install csh / tcsh shell on Linux

share|improve this answer
Thanks! So, I guess I'll install csh. – Dave Sep 1 '09 at 21:43
If you're interested in getting the exact behaviour of the FreeBSD CSH, you also want to read this: – flokra Sep 1 '09 at 21:48

This is defined by your shell. You can determine which shell you are using by typing: echo $0

In FreeBSD, you are typically running csh (which was invented at Berkeley, the home of BSD). In Linux, you typically run bash. You can get the 'up-arrow' behavior by switching to the emacs history editing mode. Try typing: set -o emacs in your terminal.

If you like this behavior, you can edit your $HOME/.bashrc file, and add that line, and you will have in every shell

share|improve this answer

You could also configure a private ~/.inputrc file for your bash like this:

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

Now the page-up key searches backward and page-down forward in the history. This is what I use. (You need to restart the shell for it to take effect.)

Press CTRL+V followed by KEY to determine the key sequence if you want to bind the shell commands to another KEY (instead of page-up/page-down).

share|improve this answer
  1. Install tcsh as @flokra mentioned.
  2. Place a .cshrc file in your home directory. Inside of that file configure tcsh to show a list of matches to the partially typed command when you press the up or down arrow. Use as a guide, but what you are looking for is:

    bindkey -k up history-search-backward
    bindkey -k down history-search-forward
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .