Bash - Keyboard Shortcuts


Handy-dandy command line shortcuts!

Cursor

Move the cursor around when typing commands.

  • Ctrl + a: Go to the beginning of the line
  • Ctrl + e: Go to the end the of the line
  • Alt + b: Go back one word
  • Alt + f: Go forward one word
  • Ctrl + xx: Move between the beginning of the line and the current position of the cursor

Cut Paste

  • Ctrl + w: Cut the word before the cursor
  • Ctrl + u: Cut the line before the cursor
  • Ctrl + k: Cut the line after the cursor
  • Ctrl + y: Paste (yank) from the terminal's clipboard
  • Alt + .: Recall the last arguments of the previous command

Deleting Text

Delete part of a line of text.

  • Alt + d: Delete all characters after the cursor until the next whitespace

Fixing Typos

  • Alt + t: Swap the current word with the previous word

History

Command history can be gone through via the ↑↓. In the middle of your history? Use Ctrl + c to get back to the start!

Here are some commands to further explore your bash history:

  • Alt + r: Revert command pulled from history to its original form (undo changes to command)
  • Ctrl + r: Recall (search) for the last instance of a command
    • Enter: Run the searched command
    • Ctrl + g: Leave the search without running a command

Processes

Manage running processes

  • Ctrl + c: Kill the current running process
  • Ctrl + z: Suspends the current running process and moves it to the background
    • Use bg to start the process in the background
    • Use jobs and fg %<Number> to bring it back to the foreground
  • Ctrl + d: Send the EOF (End-Of-File) marker. If in bash, the terminal will exit

Screen

Control the screen

  • Ctrl + l: Clear the screen
  • Ctrl + s: Stop all output to the screen (nice when there is LOTS of output and you want to look at something now)
    • Ctrl + q: Resume output to the screen