CentOS up arrow previous command

3

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.

Dave

Posted 2009-09-01T21:13:00.250

Reputation: 165

What shell are you using? – Rob Jones – 2009-09-01T21:21:33.090

2Needs to be moved to superuser. – Vineet Reynolds – 2009-09-01T21:37:29.670

Answers

2

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

mando

Posted 2009-09-01T21:13:00.250

Reputation:

1Thanks! 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. – None – 2009-09-01T21:42:54.013

Honestly, I just use Bash Completion to cheat around that :).

http://freshmeat.net/projects/bashcompletion/

– None – 2009-09-01T21:51:31.220

2

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

knweiss

Posted 2009-09-01T21:13:00.250

Reputation: 1 636

1

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

flokra

Posted 2009-09-01T21:13:00.250

Reputation:

If you're interested in getting the exact behaviour of the FreeBSD CSH, you also want to read this: http://www.vmunix.com/fbsd-book/configure.phtml

– None – 2009-09-01T21:48:45.313

0

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

Rich Homolka

Posted 2009-09-01T21:13:00.250

Reputation: 27 121

0

  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
    

wandns

Posted 2009-09-01T21:13:00.250

Reputation: 1