Skip to main content

Linux Shell Command Line Shortcuts Complete Guide

Published: November 6, 2016 Updated: May 25, 2026 Larry Qu 4 min read

Overview

Mastering Shell command line shortcuts can greatly improve work efficiency.

Cancelling and Interrupting Commands

Ctrl + C - Interrupt Current Command

# The most common way to cancel a command
# Press Ctrl + C sends SIGINT signal, terminating the currently executing command

# Example: while pinging an address, want to stop
ping google.com
# Press Ctrl + C to stop

Ctrl + Z - Suspend Command

# Press Ctrl + Z sends SIGTSTP signal, suspending the current command
# After suspension, it can be moved to the background

# View background tasks
jobs

# Resume in foreground
fg

# Resume in background
bg

Ctrl + D - Exit Shell

# Equivalent to typing exit
# Closes the current terminal or logs out the current user

Ctrl + \ - Force Exit

# Sends SIGQUIT signal
# Forcefully terminates current command, cannot be caught

Editing Commands

Moving the Cursor

Shortcut Function
Ctrl + A Move to beginning of line
Ctrl + E Move to end of line
Ctrl + B Move back one character
Ctrl + F Move forward one character
Alt + B Move back one word
Alt + F Move forward one word

Deleting Text

Shortcut Function
Ctrl + D Delete character at cursor
Ctrl + H Delete character before cursor (like Backspace)
Ctrl + K Delete from cursor to end of line
Ctrl + U Delete from cursor to beginning of line
Ctrl + W Delete word before cursor
Alt + D Delete word after cursor

Other Editing

Shortcut Function
Ctrl + T Swap character at cursor with previous character
Alt + T Swap word at cursor with previous word
Ctrl + Y Paste (recover) recently deleted text
Alt + . Use last argument of previous command

Command History

Searching History

Shortcut Function
Ctrl + P Previous command
Ctrl + N Next command
Ctrl + R Reverse search history
Ctrl + G Exit search mode
Ctrl + O Execute current command and show next

History Expansion

# !! - Execute previous command
!!

# !n - Execute the nth command
!123

# !-n - Execute the nth from last command
!-1

# !string - Execute the most recent command starting with string
!ping

# !$ - Use last argument of previous command
cp file.txt /backup/
cd !$

# !* - Use all arguments of previous command
mkdir newdir
cd !*

Job Control

Background Jobs

# Append & to run command in background
./script.sh &

# Ctrl + Z to suspend current job
# Then bg to continue running in background

# jobs to view background tasks
jobs

# fg to bring to foreground
fg %1

# bg to continue in background
bg %1

# kill to terminate job
kill %1

Screen Control

Shortcut Function
Ctrl + L Clear screen (equivalent to clear)
Ctrl + S Pause screen output
Ctrl + Q Resume screen output
Ctrl + P Scroll up
Ctrl + N Scroll down

Practical Tips

1. Safely Cancel Current Input

# Method 1: Ctrl + C
# Directly cancel current line, re-enter

# Method 2: Ctrl + U
# Delete entire line, re-enter

# Method 3: Ctrl + C then re-display
# Sometimes after pasting garbled text, Ctrl+C may not be enough

2. Quick Command Correction

# Spelling correction
shopt -s cdspell  # Automatically correct cd spelling errors

# Case-insensitive matching
shopt -s nocaseglob  # File name case-insensitive matching

3. Alias Setup

# Add common aliases in ~/.bashrc
alias ll='ls -la'
alias la='ls -A'
alias l='ls -CF'

# Safe delete alias (requires confirmation)
alias rm='rm -i'

# Directory navigation shortcuts
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'

4. Quick Directory Navigation

# Quickly return to previous directory
cd -

# Quickly return to home directory
cd ~
cd

# Quickly enter working directory
cd /var/log

Common Questions

Q: A command is running, can’t type new commands?

# Ctrl + C to terminate
# Ctrl + Z to suspend
# Ctrl + \ to force terminate

Q: Pasted text contains special characters?

# Ctrl + U to delete current line
# Then re-paste

Q: Want to cancel without deleting the command?

# Ctrl + Z to suspend
# Move to background
# Resume later with fg

2026 Productivity Tools

Tool Purpose
fzf Fuzzy search tool
tmux Terminal multiplexer
zsh + oh-my-zsh Enhanced Shell
starship Prompt customization

Comments

👍 Was this article helpful?