Linux Command Line: The Developer's Survival Guide (2026)
The terminal is your superpower. These are the commands you'll use every day as a developer — explained with practical examples.
File System Navigation
# === Essential Navigation ===
pwd # Print working directory (where am I?)
ls # List files (basic)
ls -la # List all (including hidden) + details
ls -lt # Sort by modification time (newest first)
ls -lhS # Human-readable sizes, sorted by size
cd ~/projects # Go to projects directory
cd - # Go to previous directory (toggle!)
cd .. # Go up one directory
# === Finding Things ===
find . -name "*.js" # Find JS files in current directory + subdirs
find . -name "*.js" -mtime -7 # Modified in last 7 days
find . -type d -name "node_modules" # Find node_modules directories
find . -size +100M # Files larger than 100MB
find . -empty # Empty files or directories
# Fast file search (uses index, much faster than find):
locate config.json # Instantly finds any file matching name
sudo updatedb # Update the locate database
# Search INSIDE files:
grep -r "function" src/ # Recursive search for text in files
grep -ri "error" *.log # Case-insensitive search in log files
grep -rn "TODO" src/ # Show line numbers too!
grep -rn "import" --include="*.ts" src/ # Only TypeScript files
# Modern alternative (faster, better output):
rg "function" src/ # ripgrep — faster than grep, respects .gitignore
rg -i "todo" src/ -S # Smart case, show surrounding context
# Find which process is using a port:
lsof -i :3000 # What's running on port 3000?
ss -tlnp | grep :3000 # Alternative (works without lsof)
# Find a command:
which node # Where is node installed?
type cd # Is it built-in, alias, or binary?
history | grep git # Search your command history
File Operations
# === Viewing Files ===
cat file.txt # Print entire file
less file.txt # Paginated viewer (q to quit, / to search)
head -n 20 file.txt # First 20 lines
tail -n 50 file.txt # Last 50 lines
tail -f app.log # Follow file (live updates! Great for logs)
tail -f -n 100 app.log # Follow from last 100 lines
# === Creating & Editing ===
touch newfile.js # Create empty file (or update timestamp)
mkdir new-project # Create directory
mkdir -p src/components/utils # Create nested directories (no error if exists!)
# Quick editing without an editor:
echo "console.log('hello')" > test.js # Write (overwrites!)
echo "more code" >> test.js # Append!
# sed — stream editor for quick replacements:
sed -i 's/old-text/new-text/g' file.txt # Replace all occurrences in place
sed -n '10,30p' file.txt # Print lines 10-30
sed -i '42d' file.txt # Delete line 42
# === Copying, Moving, Renaming ===
cp file.txt backup.txt # Copy file
cp -r project/ project-backup/ # Copy directory recursively
mv old-name.txt new-name.txt # Rename (or move)
mv file.txt ../other-dir/ # Move to different directory
# === Deleting (⚠️ Be careful!) ===
rm unwanted.txt # Delete file
rm -rf node_modules/ # Delete directory and contents (force recursive)
# ⚠️ rm -rf / = deletes everything. Always double-check before pressing Enter!
# Safer alternatives:
trash file.txt # Moves to trash (recoverable!) — install trash-cli
rm -i file.txt # Interactive: asks before each deletion
Process Management
# === Understanding Processes ===
ps aux # List ALL processes
ps aux | grep node # Find Node processes
top # Live process viewer (like Task Manager)
htop # Better top (colorful, interactive) — install htop
# === Controlling Processes ===
kill 12345 # Gracefully stop process (PID 12345)
kill -9 12345 # Force kill (use when kill doesn't work)
# ⚠️ -9 (SIGKILL) doesn't allow cleanup. Try regular kill first.
pkill -f "node server" # Kill by process name pattern
killall node # Kill all processes named 'node'
# Background & foreground:
long-running-command & # Run in background
jobs # List background jobs
fg %1 # Bring job 1 to foreground
Ctrl+Z # Suspend current job (pause it)
bg # Resume suspended job in background
# nohup — keep process running after you disconnect:
nohup npm start > output.log 2>&1 &
# Process keeps running even after you close the terminal!
# tmux/screen — persistent terminal sessions:
tmux new -s mysession # Start named session
tmux attach -t mysession # Reconnect to session later
# Inside tmux: Ctrl+B then D = detach (session keeps running)
# Inside tmux: Ctrl+B then c = create new window
# Inside tmux: Ctrl+B then % = split pane vertically
Disk & Memory
# === Disk Space ===
df -h # Disk usage overview (human-readable)
du -sh * # Size of items in current directory
du -sh node_modules/ # Size of specific directory
du -h --max-depth=2 . | sort -rh | head -20 # Top 20 largest directories
# Find large files:
find . -type f -size +50M -exec ls -lh {} \; # Files over 50MB
find . -type f -size +500M -delete # Delete huge files (careful!)
# Clean up disk space:
npm cache clean --force # Free npm cache (can save GBs!)
docker system prune -a # Remove unused Docker images/containers
rm -rf ~/.cache/* # Clear user caches (generally safe)
journalctl --vacuum-size=200M # Limit systemd journal size
# === Memory ===
free -h # RAM usage overview
vmstat 1 # Live memory/CPU stats (every 1 second)
# Find memory-hungry processes:
ps aux --sort=-%mem | head -10 # Top 10 memory consumers
# Check memory usage of specific process:
pidstat -r -p 12345 1 # Real-time memory stats for PID
Networking
# === Network Diagnostics ===
ping google.com # Basic connectivity test
ping -c 4 google.com # Send exactly 4 packets then stop
curl -I https://example.com # HTTP headers only (check status, redirects)
curl -v https://example.com # Verbose (see full request/response)
curl -X POST https://api.example.com/data \
-H "Content-Type: application/json" \
-d '{"key": "value"}' # POST request with JSON body
curl -o output.zip https://... # Download file
curl -L https://bit.ly/link # Follow redirects
wget https://example.com/file.zip # Alternative download tool
# DNS lookup:
nslookup example.com # DNS query
dig example.com # More detailed DNS info
host example.com # Quick DNS check
# Port scanning (is something listening?):
nc -zv localhost 3000 # Test if port 3000 is open
netstat -tlnp # All listening ports + their processes
ss -tlnp # Same thing, modern version
# === SSH ===
ssh user@server.com # Connect to remote server
ssh -p 2222 user@server.com # Custom port
ssh -i ~/.ssh/my_key.pem user@server.com # Specific key
# Copy files over SSH:
scp file.txt user@server:/path/to/ # Upload
scp user@server:/path/to/file.txt ./ # Download
scp -r folder/ user@server:/path/ # Upload directory
# SSH key setup (passwordless login):
ssh-keygen -t ed25519 -C "my@email.com" # Generate key pair
ssh-copy-id user@server.com # Copy public key to server
# Now you can ssh without password!
Text Processing Pipeline
# The Unix philosophy: small tools that do one thing well,
# connected by pipes (|) to form powerful pipelines.
# Example: Analyze web server logs
cat access.log \
| grep '" 500 ' \ # Only server errors
| awk '{print $7}' \ # Extract URL path
| sort \ # Sort alphabetically
| uniq -c \ # Count duplicates
| sort -rn \ # Sort by count descending
| head -20 # Top 20 error URLs
# Example: Find largest JSON files
find . -name "*.json" -exec du -b {} + \
| sort -rn \
| head -5 \
| awk '{print $1/1024/1024 "MB", $2}'
# Example: Count code lines by type
find src/ -type f \( -name "*.js" -o -name "*.ts" \) \
| xargs wc -l \
| sort -n \
| tail -1
# Useful text tools:
wc -l file.txt # Line count
wc -w file.txt # Word count
sort file.txt # Sort lines
uniq file.txt # Remove adjacent duplicates
uniq -c file.txt # Count occurrences
cut -d',' -f2 file.csv # Extract field 2 (comma-separated)
tr 'A-Z' 'a-z' < file.txt # Convert to lowercase
tee output.txt # Write to file AND stdout simultaneously
xargs -I{} echo "Processing: {}" # Run command for each input line
Developer-Specific Essentials
# === Git Quick Reference ===
git status # What changed?
git diff # What exactly changed?
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 stash && git pull && git stash pop # Save changes, update, restore
# === Node.js / npm ===
node -v && npm -v # Check versions
npm install # Install dependencies
npm install -D eslint # Install dev dependency
npm outdated # Check for updates
npm audit # Security vulnerabilities
npx create-react-app my-app # Run packages without installing
npm run build # Run scripts from package.json
# === Docker ===
docker ps # Running containers
docker ps -a # All containers (including stopped)
docker images # Local images
docker logs container_name # Container logs (-f to follow)
docker exec -it container_name sh # Shell into running container
docker compose up -d # Start services in background
docker compose down # Stop and remove containers
# === Environment Variables ===
env # Show all environment variables
echo $PATH # Show PATH variable
export API_KEY="secret123" # Set variable for current session
source .env # Load environment from file (in Node: use dotenv)
printenv | grep NODE # Filter env vars
# === Permissions ===
chmod +x script.sh # Make executable
chmod 644 file.txt # Read/write owner, read-only others
chown user:group file.txt # Change owner
sudo !! # Run previous command with sudo (lifesaver!)
Which Linux command do you wish you'd learned earlier? What's your go-to terminal trick?
Follow @armorbreak for more practical developer guides.
Top comments (0)