|

Linux CLI 15 🐧 shortcuts

Mastering keyboard shortcuts is the fastest way to boost your productivity in the terminal. Once these become muscle memory, you’ll navigate and edit commands at lightning speed — without ever touching the arrow keys.


Moving Around the Line

ShortcutAction
Ctrl + AMove cursor to the beginning of the line
Ctrl + EMove cursor to the end of the line
Alt + BMove back one word
Alt + FMove forward one word

Examples:

$ ls -la /var/log/myservice/debug.log
# Cursor at the end (after "log")
# Press Ctrl+A → cursor moves to start of line
# Press Ctrl+E → cursor back at end

Editing and Deleting

ShortcutAction
Ctrl + HDelete the character to the left of the cursor
Ctrl + WKill (delete) the word to the left
Alt + DKill from cursor to the end of the word
Alt + BackspaceKill from cursor to the beginning of the word

Examples:

$ echo "hello world foo bar"
# Cursor after "bar"
# Ctrl+W → deletes "bar", now: echo "hello world foo 
# Ctrl+W again → deletes "foo", now: echo "hello world

Cutting and Pasting (Kill/Yank)

ShortcutAction
Ctrl + KCut from cursor to the end of the line
Ctrl + UCut from cursor to the beginning of the line
Ctrl + Shift + KCut from cursor to end of line, save in kill buffer
Ctrl + YPaste text from kill buffer at cursor

Examples:

Cut and reorder:

$ cp /source/file.txt /destination/file.txt
# Cut the destination part with Ctrl+K
$ cp /source/file.txt /destination/file.txt
# Ctrl+K → "cp /source/file.txt /destination/"  (line now "cp /source/file.txt ")
# Ctrl+Y → pastes "/destination/file.txt"  (back to original)

Move to start of line:

$ cd /home/kronos/Documents
# Cursor at end of line
# Ctrl+U → cuts "/home/kronos/Documents", leaving "cd "
# Type " " + Ctrl+Y → "cd /home/kronos/Documents"

Practical: swap arguments

$ mv oldname.txt newname.txt
# Cursor at end
# Ctrl+W → cuts "newname.txt"
# Ctrl+W → cuts "oldname.txt"
# Type " " then Ctrl+Y → pastes "oldname.txt"
# Type " " then Ctrl+Y → pastes "newname.txt"
# Result: mv oldname.txt newname.txt  (still the same)

# Or with Ctrl+K:
$ mv oldname.txt newname.txt
# Ctrl+A (start of line)
# Ctrl+K (cut whole line)
# Ctrl+Y (paste back)

History Navigation

ShortcutAction
Ctrl + RReverse search through command history
Ctrl + PGo back in command history (like ↑)
Ctrl + NGo forward in command history (like ↓)

Ctrl + R — Reverse Search

The most powerful shortcut in this list!

How it works:

  1. Press Ctrl + R
  2. Start typing a keyword
  3. The most recent matching command appears
  4. Press Ctrl + R again to go further back
  5. Press Enter to run or to edit

Example:

(reverse-i-search)`git': git commit -m "fix: update readme"
# Press Ctrl+R again → previous command containing "git"
(reverse-i-search)`git': git status
# Press Enter → runs "git status"
# Or press → to edit it before running

Exiting search:

  • Ctrl + C — cancel
  • Enter — run the matched command
  • Esc — exit search but keep the line
  • / — exit and edit

Ctrl + P / Ctrl + N — History Navigation

KeySame as
Ctrl + P↑ (previous)
Ctrl + N↓ (next)

Example:

$ date
$ cal
$ pwd
# Press Ctrl+P three times → date
# Press Ctrl+N twice → pwd

Screen and Terminal Control

ShortcutAction
Ctrl + LClear the screen (like clear command)
Ctrl + JEnter a new line without moving to next tab stop
Ctrl + XExit current mode back to command line

Examples:

Clear screen:

$ ls -la
# (lots of output)
# Ctrl+L → clean screen, prompt at top

Multi-line command (Ctrl + J):

$ echo "Line 1" && \
> echo "Line 2"
# Or use Ctrl+J to insert a newline without running

Copy and Paste

ShortcutAction
Ctrl + Shift + CCopy selected text to clipboard
Ctrl + Shift + VPaste text from clipboard

Note: These are terminal emulator shortcuts, not shell shortcuts. They work in most Linux terminals (GNOME Terminal, Konsole, xfce4-terminal).

Why Ctrl+Shift+C instead of Ctrl+C?

  • Ctrl + C is reserved by the shell to cancel the current command
  • Terminal emulators use Ctrl + Shift + C for copying

Examples:

# Select text with mouse
# Ctrl+Shift+C → copy
# Ctrl+Shift+V → paste into another command or editor

Complete Shortcut Reference Table

Cursor Movement

ShortcutAction
Ctrl + ABeginning of line
Ctrl + EEnd of line
Alt + BBack one word
Alt + FForward one word

Editing

ShortcutAction
Ctrl + HDelete character left of cursor
Ctrl + WDelete word left of cursor
Alt + DDelete word right of cursor
Alt + BackspaceDelete word left of cursor

Kill/Yank (Cut/Paste)

ShortcutAction
Ctrl + KCut to end of line
Ctrl + UCut to beginning of line
Ctrl + Shift + KCut to end (save in kill buffer)
Ctrl + YPaste from kill buffer

History

ShortcutAction
Ctrl + RReverse search
Ctrl + PPrevious command (like ↑)
Ctrl + NNext command (like ↓)

Terminal

ShortcutAction
Ctrl + LClear screen
Ctrl + JNew line (no tab stop)
Ctrl + XExit current mode
Ctrl + Shift + CCopy to clipboard
Ctrl + Shift + VPaste from clipboard

Complete Example Session

Let’s walk through real scenarios:

# ============================================
# SCENARIO 1: FIX A TYPO IN A LONG COMMAND
# ============================================

$ cp /home/kronos/Documents/important-file.txt /backup/
# Oops! Forgot the destination is "/backup/"
# Actually, we meant "/mnt/backup/"
# Cursor is at end of line
# Ctrl+A → cursor to start
# Alt+F × 3 → forward 3 words
# ... but this is slow
# Better: Ctrl+W → deletes "/backup/"
# Type "/mnt/backup/" + Enter

# ============================================
# SCENARIO 2: SEARCH FOR A PREVIOUS COMMAND
# ============================================

$ git commit -m "initial commit"
$ git push origin main
$ npm install
$ docker build -t myapp .
$ git log
# Now you want to run "git push" again
# Ctrl+R → type "push"
(reverse-i-search)`push': git push origin main
# Press Enter → runs it again

# ============================================
# SCENARIO 3: SWAP TWO WORDS
# ============================================

$ mv file2.txt file1.txt
# Oops! Should be: mv file1.txt file2.txt
# Cursor at end of line
# Ctrl+W → deletes "file2.txt"
# Ctrl+W → deletes "file1.txt"
# Type " " + Ctrl+Y → pastes "file1.txt"
# Type " " + Ctrl+Y → pastes "file2.txt"
# Result: mv file1.txt file2.txt ✅

# ============================================
# SCENARIO 4: CLEAR SCREEN QUICKLY
# ============================================

$ cat /var/log/syslog
# (floods screen with output)
# Ctrl+L → clean screen, back to prompt

# ============================================
# SCENARIO 5: COPY OUTPUT TO ANOTHER APP
# ============================================

$ ls -la
# Select relevant lines with mouse
# Ctrl+Shift+C → copied
# Switch to editor/browser
# Ctrl+V (or Cmd+V on Mac) → pasted

# ============================================
# SCENARIO 6: CANCEL A HUNG COMMAND
# ============================================

$ find / -name "*.log"
# (takes forever)
# Ctrl+C → cancels the command
# Note: Ctrl+C cancels; Ctrl+Shift+C copies!

Kill Buffer Explained

The kill buffer is a temporary storage in the shell where cut text goes. Ctrl + Y (Yank) pastes from it.

ActionShortcut
Cut textCtrl + K, Ctrl + U, Ctrl + W, Alt + D
Paste cut textCtrl + Y

Key points:

  • The kill buffer holds the last cut text
  • Multiple cuts append to the buffer
  • Ctrl + Y pastes it back at cursor position
  • Buffer is session-only — not saved between terminals

Example — kill buffer with multiple cuts:

$ echo "line1 line2 line3"
# Ctrl+W → cuts "line3"
# Ctrl+W → cuts "line2" (appended)
# Now buffer contains "line2 line3"
# Ctrl+Y → pastes "line2 line3" 
# Result: echo "line1 line2 line3"

Best Practices

Do This:

# Learn Ctrl+R first
Ctrl+R              # Then type a keyword

# Use Ctrl+L instead of typing "clear"
Ctrl+L              # Faster than clear + Enter

# Use Ctrl+A / Ctrl+E to jump
Ctrl+A              # Start of line
Ctrl+E              # End of line

# Use Ctrl+W to delete a whole word
Ctrl+W              # Faster than Backspace

# Use Ctrl+U to clear a line you regret
Ctrl+U              # Cuts entire line to start

# Use Ctrl+Y to bring back cut text
Ctrl+Y              # Paste from kill buffer

Don’t Do This:

# Don't use arrow keys for everything
# ↑↑↑↓←←→→       → Slower than Ctrl+R

# Don't use Ctrl+C to copy
Ctrl+C              # ❌ Cancels the command!
Ctrl+Shift+C        # ✅ Copies

# Don't forget Ctrl+Shift+C for copy
# In Linux terminals, Ctrl+C ≠ copy!

# Don't backspace a whole word
# Hold Backspace    → Slow
Ctrl+W              # ✅ Instant

# Don't retype a long command
# Just press ↑ or use Ctrl+R

Common Pitfalls

PitfallProblemSolution
Ctrl+C to copyCancels commandUse Ctrl+Shift+C
Ctrl+V to pasteInserts literal characterUse Ctrl+Shift+V
Ctrl+K to save textCuts and saves in kill bufferUse Ctrl+Y to paste back
Arrow keys onlySlow history navigationUse Ctrl+R
Forget Ctrl+LType clear manuallyCtrl+L is instant
Confusing Ctrl+P/NSame as ↑/↓Use whichever feels natural

Real-World Use Cases

1. Editing a Long File Path

$ cp /home/kronos/projects/webapp/src/components/Header.jsx /backup/components/
# Cursor at end
# Ctrl+A → go to start
# Alt+F × 6 → move to "/backup/"
# Ctrl+W → delete the destination
# Type "/mnt/backup/Header.jsx"
# Press Enter

2. Rerunning a Previous Command with Edits

$ docker run -p 8080:80 nginx
# Ctrl+P → same command
# Ctrl+A → start
# Ctrl+F → navigate to "8080"
# Edit to "3000"
# Enter

3. Searching History for a Complex Command

$ ssh -i ~/.ssh/prod-key.pem ubuntu@10.0.1.5 -p 2222
# Later...
# Ctrl+R → type "ubuntu"
(reverse-i-search)`ubuntu': ssh -i ~/.ssh/prod-key.pem ubuntu@10.0.1.5 -p 2222
# Enter → reruns it

4. Reordering Arguments

$ chmod 755 script.sh
# Oops, want: chmod script.sh 755? No — order matters
# Actually: chmod 755 script.sh is correct
# But if you wanted to swap:
$ chmod 755 script.sh
# Ctrl+A → start
# Ctrl+W × 3 → delete "chmod 755 script.sh" word by word
# Type "chmod script.sh 755" (hypothetical)

5. Multi-Line Command Entry

$ for i in {1..5}; do
>     echo "Number: $i"
> done
# Each line is prompted with ">" to continue
# Use Ctrl+C to cancel if needed

Customizing Shortcuts (Bonus)

You can customize shortcuts in ~/.inputrc:

# ~/.inputrc
"\C-t": "hello world"           # Ctrl+T inserts "hello world"
"\C-g": kill-whole-line          # Ctrl+G kills the whole line
"\e[1;5C": forward-word          # Ctrl+Right → forward word
"\e[1;5D": backward-word         # Ctrl+Left → backward word

After editing:

$ bind -f ~/.inputrc
# Or restart the shell

Summary

CategoryKey Shortcuts
NavigationCtrl+A (start), Ctrl+E (end), Alt+B/F (words)
EditingCtrl+H (delete), Ctrl+W (delete word)
Cut/PasteCtrl+K (cut end), Ctrl+U (cut start), Ctrl+Y (paste)
HistoryCtrl+R (search), Ctrl+P/N (prev/next)
ScreenCtrl+L (clear), Ctrl+J (newline)
ClipboardCtrl+Shift+C (copy), Ctrl+Shift+V (paste)

Key takeaways:

  • Ctrl + R is the single most powerful shortcut — use it constantly
  • Ctrl + A and Ctrl + E jump to start and end of line
  • Ctrl + W deletes a whole word — faster than mashing Backspace
  • Ctrl + K and Ctrl + U cut to end or start of line
  • Ctrl + Y pastes back from the kill buffer — your safety net
  • Ctrl + L clears the screen instantly — no need for clear
  • Ctrl + Shift + C/V for copy/paste — because Ctrl + C cancels commands
  • Ctrl + P and Ctrl + N are the same as ↑ and ↓

Remember: Learning just 5 of these shortcutsCtrl+R, Ctrl+A, Ctrl+E, Ctrl+W, and Ctrl+L — will make you noticeably faster. The single most important is Ctrl+R for reverse history search. Once it clicks, you’ll wonder how you ever lived without it. And always remember the golden rule: Ctrl + C cancels commands — Ctrl + Shift + C copies text!


Stop using slow, ad-bloated tool sites! 🤮

🔎 Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)

⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free

🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!