Terminal Keyboard Shortcuts That Save You Hours
Stop reaching for the mouse. Master Ctrl+R, Ctrl+U, tab completion, history tricks, and the shortcuts every terminal user needs.
The fastest terminal users aren't faster typists — they're smarter about not typing. Keyboard shortcuts let you edit commands instantly, reuse previous work, and navigate without ever touching the mouse.
learn these once and they become muscle memory. They work in bash, zsh, and even many other programs that use readline (like the Python REPL).
Navigation: Move Around the Line
Instead of holding the left/right arrow keys to move through a long command, use these to jump instantly:
Navigation Shortcuts
| Shortcut | Action |
|---|---|
Ctrl + A | Jump to start of line |
Ctrl + E | Jump to end of line |
Alt + F | Move forward one word |
Alt + B | Move backward one word |
Ctrl + F | Move forward one character (like →) |
Ctrl + B | Move backward one character (like ←) |
Ctrl + XX | Toggle between start of line and cursor |
# Example: you typed a long command and need to fix something at the start
$ sudo apt install nginx php mysql-server postgresql redis
# Instead of holding ← for 40 characters:
# Press Ctrl+A → jumps instantly to start
# Press Alt+F repeatedly → skips word by word
# Press Ctrl+E → back to the endEditing: Cut, Paste, Transform
The terminal has its own clipboard called the kill ring. Ctrl+K, Ctrl+U, and Ctrl+W all "cut" text (send it to the kill ring). Ctrl+Y pastes it back. This is incredibly useful for restructuring commands on the fly.
Editing Shortcuts
| Shortcut | Action |
|---|---|
Ctrl + U | Cut everything before cursor |
Ctrl + K | Cut everything after cursor |
Ctrl + W | Cut the word before cursor |
Alt + D | Cut the word after cursor |
Ctrl + Y | Paste (yank) what was cut |
Ctrl + H | Delete character before cursor (backspace) |
Ctrl + D | Delete character under cursor |
Alt + U | UPPERCASE word from cursor forward |
Alt + L | lowercase word from cursor forward |
Alt + T | Swap current word with previous word |
# Real workflow: fix a typo at the start without retyping everything
$ git commit -m "fix: updtae login form validation"
# ^ typo here, cursor is at end
# Press Ctrl+A → jump to start
# Press Alt+F Alt+F Alt+F Alt+F → move to "updtae"
# Press Ctrl+W → cut "updtae"
# Type "update" → done
# Another workflow: clear a misconfigured command and start over
$ sudo rm -rf /var/www/html/wrong-dir/ # Oops, wrong directory!
# Press Ctrl+C → cancel
# Or: Ctrl+U → cuts the whole line (saves it to kill ring)
# Then type the correct command
# Then Ctrl+Y if you need to reference the old oneControl: Kill, Suspend, Clear
Control Shortcuts
| Shortcut | Action |
|---|---|
Ctrl + C | Kill the currently running command (sends SIGINT) |
Ctrl + Z | Suspend the running command (pauses it, sends to background) |
Ctrl + D | Exit the shell — same as typing exit |
Ctrl + L | Clear the screen — same as clear |
Ctrl + S | Freeze terminal output (scroll lock) |
Ctrl + Q | Unfreeze terminal output |
Ctrl+C vs Ctrl+Z
Ctrl+C terminates the process — it's gone. Ctrl+Z suspends it — the process is paused and waiting in the background. You can resume it with fg (foreground) or bg (keep running in background). Use Ctrl+Z when you want to temporarily step away from an interactive program.
History: Stop Retyping Commands
Your shell saves every command you've ever run. These shortcuts let you use that history without scrolling through it manually:
History Shortcuts
| Shortcut | Action |
|---|---|
↑ / Ctrl+P | Previous command |
↓ / Ctrl+N | Next command |
Ctrl+R | Reverse search — type part of a command to find it |
!! | Run the last command again |
sudo !! | Run last command again with sudo |
!$ | The last argument of the previous command |
!* | All arguments of the previous command |
!git | Run last command that started with git |
^old^new | Repeat last command with old replaced by new |
# The most useful: sudo !!
apt install nginx # Forgot sudo!
sudo !! # → sudo apt install nginx ✓
# Reuse the last argument
mkdir /var/www/myproject
cd !$ # → cd /var/www/myproject ✓
# Fix a typo in the last command
echo "Helo World"
^Helo^Hello # → echo "Hello World" ✓
# Ctrl+R interactive search
# Press Ctrl+R → type "ssh" → finds: ssh user@myserver.com
# Press Ctrl+R again → older ssh commands
# Press Enter → run it
# Press Ctrl+G → cancel searchTab Completion
Tab is the most important productivity key in the terminal. Press it once to autocomplete a unique match. Press it twice to see all possibilities.
Tab completion works for: command names, file paths, directory names, even package names (with apt/dnf).
# Command completion
sys → Tab → systemctl
# File and directory completion
cd /ho → Tab → cd /home/
cd /home/sa → Tab → cd /home/sagar/
# Show multiple options (press Tab twice)
ls /etc/ap → Tab Tab
# apache2/ apparmor/ apparmor.d/ apt/
# Never type a full path again
cat /etc/os → Tab → cat /etc/os-release
# Works with arguments too
git ch → Tab Tab
# checkout cherry-pick cloneQuick Reference
# ─── NAVIGATION ─────────────────────────────────────────────
# Ctrl+A Jump to start of line
# Ctrl+E Jump to end of line
# Alt+F Forward one word
# Alt+B Backward one word
# ─── EDITING ─────────────────────────────────────────────────
# Ctrl+U Cut before cursor
# Ctrl+K Cut after cursor
# Ctrl+W Cut word before cursor
# Ctrl+Y Paste (yank)
# Alt+T Swap word with previous
# ─── CONTROL ─────────────────────────────────────────────────
# Ctrl+C Kill running command
# Ctrl+Z Suspend running command
# Ctrl+L Clear screen
# Ctrl+D Exit shell
# ─── HISTORY ─────────────────────────────────────────────────
# Ctrl+R Reverse search
# !! Last command
# sudo !! Last command with sudo
# !$ Last argument
# ^a^b Fix typo in last command
# ─── COMPLETION ──────────────────────────────────────────────
# Tab Autocomplete
# Tab Tab Show all optionsYou ran `rm important-file.txt` and meant to type `rm temp-file.txt`. Which shortcut replaces just that part without retyping the whole command?
You typed a long command but forgot to prefix it with `sudo`. What is the fastest fix?
Practice session — do each of these WITHOUT using the arrow keys:
-
Type:
echo "terminal shortcuts are amazing"- Use Ctrl+A to jump to the start, Ctrl+E to jump to the end
- Use Alt+F / Alt+B to move word by word
-
Type a long path like
ls /etc/apt/sources.list.d- Use tab completion after each
/to avoid typing the full path
- Use tab completion after each
-
Run any command, then re-run it with
sudo !! -
Use
Ctrl+Rto find and re-run a command from earlier in this exercise