Matching command scroll - ksh

In ksh is there a was to scroll thru all matching commands? For example I executed several commands over several days. Is there a way to scroll thru all the matching 'find' commands only that was executed?

No messing with the .history file. Anyway to do this from the command prompt? TIA.

I have not always had 100% success with this and don't know the reasons why but it works way more than not.

If you don't have this set already, type

set -o vi

at the command prompt. I don't know the official term but this lets you scroll back through the command history.

Then type command below in two key strokes. Not both keys at the same time.

Esc k

This should recall the last command you executed from the command prompt.

If you just want to manually scroll though the command history hit

 n 

for next.

Then if you want to search through the command history for something specific, like the last find command in stead of hitting "n" to scroll back though the list manually you would hit the forwardslash (/) and what specific value you are looking for like below.

root@foobar:/ $ /find

After typing the value simular to above hit enter and it should display the last "find" command that you executed. Then you would just keep hitting the letter "n" to display the next find command that you executed or possibly anyone else executed while logged in as that id if you happen to be using root.

Hope this helps.

1 Like

"VI command line editing mode". :wink:

Basically you have a vi-editor with only one line visible (and the history-file as text open) at the commandline. (Almost) every vi-command will work on the commandline too:

ESC (to set the editor from insert- to command-mode) and then:

  • k - a line up (therefore: last command)
  • j - a line down (therefore: next command, if you have already gone back some)
  • l - move cursor a character right
  • h - move cursor a character left
  • w - move cursor to first character of the word right to the cursor
  • b - move cursor to first character of the word left to the cursor
  • W/B - same as w/b but only taking whitespace as word boundaries into consideration
    This means: let text be "abc/def/ghi". If the cursor is on "g", then "w" brings you to the third "/", the next "w" to "d", etc., while "W" brings you to "a".
  • 0 - move to first character in the line

  • / - search through command history (all regexps allowed)
  • n - repeat last search and go to next hit
  • N - repeat last search and go to previous hit

  • i - reenter insert mode
  • a - append: insert right after cursor position
  • A - append at end of line

  • v - open a full vi with the command line as text (saving & exiting executes the command)
  • # - put a comment sign in front of the command and put it into history
    This won't execute anything, but saves a command(-part) for future use in the history file.

I hope this helps.

bakunin

3 Likes

Thanks.

---------- Post updated at 01:39 PM ---------- Previous update was at 01:36 PM ----------

This is what I was looking for. Thanks.