Terminal & Command Line Essential Keyboard Shortcuts
Speed up command line work with essential terminal shortcuts for cursor movement, text editing, history search, and process control in bash, zsh, and iTerm2.
Detailed Explanation
Terminal Command Line Shortcuts
Terminal keyboard shortcuts are based on readline, the line-editing library used by bash, zsh, and most shells. These shortcuts work in macOS Terminal, iTerm2, Windows Terminal, and Linux terminals.
Cursor Movement
- Beginning of Line (
Ctrl+A) — jump to the start of the current command - End of Line (
Ctrl+E) — jump to the end - Move Back One Word (
⌥+B/Alt+B) — move cursor left by one word - Move Forward One Word (
⌥+F/Alt+F) — move cursor right by one word - Move Back One Character (
Ctrl+B) — same as left arrow - Move Forward One Character (
Ctrl+F) — same as right arrow
Text Editing
- Delete Word Before Cursor (
Ctrl+W) — delete the word behind the cursor - Delete to Beginning of Line (
Ctrl+U) — clear everything before the cursor - Delete to End of Line (
Ctrl+K) — clear everything after the cursor - Paste (Yank) (
Ctrl+Y) — paste the last deleted text (from Ctrl+W, Ctrl+U, or Ctrl+K) - Swap Characters (
Ctrl+T) — swap the two characters before the cursor
History
- Previous Command (
↑orCtrl+P) — cycle through previous commands - Next Command (
↓orCtrl+N) — cycle forward through command history - Search History (
Ctrl+R) — reverse incremental search through command history. Type any substring to find matching commands. - Run Previous Command (
!!) — re-execute the last command (not a shortcut, but essential) - Run Last Command with sudo (
sudo !!) — re-run the previous command with elevated privileges
Process Control
- Cancel (
Ctrl+C) — send SIGINT to the foreground process - Suspend (
Ctrl+Z) — send SIGTSTP to suspend the process (resume withfg) - EOF/Exit (
Ctrl+D) — send end-of-file, closes the shell if the line is empty - Clear Screen (
Ctrl+Lor⌘+K) — clear the terminal output
These shortcuts use readline/emacs keybindings by default. Some shells support vim keybindings (set -o vi in bash).
Use Case
Terminal shortcuts are fundamental for any developer, devops engineer, or system administrator who works in the command line. Ctrl+R (history search) alone can save enormous time by finding long, complex commands without retyping them. Ctrl+A and Ctrl+E for line navigation are faster than arrow keys for editing long commands.