Essential Linux Commands Cheatsheet
Last updated: January 2026
Reading time: 20 min
Difficulty: All Levels
What You'll Learn
Complete reference of essential Linux terminal commands with practical examples. From basic file management to advanced system administration. Works on Ubuntu, Debian, Fedora, Arch, and all major distributions.
Table of Contents
File Management Commands
ls - List Directory Contents
List files
# Basic listing
ls
# Detailed listing with permissions, owner, size
ls -l
# Show hidden files (starting with .)
ls -a
# Human-readable file sizes
ls -lh
# Sort by modification time (newest first)
ls -lt
# Recursive listing
ls -R
# Common combination
ls -lah
Output explained (ls -l):
-rw-r--r-- 1 user group 1234 Jan 28 10:30 file.txt
│││││││││ │ │ │ │ │ └─ filename
│││││││││ │ │ │ │ └─ modification date/time
│││││││││ │ │ │ └─ file size (bytes)
│││││││││ │ │ └─ group owner
│││││││││ │ └─ user owner
│││││││││ └─ number of hard links
└─────────── permissions
cp - Copy Files and Directories
Copy commands
# Copy file
cp source.txt destination.txt
# Copy to directory
cp file.txt /path/to/directory/
# Copy directory recursively
cp -r source_dir/ destination_dir/
# Copy with verbose output
cp -v file.txt /backup/
# Preserve permissions, timestamps
cp -p file.txt /backup/
# Interactive (ask before overwrite)
cp -i file.txt existing_file.txt
# Copy multiple files to directory
cp file1.txt file2.txt file3.txt /destination/
mv - Move/Rename Files
Move and rename
# Rename file
mv oldname.txt newname.txt
# Move file to directory
mv file.txt /path/to/directory/
# Move multiple files
mv file1.txt file2.txt /destination/
# Move directory
mv old_dir/ new_location/
# Interactive mode (ask before overwrite)
mv -i source.txt destination.txt
rm - Remove Files and Directories
⚠️ Warning
rm is destructive and permanent. There is no "undo" or "recycle bin" in the terminal. Always double-check before running rm commands.
Remove files (use with caution!)
# Remove file
rm file.txt
# Remove multiple files
rm file1.txt file2.txt file3.txt
# Remove directory and contents (recursive)
rm -r directory/
# Force remove (no confirmation)
rm -f file.txt
# Interactive (ask for each file)
rm -i file.txt
# Remove directory recursively with verbose output
rm -rv old_directory/
# DANGEROUS: Never run this without absolute certainty
# rm -rf / # Destroys entire system!
mkdir - Create Directories
Make directories
# Create directory
mkdir new_directory
# Create multiple directories
mkdir dir1 dir2 dir3
# Create nested directories (parents)
mkdir -p parent/child/grandchild
# Create with specific permissions
mkdir -m 755 public_directory
touch - Create Empty Files / Update Timestamps
Create files
# Create empty file
touch newfile.txt
# Create multiple files
touch file1.txt file2.txt file3.txt
# Update modification time of existing file
touch existing_file.txt
Navigation Commands
cd - Change Directory
Navigate filesystem
# Go to home directory
cd
cd ~
# Go to specific directory
cd /path/to/directory
# Go up one level
cd ..
# Go up two levels
cd ../..
# Go to previous directory
cd -
# Go to root directory
cd /
pwd - Print Working Directory
Show current location
# Show current directory
pwd
# Example output: /home/username/Documents
find - Search for Files
Find files and directories
# Find file by name
find /path/to/search -name "filename.txt"
# Case-insensitive search
find /path -iname "*.jpg"
# Find directories only
find /path -type d -name "folder*"
# Find files modified in last 7 days
find /path -type f -mtime -7
# Find files larger than 100MB
find /path -type f -size +100M
# Find and delete
find /path -name "*.tmp" -delete
# Find with permissions
find /path -type f -perm 644
Text Processing Commands
cat - Display File Contents
View files
# Display file
cat file.txt
# Display multiple files
cat file1.txt file2.txt
# Number all lines
cat -n file.txt
# Concatenate files into new file
cat file1.txt file2.txt > combined.txt
# Append to file
cat file1.txt >> existing.txt
grep - Search Text Patterns
Search within files
# Search for pattern in file
grep "search_term" file.txt
# Case-insensitive search
grep -i "search_term" file.txt
# Search recursively in directory
grep -r "search_term" /path/to/dir/
# Show line numbers
grep -n "search_term" file.txt
# Show only filenames with matches
grep -l "search_term" *.txt
# Invert match (show lines NOT containing pattern)
grep -v "exclude_this" file.txt
# Count matches
grep -c "search_term" file.txt
# Search with regular expressions
grep -E "pattern|alternative" file.txt
head - Display Beginning of File
Show first lines
# Show first 10 lines (default)
head file.txt
# Show first 20 lines
head -n 20 file.txt
# Show first 5 lines
head -5 file.txt
tail - Display End of File
Show last lines
# Show last 10 lines (default)
tail file.txt
# Show last 20 lines
tail -n 20 file.txt
# Follow file in real-time (useful for logs)
tail -f /var/log/syslog
# Follow with line numbers
tail -fn 50 logfile.txt
wc - Word Count
Count lines, words, characters
# Count lines, words, bytes
wc file.txt
# Count lines only
wc -l file.txt
# Count words only
wc -w file.txt
# Count characters only
wc -m file.txt
File Permissions Commands
chmod - Change File Permissions
Permission Numbers
- 4 = read (r)
- 2 = write (w)
- 1 = execute (x)
- 7 = rwx (4+2+1)
- 6 = rw- (4+2)
- 5 = r-x (4+1)
- 0 = --- (no permissions)
Modify permissions
# Make file executable
chmod +x script.sh
# Remove execute permission
chmod -x file
# Set specific permissions (rwxr-xr-x)
chmod 755 script.sh
# Owner read/write, group read, others none
chmod 640 private_file.txt
# Recursive permission change
chmod -R 755 directory/
# Symbolic notation
chmod u+x file # Add execute for user (owner)
chmod g-w file # Remove write for group
chmod o+r file # Add read for others
chmod a+x file # Add execute for all
chown - Change File Owner
Change ownership
# Change owner
sudo chown username file.txt
# Change owner and group
sudo chown username:groupname file.txt
# Recursive ownership change
sudo chown -R username:groupname directory/
# Change group only
sudo chown :groupname file.txt
Process Management Commands
ps - Show Running Processes
List processes
# Show processes for current user
ps
# Show all processes
ps aux
# Show process tree
ps auxf
# Show processes for specific user
ps -u username
# Sort by CPU usage
ps aux --sort=-%cpu | head
# Sort by memory usage
ps aux --sort=-%mem | head
top / htop - Monitor System Resources
Real-time monitoring
# Interactive process monitor
top
# Better alternative (if installed)
htop
# Sort by CPU (in top): press Shift+P
# Sort by memory (in top): press Shift+M
# Kill process (in top): press k, then enter PID
# Quit: press q
kill - Terminate Processes
Stop processes
# Graceful termination (SIGTERM)
kill PID
# Force kill (SIGKILL)
kill -9 PID
# Kill by process name
killall process_name
# Kill all processes of a user
sudo pkill -u username
System Information Commands
uname - System Information
Show system details
# Show all information
uname -a
# Show kernel name
uname -s
# Show kernel version
uname -r
# Show machine hardware name
uname -m
df - Disk Space Usage
Check disk space
# Show disk usage
df
# Human-readable format
df -h
# Show specific filesystem
df -h /home
# Show inodes
df -i
du - Directory Size
Check directory sizes
# Show directory size
du -sh directory/
# Show sizes of all subdirectories
du -h directory/
# Show top 10 largest directories
du -h / | sort -rh | head -10
# Show size of current directory
du -sh .
free - Memory Usage
Check RAM and swap
# Show memory usage
free
# Human-readable format
free -h
# Show in megabytes
free -m
# Continuous monitoring (updates every 2 seconds)
free -h -s 2
Networking Commands
ping - Test Network Connectivity
Test connection
# Ping host
ping google.com
# Ping specific number of times
ping -c 4 google.com
# Ping with specific interval
ping -i 2 google.com
ip - Network Configuration
Show network info
# Show all network interfaces
ip addr show
# Show routing table
ip route show
# Show specific interface
ip addr show eth0
# Brief output
ip -brief addr
wget - Download Files
Download from internet
# Download file
wget https://example.com/file.zip
# Download with custom name
wget -O custom_name.zip https://example.com/file.zip
# Continue interrupted download
wget -c https://example.com/large_file.iso
# Download in background
wget -b https://example.com/file.zip
curl - Transfer Data
HTTP requests and downloads
# Download file
curl -O https://example.com/file.zip
# Save with custom name
curl -o custom_name.zip https://example.com/file.zip
# Follow redirects
curl -L https://example.com
# Show HTTP headers
curl -I https://example.com
# POST request with data
curl -X POST -d "param=value" https://api.example.com
Package Management Commands
Ubuntu / Debian (apt)
APT commands
# Update package lists
sudo apt update
# Upgrade all packages
sudo apt upgrade
# Full upgrade (handles dependencies better)
sudo apt full-upgrade
# Install package
sudo apt install package-name
# Remove package
sudo apt remove package-name
# Remove package and config files
sudo apt purge package-name
# Search for packages
apt search keyword
# Show package information
apt show package-name
# Remove unnecessary packages
sudo apt autoremove
# Clean package cache
sudo apt clean
Fedora (dnf)
DNF commands
# Update all packages
sudo dnf upgrade
# Install package
sudo dnf install package-name
# Remove package
sudo dnf remove package-name
# Search packages
dnf search keyword
# Show package info
dnf info package-name
# List installed packages
dnf list installed
Arch Linux (pacman)
Pacman commands
# Update system
sudo pacman -Syu
# Install package
sudo pacman -S package-name
# Remove package
sudo pacman -R package-name
# Remove package and dependencies
sudo pacman -Rs package-name
# Search packages
pacman -Ss keyword
# Show package info
pacman -Si package-name
# List installed packages
pacman -Q
✓ Quick Reference
Print this cheatsheet: Save this page as PDF (Ctrl+P) for offline reference
Practice safely: Test commands in a non-critical directory or VM
Man pages: Use man command-name for full documentation
Help flag: Most commands support --help for quick reference
Command Chaining & Shortcuts
Operators
Chain commands
# Run commands sequentially
command1 ; command2
# Run second command only if first succeeds
command1 && command2
# Run second command only if first fails
command1 || command2
# Pipe output to another command
command1 | command2
# Redirect output to file (overwrite)
command > file.txt
# Redirect output to file (append)
command >> file.txt
# Redirect stderr to stdout
command 2>&1
# Redirect both stdout and stderr to file
command &> file.txt
Keyboard Shortcuts
- Ctrl+C: Kill running process
- Ctrl+Z: Suspend process (resume with
fg) - Ctrl+D: Exit current shell / EOF
- Ctrl+L: Clear screen (same as
clear) - Ctrl+A: Move to beginning of line
- Ctrl+E: Move to end of line
- Ctrl+U: Delete from cursor to beginning
- Ctrl+K: Delete from cursor to end
- Ctrl+R: Search command history
- Tab: Auto-complete file/command names
- ↑/↓: Navigate command history
Works On
- Ubuntu (all versions)
- Debian (all versions)
- Fedora (all versions)
- Arch Linux
- Linux Mint
- Any Linux distribution with bash shell