Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reverse search UNIX command.

56 views
Skip to first unread message

shraw...@gmail.com

unread,
Jan 19, 2016, 5:17:37 AM1/19/16
to
Hi All,

Can someone tell me the command for reverse search in UNIX.

i am only known about ctrl + r in Linux.

Thanks in Advance! :)

Trek

unread,
Jan 19, 2016, 8:09:08 AM1/19/16
to
On Tue, 19 Jan 2016 02:17:30 -0800 (PST)
shraw...@gmail.com wrote:

> Can someone tell me the command for reverse search in UNIX.
> i am only known about ctrl + r in Linux.

ctrl + r is a bash command, that runs everywhere, not only linux

ksh is most common under commercial unixes and it comes with the vi
mode (check the manual page chapter "Vi Editing Mode")
to enable it you must set the vi option:

$ set -o vi

then you can press ESC to enter in the vi control mode and you can use
most of the vi commands like:

/string + ENTER to search a string like in bash
k to get the previous command
j for the next command
l to move the cursor right
h to move the cursor left
i to add text (and then press ESC to return in the control mode)
x to remove a character
ENTER to finally execute the command

additionally the vi mode is present other shells like bash, yash and zsh

Shrawan Bhagwat

unread,
Jan 21, 2016, 9:00:42 AM1/21/16
to
Hi Trek,

Thanks for Your reply :)

But my Query is that the way we do reverse search in bash in Linux, i am unable to do the same using the same command (ctrl+r) in UNIX.

Can you please help me with this?

Janis Papanagnou

unread,
Jan 21, 2016, 9:35:47 AM1/21/16
to
I'm not sure what UNIX that is that you actually have. Maybe your terminal
settings are not set appropriately to map ^R as in your Linux configuration.

Without knowing details I can just extend the answer given by Trek; you may
want to try vi-mode and use the '/' search(-forward) command, then use 'n'
(or resp. 'N') to find the next (resp. previous) match in the history file.
There should not be a problem with those regular (i.e. non-control) keys.

Janis

Bit Twister

unread,
Jan 21, 2016, 9:53:55 AM1/21/16
to
On Thu, 21 Jan 2016 06:00:34 -0800 (PST), Shrawan Bhagwat wrote:
> Hi Trek,
>
> Thanks for Your reply :)
>
> But my Query is that the way we do reverse search in bash in Linux,
> i am unable to do the same using the same command (ctrl+r) in UNIX.

Your command line editor can be control with an environment same for
the default editor. Examples from my setup

export VISUAL=emacs # default command line editor
export EDITOR=nedit # default file editor
export PAGER=less # default file pager
0 new messages