vote up 0 vote down star

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.

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

migrated from stackoverflow.com

4 Answers

vote up 1 vote down

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').

link|flag
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 at 21:42
Honestly, I just use Bash Completion to cheat around that :). freshmeat.net/projects/bashcompletion – mando Sep 1 at 21:51
vote up 1 vote down

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

Also, this belongs to SuperUser.

HTH, flokra

link|flag
Thanks! So, I guess I'll install csh. – Dave Sep 1 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 at 21:48
vote up 0 vote down

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

link|flag
vote up 0 vote down

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).

link|flag

Your Answer

Get an OpenID
or
never shown

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