0

For example, can I see all the previous parameters I passed to the command ssh (i.e. all the server addresses I passed as a parameter when calling ssh)?

This is going to be something similar to the 'history' command, but not exactly.

It would be amazing if I could tab through this command history but that is probably asking for too much. For example, if I typed in ssh, and then tab would allow me to cycle through previously executed commands.

migrated from serverfault.com Jun 2 '16 at 15:07

This question came from our site for system and network administrators.

  • 3
    Ctrl+R, type ssh. – Jenny D May 30 '16 at 8:20
4

Not exactly what you are asking for, but you can search through the history.

Eg, ^R followed by ssh and then continue cycling through commands with ^R.

(That's reverse search. Forward search is by default at ^S but that unfortunately collides with XOFF (undone with ^Q) for the typical terminal, so you probably want to remap that for it to be useful.)

4

This is possible. You want to investigate Ctrl-R and a little bit of history expansion.

From man bash:

reverse-search-history (C-r)
    Search backward starting at the current  line  and  moving 'up'
    through  the  history  as  necessary.   This  is  an incremental
    search.

History expansions introduce words from the history list into the input
stream,  making  it  easy to repeat commands, insert the arguments to a
previous command into the current input line, or fix errors in previous
commands quickly.

Further explanations on reverse-search-history:

Hit Ctrl-R and start typing in a string. You will see the last line from your history that contains the string in any position, updated for every keypress. Hit Ctrl-R more times to see preceding lines without typing in new characters. Hit enter to accept and launch the command, left-right to edit the command, up-down to browse history without limiting to the searched string starting from the line you found, Ctrl-C to abandon the search.

1

This is also useful:

history-search-backward
      Search backward through the history for the string of characters between the start
      of the current line and the point.  This is a non-incremental search.

Might not be bound by default, but you can bind it and h-s-forward to e.g. page up/page down. Writing the start of a command line and hitting pgup/pgdown then allows you scroll through command lines starting with that. I've gone a bit further and bound those to up/down arrow keys too.

In /etc/inputrc or $HOME/.inputrc:

# pgup, pgdown, up, down
"\e[5~" history-search-backward
"\e[6~" history-search-forward
"\e[A" history-search-backward
"\e[B" history-search-forward
  • Actually I'd find this more useful than Ctrl-R, because I've usually started typing before before I decide to do a search. Since as far as I can see reverse-search-history throws away what was typed before -- I think I'll try binding history-search-backward to Ctrl-R in lieu of reverse-search-history. – Law29 Jun 5 '16 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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