HomeTerminal & Command LineTerminal Shortcuts & Productivity
beginner10 min read· Module 3, Lesson 4

⌨️Terminal Shortcuts & Productivity

Tab completion, history, shortcuts, and tricks that save hours

Terminal Shortcuts & Productivity

The difference between a beginner and a power user often comes down to shortcuts. Learning a handful of keyboard tricks can cut your terminal work time in half — or more. This lesson covers the essential shortcuts, history tricks, and productivity patterns every developer should know.


1. Tab Completion — The Most Important Shortcut

Tab completion is the single most important shortcut in the terminal. Instead of typing a full file name, path, or command, you press Tab and the shell finishes it for you.

How It Works

Terminal
# Type the beginning of a file name, then press Tab cd Doc[Tab] # Shell completes it to: cd Documents/ # If there are multiple matches, press Tab twice to see all options cd D[Tab][Tab] # Shows: Desktop/ Documents/ Downloads/

Tab Completion Works For

  • File and directory names — the most common use
  • Command names — type gi[Tab] to get git
  • Git branchesgit checkout fea[Tab] completes to git checkout feature-branch
  • Environment variablesecho $HO[Tab] completes to echo $HOME
  • SSH hostnames — if configured in your SSH config
  • Package names — many package managers support tab completion

Why It Matters

  • Speed — you type fewer characters
  • Accuracy — the shell never misspells a filename
  • Discovery — pressing Tab twice shows you what is available
  • Confidence — if Tab completes, the path exists

Pro Tip

If Tab does nothing, the match is ambiguous. Press Tab again to see all possibilities. Then type one or two more characters and Tab again.

Terminal
# Nothing happens on first Tab because multiple matches exist ls pro[Tab] # Press Tab again to see options: # profile.txt project/ prometheus.yml # Add one more letter and Tab again ls proj[Tab] # Completes to: ls project/

2. Command History

Your shell remembers every command you run. Learning to navigate that history is a huge time saver.

Up / Down Arrow Keys

The simplest way to access history:

Terminal
# Press Up Arrow to go to the previous command # Press Up Arrow again to go further back # Press Down Arrow to go forward in history # Press Enter to re-run the displayed command

The history Command

View your full command history:

Terminal
# Show all history history # Show last 20 commands history 20 # Search history for a specific command history | grep "docker" # Run a specific command by number !42 # This runs whatever command was number 42 in your history

Ctrl+R — Reverse Search (Game Changer)

This is the most powerful history feature. Press Ctrl+R and start typing any part of a previous command:

Terminal
# Press Ctrl+R, then type "docker" (reverse-i-search)\`docker\`: docker compose up -d # Press Ctrl+R again to cycle through older matches # Press Enter to run the found command # Press Ctrl+C or Escape to cancel the search # Press Right Arrow to edit the found command before running

Why Ctrl+R Is So Powerful

Imagine you ran a complex command 200 commands ago:

Terminal
kubectl exec -it my-pod-abc123 -- /bin/bash -c "cat /var/log/app.log | tail -50"

Instead of typing all of that again, press Ctrl+R, type kubectl exec, and it appears instantly. Press Enter to run it.


3. Essential Keyboard Shortcuts

These shortcuts work in most Unix shells (Bash, Zsh) and are based on Emacs keybindings.

Canceling and Exiting

ShortcutActionWhen to Use
Ctrl+CCancel / kill current processA command is stuck or you want to stop it
Ctrl+DExit the shell / send EOFClose terminal session or end input
Ctrl+ZSuspend current processPause a process (resume with fg)

Clearing and Display

ShortcutActionWhen to Use
Ctrl+LClear the screenClean up a cluttered terminal
clearSame as Ctrl+L (command)Alternative to the shortcut

Cursor Movement

ShortcutActionWhen to Use
Ctrl+AMove cursor to beginning of lineJump to the start quickly
Ctrl+EMove cursor to end of lineJump to the end quickly
Alt+FMove cursor one word forwardNavigate within a long command
Alt+BMove cursor one word backwardNavigate within a long command

Deleting Text

ShortcutActionWhen to Use
Ctrl+UDelete from cursor to beginning of lineClear everything before cursor
Ctrl+KDelete from cursor to end of lineClear everything after cursor
Ctrl+WDelete one word before cursorRemove the last word you typed
Alt+DDelete one word after cursorRemove the next word
Ctrl+YPaste (yank) the last deleted textUndo a Ctrl+U or Ctrl+K

Example Workflow

Suppose you typed a long command but need to change the beginning:

Terminal
# You typed: npm run build --env=production --verbose --output=dist # You realize you need sudo. Instead of using the arrow keys: # 1. Press Ctrl+A to jump to the beginning # 2. Type "sudo " before the command # 3. Press Ctrl+E to jump back to the end if needed # 4. Press Enter to run sudo npm run build --env=production --verbose --output=dist

4. History Shortcuts

!! — Repeat Last Command

Terminal
# Run the last command again !! # Most common use: forgot sudo apt install nginx # Permission denied! sudo !! # Expands to: sudo apt install nginx

!$ — Last Argument of Previous Command

Terminal
mkdir /var/www/myproject cd !$ # Expands to: cd /var/www/myproject

!command — Run Last Command Starting With...

Terminal
!git # Runs the last command that started with "git" !ssh # Runs the last command that started with "ssh"

Use With Caution

The ! shortcuts run commands immediately without confirmation. If you are not sure what the last matching command was, use Ctrl+R instead — it shows you the command before running it.


5. Wildcards — Match Multiple Files

Wildcards let you work with groups of files using patterns instead of listing each file individually.

The * Wildcard — Match Anything

Terminal
# List all .txt files ls *.txt # Delete all .log files rm *.log # Copy all images to a folder cp *.png *.jpg images/ # List all files starting with "report" ls report* # Match anything with "test" in the name ls *test*

The ? Wildcard — Match One Character

Terminal
# Match file1.txt, file2.txt, file3.txt (but not file10.txt) ls file?.txt # Match any single character ls report_?.pdf # Matches: report_A.pdf, report_B.pdf # Does not match: report_AB.pdf

Combining Wildcards

Terminal
# All JavaScript files in any subdirectory (Bash with globstar) ls **/*.js # All files with a three-letter extension ls *.???

6. Command Chaining

Run multiple commands in sequence using operators.

&& — AND (Run Next Only If Previous Succeeds)

Terminal
# Build and then deploy — only deploy if build succeeds npm run build && npm run deploy # Create directory and enter it mkdir myproject && cd myproject # Update, upgrade, then clean sudo apt update && sudo apt upgrade -y && sudo apt autoremove

|| — OR (Run Next Only If Previous Fails)

Terminal
# Try to find the file, or print an error message cat config.json || echo "Config file not found!" # Try the primary server, fall back to secondary ping -c 1 primary.server || ping -c 1 backup.server

; — Run Sequentially (Regardless of Success or Failure)

Terminal
# Run both commands no matter what echo "Starting..."; npm run build; echo "Done." # Clean up and rebuild regardless rm -rf dist; npm run build

Choosing the Right Operator

OperatorMeaningUse When
&&AND — next runs only on successSteps depend on each other
||OR — next runs only on failureYou need a fallback
;Sequential — always runs nextSteps are independent

7. Piping — Connect Commands Together

The pipe operator | sends the output of one command as input to the next.

Terminal
# List files and filter for .js files ls -la | grep ".js" # Count how many files are in a directory ls | wc -l # Find the 10 largest files du -sh * | sort -rh | head -10 # Search processes for "node" ps aux | grep "node" # Get unique sorted entries from a file cat data.txt | sort | uniq # Chain multiple pipes cat server.log | grep "ERROR" | sort | uniq -c | sort -rn | head -5 # This finds the 5 most frequent error messages in the log

How Piping Differs from Chaining

  • Chaining (&&) runs commands in sequence — command B starts after command A finishes
  • Piping (|) connects commands — command B processes the output of command A as it streams

8. Redirecting Output

Send command output to files instead of the screen.

> — Write to File (Overwrite)

Terminal
# Save directory listing to a file ls -la > filelist.txt # Save command output echo "Hello World" > greeting.txt # Save errors to a file npm run build 2> errors.log

>> — Append to File

Terminal
# Add a line to an existing file echo "New entry" >> log.txt # Append date to a log date >> activity.log # Accumulate results echo "Test 1: PASS" >> results.txt echo "Test 2: FAIL" >> results.txt

Redirect Both Output and Errors

Terminal
# Send both stdout and stderr to a file npm run build > build.log 2>&1 # Send output to one file, errors to another npm run build > output.log 2> errors.log # Discard all output (send to /dev/null) command > /dev/null 2>&1

9. Aliases — Create Your Own Shortcuts

Aliases let you create short names for long or frequently used commands.

Creating Aliases

Terminal
# Temporary alias (lasts until terminal closes) alias ll="ls -la" alias gs="git status" alias gc="git commit -m" # Use them like regular commands ll gs gc "fix: update login flow"

Permanent Aliases

Add aliases to your shell config file to make them permanent:

Terminal
# For Zsh (macOS default) nano ~/.zshrc # For Bash nano ~/.bashrc # Add lines like: alias ll="ls -la" alias gs="git status" alias gp="git push" alias gl="git log --oneline --graph" alias dc="docker compose" alias k="kubectl" alias python="python3" alias pip="pip3" # After editing, reload the config: source ~/.zshrc # or source ~/.bashrc

Useful Alias Ideas

Terminal
# Navigation alias ..="cd .." alias ...="cd ../.." alias home="cd ~" alias projects="cd ~/Projects" # Safety nets alias rm="rm -i" # Confirm before deleting alias cp="cp -i" # Confirm before overwriting alias mv="mv -i" # Confirm before overwriting # Git workflow alias gst="git status" alias gco="git checkout" alias gbr="git branch" alias gpl="git pull" alias gps="git push" alias glog="git log --oneline --graph --all" # Development alias serve="python3 -m http.server 8000" alias ports="lsof -i -P -n | grep LISTEN" alias myip="curl -s ifconfig.me"

Viewing and Removing Aliases

Terminal
# List all current aliases alias # Remove an alias unalias ll

10. Full Keyboard Shortcuts Reference

Here is a comprehensive reference table of the most useful terminal shortcuts:

Navigation

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

Editing

ShortcutAction
Ctrl+UDelete to beginning of line
Ctrl+KDelete to end of line
Ctrl+WDelete previous word
Alt+DDelete next word
Ctrl+YPaste last deleted text
Ctrl+TSwap current and previous character
Alt+TSwap current and previous word
Alt+UUppercase current word
Alt+LLowercase current word

History

ShortcutAction
Up ArrowPrevious command
Down ArrowNext command
Ctrl+RReverse search history
Ctrl+GCancel history search
Ctrl+PPrevious command (same as Up)
Ctrl+NNext command (same as Down)
!!Repeat last command
!$Last argument of previous command
!*All arguments of previous command
!commandLast command starting with "command"

Control

ShortcutAction
Ctrl+CCancel current command
Ctrl+DExit shell or send EOF
Ctrl+ZSuspend current process
Ctrl+LClear screen
Ctrl+SFreeze terminal output
Ctrl+QResume terminal output

11. Speed Comparison: Mouse vs. Keyboard

Here is a real-world comparison showing why keyboard shortcuts matter.

Task: Edit a File, Search for an Error, Fix It, Commit

Mouse-Heavy Workflow (Estimated: 45 seconds)

  1. Click on terminal window (1s)
  2. Type cd and manually type the full path (5s)
  3. Type cat filename.txt and scroll to find the error (10s)
  4. Open the file in a GUI editor, click to the right line (5s)
  5. Make the edit, save with mouse click (5s)
  6. Switch back to terminal, type full git commands (15s)
  7. Click through confirmation dialogs (4s)

Keyboard Workflow (Estimated: 15 seconds)

  1. Ctrl+R then type cd proj — instantly recalls cd ~/Projects/myapp (2s)
  2. grep -n "error" src/*.js — finds the line instantly (3s)
  3. vi +42 src/app.js — opens file at the exact line (1s)
  4. Fix the error, :wq to save and quit (4s)
  5. gst (alias) then gc "fix: resolve null check" (5s)

Result: 3x faster with keyboard shortcuts.

The Compound Effect

ScenarioMouse WorkflowKeyboard WorkflowTime Saved
Edit and commit45 seconds15 seconds30 seconds
10 edits per day7.5 minutes2.5 minutes5 minutes
Over one month (22 days)2.75 hours0.92 hours1.83 hours
Over one year33 hours11 hours22 hours

These numbers are conservative. Power users often report saving 100+ hours per year from terminal shortcuts alone.


Summary

The shortcuts covered in this lesson form the foundation of terminal productivity:

CategoryKey Takeaway
Tab completionAlways use Tab — it is faster and more accurate than typing
HistoryCtrl+R is the most powerful history tool — learn it by heart
NavigationCtrl+A, Ctrl+E, Ctrl+W save constant arrow-key pressing
CancelingCtrl+C to cancel, Ctrl+D to exit — know the difference
ChainingUse && for dependent steps, ; for independent steps
PipingConnect commands with `
RedirectingUse > to write, >> to append output to files
AliasesCreate shortcuts for commands you use dozens of times a day

The best way to learn these shortcuts is practice. Pick two or three new shortcuts today and force yourself to use them. Within a week they will be second nature.