Keyboard shortcuts#

Here are some useful keyboard shortcuts for working in the terminal:

  • Abort a running command:

    • Linux and macOS: Use ctrl+c to abort a command. You can test this by running the silly command sleep 10 (does nothing for ten seconds) and abort it with ctrl+c before it finishes.

  • Repeat previous commands:

    • Linux and macOS: Use up and down to cycle through previous commands.

  • Auto-complete file/directory names:

    • Linux and macOS: Use tab to auto-complete long file/directory names. If there are multiple possible matches, press tab twice to see the alternatives.

  • Move cursor word by word:

    • Linux: Use ctrl+right and ctrl+left

    • macOS: Use alt+right and alt+left

  • Jump to the beginning/end of the line:

    • Linux and macOS: Use ctrl+a and ctrl+e

  • Delete everything after the cursor:

    • Linux and macOS: Use ctrl+k. Thus, a quick way to clear the command line is to press ctrl+a and then ctrl+k. (Or you can press ctrl+c.)

  • Copy/paste:

    • Linux: Use ctrl+shift+c and ctrl+shift+v

    • macOS: Use cmd+c and cmd+v

  • Search previous commands:

    • Linux and macOS: Press ctrl+r and start typing a command. You can press ctrl+r again to cycle through alternative matches. Once you found it, press ctrl+j or an arrow key to start editing the command.

  • Clear the terminal screen:

    • Linux and macOS: Press ctrl+l. You can also do this by running the command clear.