Linux Commands Every Developer Should Know
Stop Googling the same commands every day. Bookmark this.
File Operations
# Find files by name
find . -name "*.js" -type f
# Find files modified in last 7 days
find . -mtime -7 -type f
# Find large files (>100MB)
find . -size +100M -ls
# Search file contents
grep -r "TODO" .
grep -r "functionName" src/ --include="*.js"
# Replace text in files
sed -i 's/oldText/newText/g' *.js
# Copy with progress
cp -r source/ dest/
# Move/Rename
mv old_name.js new_name.js
# Delete recursively (careful!)
rm -rf node_modules/
Disk & Memory
# Disk usage summary
df -h
# Directory sizes (sorted)
du -sh * | sort -hr
# Top 10 largest files
du -ah . | sort -hr | head -10
# Free memory
free -h
# What's using disk space?
ncdu / # Interactive disk usage explorer (install first)
# Clean up
sudo apt autoremove # Remove unused packages
docker system prune -a # Clean Docker unused data
npm cache clean --force # Clear npm cache
Process Management
# Running processes
ps aux | grep node
# Real-time process monitor
htop # Better top (install: sudo apt install htop)
# Kill process
kill PID
kill -9 PID # Force kill (use as last resort)
# Kill by name
pkill -f "node server"
# Port in use?
lsof -i :3000
ss -tlnp | grep :3000
# Background process
node server.js &
# Or use nohup for persistent:
nohup node server.js &
disown # Detach from terminal
Network
# Test connectivity
ping google.com
# DNS lookup
nslookup example.com
dig example.com # More detailed
# HTTP request (no curl? use this)
wget -qO- https://example.com
# With headers
curl -I https://example.com # Headers only
curl -v https://example.com # Verbose
# POST request
curl -X POST https://api.example.com/data \
-H "Content-Type: application/json" \
-d '{"key": "value"}'
# Download file
curl -o filename.zip https://example.com/file.zip
# Port scanning (basic)
nmap localhost # Install: sudo apt install nmap
Text Processing
# View file contents
cat file.txt
less file.txt # Paginated (q to quit)
head -n 20 file.txt # First 20 lines
tail -f logfile.txt # Follow live updates
# Count lines/words/chars
wc -l file.txt # Lines only
wc -w file.txt # Words
# Sort
sort file.txt # Alphabetical
sort -nr numbers.txt # Numerical reverse
sort -k2 -t',' file.csv # By column 2
# Unique values
sort file.txt | uniq # Deduplicate
sort file.txt | uniq -c # Count occurrences
sort file.txt | uniq -c | sort -rn | head # Top occurrences
# Column extraction
awk -F',' '{print $1, $3}' data.csv # Columns 1 and 3
cut -d',' -f1-3 data.csv # Columns 1-3
Permissions
# Current permissions
ls -la
# Change permissions
chmod 755 script.sh # rwxr-xr-x
chmod +x script.sh # Make executable
chmod -R 644 public/ # Recursive (files readable)
# Change owner
chown user:group file
chown -R www-data:www-data public/
# Check current user
whoami
id # Groups too
# Switch user
su - username
sudo -u postgres psql # Run as another user
SSH & Remote
# Connect
ssh user@hostname
# With custom port
ssh -p 2222 user@hostname
# Copy files to remote
scp file.txt user@host:/path/to/dest/
scp -r folder/ user@host:/path/to/dest/
# Copy from remote
scp user@host:/path/file.txt ./
# Key-based auth (no password!)
ssh-keygen -t ed25519 # Generate key
ssh-copy-id user@host # Copy key to server
# Config file (~/.ssh/config)
Host myserver
HostName 192.168.1.100
User ubuntu
IdentityFile ~/.ssh/id_ed25519
# Now just: ssh myserver
Git Quick Reference
git status # What changed?
git diff # What exactly changed?
git log --oneline -10 # Recent commits
git add -A && git commit -m "msg" # Stage all + commit
git push origin main # Push to remote
git pull origin main # Pull latest
git stash # Save work temporarily
git stash pop # Restore stashed work
System Info
# OS info
uname -a
cat /etc/os-release
# CPU info
nproc # Number of cores
lscpu # Detailed CPU info
# Uptime
uptime
# Environment variables
env | grep NODE # Filter by keyword
echo $PATH # Just PATH
export PATH="$PATH:/new/path" # Add to PATH
One-Liners That Save Time
# Kill all Node processes
pkill -f node
# Find and replace in all JS files recursively
find . -name "*.js" -exec sed -i 's/old/new/g' {} +
# Watch a command run repeatedly (every 2s)
watch -n 2 'curl -s http://localhost:3000/health'
# Create directory structure
mkdir -p project/{src,test,dist,docs}
# Batch rename files
for f in *.txt; do mv "$f "${f%.txt}.md"; done
# Download entire website
wget --mirror --convert-links --page-requisites https://example.com
# Random password
openssl rand -base64 16
# Base64 encode/decode
echo "text" | base64
echo "dGV4dA==" | base64 -d
# JSON pretty print
echo '{"a":1}' | python3 -m json.tool
curl -s api/data | python3 -m json.tool
What's your most-used Linux command? Share it!
Follow @armorbreak for more developer content.
Top comments (0)