In reverse i-search (Ctrl + R), Any method of switching between similar commands in history

I think an example would be good to understand my question.

... scp file1 user10@192.168.10.1:/home/user1/linuxfiles/samplecode/important ... ... scp file1 user10@192.168.10.1:/home/user1/linuxfiles/samplecode/important/tested ... ... 

Suppose this is the order of the teams in history. If I do Ctrl + R and type scp , it will show the last scp command executed (that is, the line ending with "verified").

But I want to find a scp command ending with 'important'. So, is there a way in this reverse-i-search look at all the commands starting with scp to choose the right one?

+43
command-line linux bash
Jan 09 '13 at 9:07
source share
3 answers

Continue pressing Ctrl - R and it will move through your story.

+91
Jan 09 '13 at 9:10
source share

If your search terms are a bit more complicated / not contiguous, another option is grep among history results, for example:

 history 300 | grep scp | grep important$ 

This will return a list of commands in your history that match, for example:

 3323 scp file1 user10@192.168.10.1:/home/user1/linuxfiles/samplecode/important 3325 scp file1 user10@192.168.10.1:/home/user1/winfiles/samplecode/important 

Then you can execute the corresponding command with !3325 .

I sometimes find this useful when running many of these commands, and you may have to press Ctrl + R repeatedly to return to the exact command.

+15
Jan 10 '13 at 2:31
source share

There is a great alternative to Ctrl + R

install https://github.com/dvorka/hstr

run it with hh

it displays a list of all recently executed commands (contents. / bash_history)

if you start typing a list, it will be filtered based on what you type

you can use the Up / Down arrows to select the desired command and select it with Enter

+2
Jan 19 '17 at 19:46 on
source share



All Articles