Linux Command Line: The 50 Commands You Actually Need (2026)
You don't need to memorize 10,000 commands. These 50 cover 95% of what you'll do daily as a developer.
File & Directory Operations
# Navigation
pwd # Print working directory (where am I?)
cd ~/projects # Change directory (~ = home)
cd - # Go to previous directory
ls -lah # List files (long, human-readable, hidden)
# Finding things
find . -name "*.js" # Find by name (recursive)
find . -type f -mtime -7 # Files modified in last 7 days
grep -r "TODO" ./src # Search file contents recursively
rg "function" ./src # Ripgrep — faster alternative to grep
# File operations
cp file.txt backup.txt # Copy
cp -r folder/ backup/ # Copy directory (recursive)
mv old.txt new.txt # Move/rename
rm file.txt # Delete (⚠️ gone forever!)
rm -rf folder/ # Delete directory and contents (⚠️!)
mkdir -p a/b/c/d # Create nested directories
touch newfile.js # Create empty file (or update timestamp)
ln -s /path/to/file link # Create symbolic link
# Viewing files
cat file.txt # Show entire file
less file.txt # Scroll through file (q to quit)
head -20 file.txt # First 20 lines
tail -f logfile.log # Last lines + follow updates live!
wc -l file.txt # Count lines
du -sh * # Disk usage per item (human-readable)
Text Processing
# Search within files
grep "error" app.log # Find lines containing "error"
grep -n "error" app.log # With line numbers
grep -C 3 "error" app.log # Show 3 lines before/after match
grep -r "import" src/ # Recursive search in directory
grep -ri "todo" src/ # Case-insensitive recursive
# Find and replace
sed 's/old/new/g' file.txt # Replace all occurrences (g = global)
sed -i.bak 's/foo/bar/g' * # In-place replace with backup
# Stream editing with awk
awk '{print $1, $3}' data.txt # Print columns 1 and 3 (space-delimited)
awk '/error/{count++} END {print count}' log.txt # Count matching lines
# Sort & unique
sort names.txt # Alphabetical sort
sort -rn numbers.txt # Reverse numeric sort
uniq sorted.txt # Remove adjacent duplicates
sort file.txt | uniq -c # Count occurrences
# Column extraction
cut -d',' -f1,3 csv.csv # Extract fields 1 and 3 (comma-separated)
column -t -s',' csv.csv # Pretty-print CSV as aligned table
Process Management
# What's running?
ps aux # All processes
top # Interactive process viewer (q to quit)
htop # Better top (colorful, scrollable)
# Find specific process
pgrep node # Find PIDs of node processes
ps aux | grep node # Alternative: filter ps output
# Kill processes
kill PID # Graceful termination (SIGTERM)
kill -9 PID # Force kill (SIGKILL) — use as last resort
pkill -f "node server" # Kill by name pattern
killall node # Kill all processes named node
# Background jobs
command & # Run in background
jobs # List background jobs
fg %1 # Bring job 1 to foreground
bg %1 # Resume suspended job in background
Ctrl+Z # Suspend current job
Ctrl+C # Interrupt current foreground job
# Resource monitoring
free -h # Memory usage (human-readable)
df -h # Disk space per filesystem
iotop # Disk I/O by process
nethogs # Network bandwidth by process
vmstat 1 # System stats every second
Networking
# Connection testing
ping google.com # Basic connectivity
curl -I https://example.com # HTTP headers only
curl -v https://api.example.com/test # Verbose request/response
wget https://example.com/file.zip # Download file
# DNS lookup
dig example.com # Full DNS info
nslookup example.com # Simple DNS query
host example.com # Quick lookup
# Port scanning (is something listening?)
netstat -tlnp # Listening TCP ports + PIDs
ss -tlnp # Modern netstat replacement
lsof -i :3000 # What's using port 3000?
# SSH essentials
ssh user@host # Connect to remote server
ssh -i key.pem user@host # Connect with specific key
scp file.txt user@host:/path/ # Copy file TO server
scp user@host:/path/file ./ # Copy file FROM server
ssh-keygen -t ed25519 # Generate SSH key pair
ssh-copy-id user@host # Copy public key to server
Permissions & Users
# Understanding permissions: rwx rwx rwx
# Owner | Group | Others
# r=4, w=2, x=1 → 7=rwx, 5=r-x, 6=rw-
ls -la # Shows permissions
chmod +x script.sh # Make executable
chmod 755 script.sh # rwxr-xr-x (owner=full, others=read+execute)
chmod 600 secret.key # rw------- (only owner can read/write)
chown user:group file.txt # Change owner and group
# Sudo (run as root)
sudo command # Run single command as root
sudo -i # Switch to root shell
sudo visudo # Edit sudoers file safely
# User management
whoami # Who am I?
id # Current user/group info
groups # Which groups am I in?
last # Recent login history
Package Management & DevOps
# apt (Debian/Ubuntu)
sudo apt update # Refresh package lists
sudo apt upgrade # Upgrade installed packages
sudo apt install nginx # Install package
apt search docker # Search for packages
apt show nginx # Package details
# Systemd services
systemctl status nginx # Service status
systemctl start nginx # Start service
systemctl stop nginx # Stop service
systemctl restart nginx # Restart
systemctl enable nginx # Start on boot
journalctl -u nginx -f # Follow service logs live
# Docker basics
docker ps # Running containers
docker ps -a # All containers (including stopped)
docker images # Available images
docker run -d -p 80:3000 --name myapp myimage:latest # Run container
docker logs -f myapp # Container logs (follow)
docker exec -it myapp bash # Enter running container
docker-compose up -d # Start all services from compose file
docker system prune -a # Clean up unused images/containers
# Git (quick reference)
git status # Working tree status
git diff # Unstaged changes
git add -A && git commit -m "msg" # Stage all + commit
git push origin main # Push to remote
git pull origin main # Pull from remote
git log --oneline -10 # Recent commits compact
git stash # Save changes temporarily
The Real Power: Chaining Commands
# Pipe (|): Output of one command = input of next
cat access.log | grep "404" | wc -l # Count 404 errors
ps aux | grep node | awk '{print $2}' | xargs kill # Kill all node procs
# Redirect output:
command > output.txt # Write to file (overwrite)
command >> output.txt # Append to file
command 2> errors.txt # Write stderr to file
command > out.txt 2>&1 # Both stdout and stderr to file
command < input.txt # Read from file instead of stdin
# Combine tools for real workflows:
# Find largest files in current directory:
du -ah | sort -rh | head -10
# Find and delete files older than 30 days:
find . -type f -mtime +30 -name "*.log" -delete
# Monitor real-time errors in logs:
tail -f /var/log/app.log | grep --line-buffered ERROR
# Batch rename files (add date prefix):
for f in *.jpg; do mv "$f" "$(date +%Y%m%d)_$f"; done
# Quick HTTP server from any directory:
python3 -m http.server 8000 # Serve current dir on port 8000
# Or: npx serve .
# Quick port check:
nc -zv localhost 3000 && echo "Port open" || echo "Port closed"
# Extract any archive (works for tar, zip, gz, etc):
extract() {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# Add this function to your ~/.bashrc!
Which command here is new to you? What's your favorite CLI trick that wasn't included?
Follow @armorbreak for more practical developer guides.
Top comments (0)