Jump to a word in a command in Bash

Viewed 929

Consider:

ssh -i "key.pem" root@server.com

Is there a quick way to jump to the beginning of "root" in such a Bash command in the terminal, without iterating over every word/character?

1 Answers

Yes. Bring up the last command using up arrow. These shortcuts will help:

  • Ctrl + E - go to the end of the line
  • Ctrl + A - go to the start of the line
  • Alt + left - go back one word
  • Alt + right - go right one word
  • Ctrl + W - delete the last word

To search the command line and the command line history, use:

  • Ctrl + R and then type the search string, e.g. "roo" to search backwards for "root@...". In the example you have given, however, it will be easier just to jump forward or back by words.
  • Ctrl + S search forwards (rarely useful). (If forward searching doesn't appear to work, try this other Stack Overflow answer.)

See also this page and google "Bash command line editing" for more tricks.

Related