Essential Linux Commands
The terminal is your superpower. Master these commands.
File Operations
# List files
ls -la # Detailed list with hidden files
ls -lh # Human-readable sizes
# Navigate
cd /path/to/dir
cd .. # Parent directory
cd - # Previous directory
# Create & delete
mkdir -p a/b/c # Create nested directories
touch file.txt # Create empty file
rm -rf directory # Delete recursively (careful!)
# Copy & move
cp file.txt backup.txt
cp -r dir1 dir2 # Copy directory
mv old.txt new.txt # Rename/move
Text Processing
# View files
cat file.txt # Print entire file
head -n 20 file.txt # First 20 lines
tail -f log.txt # Follow file changes
# Search
grep "pattern" file.txt
grep -r "pattern" . # Recursive search
grep -i "pattern" # Case insensitive
# Transform
sed 's/old/new/g' file.txt # Replace text
awk '{print $1}' file.txt # Print first column
sort file.txt | uniq # Sort and deduplicate
Process Management
# View processes
ps aux # All processes
top # Interactive process viewer
htop # Better process viewer
# Manage processes
kill PID # Terminate process
kill -9 PID # Force kill
pkill node # Kill by name
# Background processes
command & # Run in background
nohup command & # Persist after logout
jobs # List background jobs
fg %1 # Bring job to foreground
Networking
# HTTP requests
curl https://api.example.com
curl -X POST -d '{"key":"value"}' -H "Content-Type: application/json" url
# Network info
ifconfig # Network interfaces
netstat -tlnp # Open ports
ping google.com
traceroute google.com
# Download
wget https://example.com/file.zip
Disk & Memory
# Disk usage
df -h # Filesystem usage
du -sh * # Directory sizes
du -h --max-depth=1 # One level deep
# Memory
free -h # Memory usage
SSH & Remote
# Connect
ssh user@host
ssh -i key.pem user@host
# Copy files
scp file.txt user@host:/path
scp -r directory user@host:/path
# Tunnel
ssh -L 3000:localhost:3000 user@host
Useful Combinations
# Find large files
find . -type f -size +100M
# Count lines of code
find . -name "*.js" | xargs wc -l
# Watch command output
watch -n 1 'kubectl get pods'
# Command history
history | grep "docker"
!! # Repeat last command
!$ # Last argument
Conclusion
These commands will make you more productive. Practice them until they become muscle memory.