Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com 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
1  
Needs to be moved to superuser. –  Vineet Reynolds Sep 1 '09 at 21:37

5 Answers 5

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
/bin/bash

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:

(reverse-i-search)`': 

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 :). freshmeat.net/projects/bashcompletion –  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: vmunix.com/fbsd-book/configure.phtml –  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 http://svnweb.freebsd.org/base/stable/9/share/skel/dot.cshrc?revision=244007&view=co&pathrev=244007 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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