Linux Commands Every Developer Should Know: The 2026 Cheat Sheet
Whether you're deploying to a Linux server, using WSL on Windows, or developing on macOS, the command line is your home. Knowing Linux commands isn't optional for developers — it's survival.
This cheat sheet covers the commands you'll actually use, with real examples. No fluff, no "here's what ls does" filler — just practical, look-it-up reference.
File & Directory Management
Navigation
# Where am I?
pwd # /home/user/projects
# List files (detailed)
ls -la # All files including hidden, with details
ls -lah # Same, but file sizes in human-readable format
ls -lt # Sorted by modification time (newest first)
ls -lS # Sorted by size (largest first)
# Change directory
cd /var/log # Absolute path
cd ../.. # Up two directories
cd - # Back to previous directory
cd ~ # Home directory
Creating and Deleting
# Create directories
mkdir new-folder
mkdir -p path/to/nested/dirs # Create parent directories as needed
# Create files
touch index.html
touch file1.txt file2.txt file3.txt # Multiple at once
# Copy
cp file.txt backup.txt
cp -r src/ dest/ # Copy directory recursively
# Move/Rename
mv old-name.txt new-name.txt
mv file.txt /other/dir/ # Move file to another directory
# Delete
rm file.txt # Delete file
rm -r folder/ # Delete directory recursively
rm -rf folder/ # Force delete (careful! no confirmation)
Finding Files
# Find by name
find . -name "*.log" # All .log files in current dir
find /var/log -name "*.log" -mtime +7 # Log files older than 7 days
find . -type f -size +100M # Files larger than 100MB
find . -type d -empty # Empty directories
# Find by content (modern alternative: ripgrep)
grep -r "TODO" . # Search recursively for "TODO"
grep -ri "error" /var/log/ # Case-insensitive search in logs
grep -rl "pattern" . # Only show filenames that match
# ripgrep (much faster, install: apt install ripgrep)
rg "TODO" # Search current directory
rg -t py "import" # Only in Python files
rg -l "pattern" # Only filenames
File Permissions
# View permissions
ls -l file.txt
# -rw-r--r-- 1 user group 1024 Jul 5 file.txt
# ^^^ ^^^ ^^^
# owner group others
# Change permissions (symbolic)
chmod +x script.sh # Add execute permission
chmod -w file.txt # Remove write permission
chmod u+x file.txt # Add execute for owner only
chmod g+rw file.txt # Add read/write for group
chmod 755 script.sh # rwxr-xr-x (owner: all, others: read+execute)
chmod 644 file.txt # rw-r--r-- (owner: read+write, others: read)
# Change ownership
sudo chown user:group file.txt
sudo chown -R user:group folder/ # Recursive
Permission numbers cheat sheet:
| Number | Permission | |--------|-----------| | 7 | rwx (read, write, execute) | | 6 | rw- (read, write) | | 5 | r-x (read, execute) | | 4 | r-- (read only) |
Common combos: 755 (scripts/dirs), 644 (files), 600 (secrets), 777 (avoid!).
Text Processing
View File Content
# View entire file
cat file.txt
# View with line numbers
cat -n file.txt
# View large files (paginated)
less file.txt # 'q' to quit, '/' to search, 'n' for next match
# View beginning/end
head -n 20 file.txt # First 20 lines
tail -n 20 file.txt # Last 20 lines
tail -f /var/log/syslog # Follow in real-time (incredibly useful)
Text Manipulation
# Extract columns
cut -d',' -f1,3 data.csv # Fields 1 and 3 from CSV
awk '{print $2}' file.txt # Second column (space-separated)
awk -F',' '{print $1}' file.csv # First column from CSV
# Sort and filter
sort file.txt # Alphabetical sort
sort -n file.txt # Numerical sort
sort -rn file.txt # Reverse numerical sort (top N)
sort | uniq -c | sort -rn # Count unique lines, sorted by frequency
# Search and replace
sed 's/old/new/g' file.txt # Replace "old" with "new"
sed -i 's/localhost/127.0.0.1/g' config.conf # In-place edit
sed '/^#/d' file.txt # Remove comment lines
sed '/^$/d' file.txt # Remove empty lines
# Join files
paste file1.txt file2.txt # Side by side
comm -12 file1.txt file2.txt # Common lines
JSON Processing (jq)
jq is essential for working with API responses:
# Install
sudo apt install jq
# Pretty-print JSON
echo '{"name":"John","age":30}' | jq .
# Extract a field
echo '{"name":"John"}' | jq '.name'
# API response processing
curl -s https://api.github.com/users/torvalds | jq '.public_repos'
# Array processing
echo '[{"name":"A"},{"name":"B"}]' | jq '.[].name'
# "A"
# "B"
# Filter array
echo '[{"price":10},{"price":50}]' | jq '.[] | select(.price > 20)'
Process Management
Viewing Processes
# List all processes
ps aux # All processes, detailed
ps aux | grep nginx # Find nginx processes
ps -ef | grep python # Alternative format
# Interactive process viewer
top # Built-in
htop # Better (install: apt install htop)
# Process tree
pstree -p # Tree view with PIDs
pstree -p | grep nginx # Find specific process tree
Managing Processes
# Start a process in background
command &
# Keep running after logout
nohup command &
disown # Detach from shell
# Run in a terminal multiplexer (better than nohup)
tmux new -s work # Start named session
tmux attach -t work # Reconnect
# Ctrl+B, D # Detach (process keeps running)
# Kill processes
kill 1234 # Send SIGTERM (graceful)
kill -9 1234 # Send SIGKILL (force kill)
killall nginx # Kill all processes named "nginx"
pkill -f "python script.py" # Kill by command line match
Resource Monitoring
# Disk usage
df -h # Filesystem disk space
du -sh /var/log # Size of specific directory
du -sh * # Size of each item in current dir
ncdu / # Interactive disk usage (install: apt install ncdu)
# Memory usage
free -h # Memory summary
cat /proc/meminfo # Detailed memory info
# CPU info
nproc # Number of CPU cores
lscpu # CPU details
uptime # Load averages
Networking
Connectivity
# Check if a host is reachable
ping google.com
ping -c 4 google.com # 4 packets then stop
# DNS lookup
dig google.com # Detailed DNS query
dig +short google.com # Just the IP
nslookup google.com # Alternative DNS lookup
# Trace network path
traceroute google.com # Network path to host
# Download files
curl -O https://example.com/file.zip
wget https://example.com/file.zip
wget -c https://example.com/large-file.zip # Resume download
# Test local ports
curl -I http://localhost:3000 # HTTP headers only
curl -s http://localhost:3000/api/health # Silent, body only
Ports and Connections
# What's listening on which ports
sudo ss -tlnp # TCP listening ports with process names
sudo ss -ulnp # UDP listening ports
sudo netstat -tlnp # Alternative (if ss unavailable)
# Find what's using a specific port
sudo lsof -i :80 # What's on port 80
sudo lsof -i :3000-3010 # Port range
# Active connections
ss -tn # All TCP connections
ss -tn state established # Only established connections
Firewall (UFW)
# Allow SSH
sudo ufw allow 22/tcp
# Allow HTTP/HTTPS
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# Allow specific app
sudo ufw allow "Nginx Full"
# Enable firewall
sudo ufw enable
sudo ufw status verbose
SSH
# Basic SSH
ssh user@server.com
ssh -p 2222 user@server.com # Custom port
# SSH key generation
ssh-keygen -t ed25519 -C "your_email@example.com"
# Key saved to ~/.ssh/id_ed25519
# Copy key to server
ssh-copy-id user@server.com
# SSH config (create ~/.ssh/config)
Host myserver
HostName 192.168.1.100
User ubuntu
Port 2222
IdentityFile ~/.ssh/my_key
# Then just:
ssh myserver
# Port forwarding
ssh -L 3000:localhost:3000 user@server # Local port forwarding
ssh -R 8080:localhost:80 user@server # Remote port forwarding
File Transfer
# Secure copy (scp)
scp file.txt user@server:/path/to/dest/
scp -r folder/ user@server:/path/to/dest/ # Recursive
scp user@server:/var/log/syslog ./ # From server to local
# rsync (better than scp for large transfers)
rsync -avz src/ user@server:/dest/ # Compressed, verbose
rsync -avz --delete src/ user@server:/dest/ # Delete files on dest that don't exist on src
rsync -avz --progress large-file.zip user@server:/dest/ # Show progress
# Download from web
curl -O https://example.com/file.zip
wget -qO- https://example.com/script.sh | bash # Pipe to bash (be careful!)
System Information
# OS info
uname -a # Kernel info
lsb_release -a # Ubuntu/Debian version
cat /etc/os-release # Alternative
# Hardware info
lscpu # CPU details
lsblk # Block devices (disks)
lspci # PCI devices
lsusb # USB devices
# System info
uptime # How long running, load average
whoami # Current user
id # User ID and groups
hostname # Machine name
ip addr # IP addresses
Package Management
Ubuntu/Debian
sudo apt update && sudo apt upgrade -y # Update everything
sudo apt install nginx # Install package
sudo apt remove nginx # Remove package
sudo apt autoremove # Remove unused dependencies
apt search keyword # Search packages
apt show nginx # Package info
CentOS/RHEL/Fedora
sudo dnf install nginx
sudo dnf update
sudo dnf remove nginx
dnf search keyword
Universal (Snap, Flatpak)
# Snap
sudo snap install code --classic
# Flatpak
flatpak install flathub com.visualstudio.code
Git Quick Commands
git status # Check status
git add -A # Stage everything
git commit -m "message" # Commit
git push # Push
git pull # Pull
git log --oneline -10 # Last 10 commits
git diff # Unstaged changes
git diff --staged # Staged changes
Shell Tricks That Save Time
Command History
!! # Repeat last command
sudo !! # Repeat last command as root (very useful)
!$ # Last argument of previous command
history | grep nginx # Search command history
Ctrl+R # Reverse search (interactive)
Redirections and Pipes
# Redirect output
command > file.txt # Overwrite
command >> file.txt # Append
command 2> error.log # Redirect stderr only
command > /dev/null 2>&1 # Discard all output
# Pipes
command1 | command2 # Pipe output to input
ls | grep ".log" # List only .log files
cat urls.txt | xargs curl # Run curl for each URL
Loops (One-Liners)
# Process multiple files
for f in *.jpg; do convert "$f" "${f%.jpg}_resized.jpg"; done
# Ping multiple hosts
for host in google.com github.com; do ping -c 1 $host; done
# Batch rename
for f in *.txt; do mv "$f" "${f%.txt}.md"; done
Productivity Tools Worth Installing
# Modern alternatives to classic tools
sudo apt install bat # cat with syntax highlighting (alias: batcat)
sudo apt install exa # ls replacement with colors
sudo apt install ripgrep # grep replacement (much faster)
sudo apt install fd-find # find replacement (simpler syntax)
sudo apt install btop # top/htop replacement (beautiful)
sudo apt install ncdu # Interactive disk usage analyzer
# Development tools
sudo apt install jq # JSON processor
sudo apt install tmux # Terminal multiplexer
sudo apt install make # Build automation
sudo apt install git # Version control
Conclusion
You don't need to memorize all of these. Bookmark this page and reference it when needed. Over time, the commands you use most will stick.
The 10 commands you'll use daily:
cd— Navigatels— List filesgrep/rg— Searchtail -f— Watch logsps/htop— Check processesssh— Connect to serverssudo apt install— Install stuffchmod— Fix permissionscurl— Test APIsgit— Version control
Master these, and you'll be comfortable on any Linux system.