Sagar.BlogArticle
All posts
All posts
Linux

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.

January 4, 20257 min read
LinuxTerminalProductivityShortcuts

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).

Instead of holding the left/right arrow keys to move through a long command, use these to jump instantly:

Navigation Shortcuts

ShortcutAction
Ctrl + AJump to start of line
Ctrl + EJump to end of line
Alt + FMove forward one word
Alt + BMove backward one word
Ctrl + FMove forward one character (like →)
Ctrl + BMove backward one character (like ←)
Ctrl + XXToggle 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 end

Editing: 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

ShortcutAction
Ctrl + UCut everything before cursor
Ctrl + KCut everything after cursor
Ctrl + WCut the word before cursor
Alt + DCut the word after cursor
Ctrl + YPaste (yank) what was cut
Ctrl + HDelete character before cursor (backspace)
Ctrl + DDelete character under cursor
Alt + UUPPERCASE word from cursor forward
Alt + Llowercase word from cursor forward
Alt + TSwap 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 one

Control: Kill, Suspend, Clear

Control Shortcuts

ShortcutAction
Ctrl + CKill the currently running command (sends SIGINT)
Ctrl + ZSuspend the running command (pauses it, sends to background)
Ctrl + DExit the shell — same as typing exit
Ctrl + LClear the screen — same as clear
Ctrl + SFreeze terminal output (scroll lock)
Ctrl + QUnfreeze 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

ShortcutAction
/ Ctrl+PPrevious command
/ Ctrl+NNext command
Ctrl+RReverse 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
!gitRun last command that started with git
^old^newRepeat last command with old replaced by new
history-tricks.sh
# 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 [email protected]
# Press Ctrl+R again → older ssh commands
# Press Enter → run it
# Press Ctrl+G → cancel search

Tab 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  clone

Quick 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 options

Quick Check

You ran `rm important-file.txt` and meant to type `rm temp-file.txt`. Which shortcut replaces just that part without retyping the whole command?

Quick Check

You typed a long command but forgot to prefix it with `sudo`. What is the fastest fix?

Exercise

Practice session — do each of these WITHOUT using the arrow keys:

  1. 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
  2. Type a long path like ls /etc/apt/sources.list.d

    • Use tab completion after each / to avoid typing the full path
  3. Run any command, then re-run it with sudo !!

  4. Use Ctrl+R to find and re-run a command from earlier in this exercise