Every developer ends up on a Linux server eventually. Whether you’re debugging a Docker container, setting up a CI server, or SSHing into production at 2am because something’s on fire, these commands will save you.
Navigation and Files
ls -la # List everything with details and hidden files
pwd # Where am I right now?
cd - # Go back to the previous directory
find . -name "*.log" -mtime -7 # Find .log files modified in last 7 days
du -sh * # How much space is each folder using?
df -h # How much disk space is left?
Viewing and Searching Files
less app.log # Scroll through a large file
tail -f app.log # Watch a file in real-time (great for debugging)
tail -100 app.log # Last 100 lines
grep -r "ERROR" /var/log/ # Search for "ERROR" in all files recursively
grep -n "timeout" app.log # Show line numbers for matches
The tail -f command is probably the one I use most on servers. It streams new log entries as they happen.
Process Management
ps aux | grep node # Find running node processes
top # Real-time process monitor (press q to quit)
htop # Better version of top (install if not available)
kill -15 12345 # Gracefully stop process 12345
kill -9 12345 # Force kill (last resort)
lsof -i :8080 # What process is using port 8080?
Networking
curl -v https://api.example.com/health # Test an API endpoint with details
wget https://example.com/file.zip # Download a file
netstat -tlnp # What ports are being listened on?
ping google.com # Is the network working?
dig example.com # DNS lookup
ssh user@server # Connect to remote server
File Permissions
chmod 755 script.sh # Owner can do everything, others can read/execute
chmod +x deploy.sh # Make a script executable
chown user:group file # Change file ownership
Permission numbers: 7=rwx, 6=rw-, 5=r-x, 4=r–, 0=—. Three digits = owner, group, others.
Pipe Magic
The pipe | sends output from one command to another:
# Count how many errors in a log
grep "ERROR" app.log | wc -l
# Sort processes by memory usage
ps aux | sort -k4 -rn | head -10
# Find unique IPs hitting your server
cat access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -20
Emergency Commands
# Server out of disk space?
du -sh /* 2>/dev/null | sort -rh | head -10 # Find the biggest directories
find /var/log -name "*.log" -size +100M # Find logs over 100MB
# Running out of memory?
free -h # Check memory usage
sync && echo 3 > /proc/sys/vm/drop_caches # Clear cache (careful)
Print this page and keep it handy. These commands cover 80% of what you need on a Linux server. For the other 20%, that’s what Stack Overflow is for.
