DEV Community

Alex Chen
Alex Chen

Posted on

30 Linux Commands Every Developer Should Know

30 Linux Commands Every Developer Should Know

These are the commands I use daily as a developer working on Linux servers.

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 -type f 2>/dev/null | head -20

# Search file contents (recursive)
grep -r "TODO" src/
grep -rn "functionName" src/    # With line numbers

# Replace text in files (in-place)
sed -i 's/oldText/newText/g' *.js

# Batch rename files
for f in *.jpg; do mv "$f" "prefix_$f"; done
Enter fullscreen mode Exit fullscreen mode

Disk & Memory

# Disk usage summary
df -h

# Directory sizes (sorted)
du -sh * | sort -hr | head -20

# Current directory total size
du -sh .

# Memory usage
free -h

# Top memory-consuming processes
ps aux --sort=-%mem | head -10

# Real-time resource monitoring
htop          # Better top
iotop         # Disk I/O monitoring
nethogs       # Network per-process usage
Enter fullscreen mode Exit fullscreen mode

Process Management

# Find process by name
pgrep -f "node"

# Kill process by name
pkill -f "node server.js"

# Kill by PID
kill 12345           # Graceful (SIGTERM)
kill -9 12345        # Force kill (SIGKILL)

# Process details
ps aux | grep node

# Background & foreground
node server.js &     # Run in background
jobs                  # List background jobs
fg %1                 # Bring job 1 to foreground
bg %1                 # Resume suspended job in background

# NoHup (survives terminal close)
nohup node server.js &
Enter fullscreen mode Exit fullscreen mode

Networking

# Test connectivity
ping google.com

# Check port availability
ss -tlnp | grep :3000

# What's using a port?
lsof -i :3000

# Download files
curl -O https://example.com/file.zip
wget https://example.com/file.zip

# API testing with curl
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name": "test"}'

# DNS lookup
dig example.com
nslookup example.com

# Network connections
netstat -tlnp
ss -tlnp
Enter fullscreen mode Exit fullscreen mode

User & Permissions

# Who am I?
whoami
id

# Change ownership
chown user:group file.txt
chown -R user:group directory/

# Change permissions
chmod 755 script.sh
chmod +x script.sh        # Make executable
chmod -R 644 public/      # Recursive for directories

# Switch user
su - username
sudo -u postgres psql

# Add user to group
usermod -aG docker $USER
Enter fullscreen mode Exit fullscreen mode

Text Processing

# View file contents
cat file.txt
less file.txt            # Paginated (q to quit)
head -20 file.txt        # First 20 lines
tail -f logfile.log      # Follow log in real-time

# Sort lines
sort file.txt
sort -nr numbers.txt     # Numeric reverse

# Unique lines
sort file.txt | uniq
sort file.txt | uniq -c   # With counts

# Column extraction
cut -d',' -f2 data.csv    # Field 2 (comma-delimited)
awk -F',' '{print $2}' data.csv  # Same with awk

# Word/line/char count
wc -l file.txt            # Lines only
wc -w file.txt            # Words
Enter fullscreen mode Exit fullscreen mode

System Info

# OS info
uname -a
cat /etc/os-release

# CPU info
lscpu
nproc                     # Number of cores

# Uptime & load
uptime

# Systemd services
systemctl status nginx
systemctl restart nginx
journalctl -u nginx -f    # Follow logs

# Cron jobs
crontab -e                # Edit cron
crontab -l                # List cron jobs
Enter fullscreen mode Exit fullscreen mode

SSH Essentials

# Connect
ssh user@hostname

# With specific key
ssh -i ~/.ssh/mykey.pem user@hostname

# Port forwarding (access remote port locally)
ssh -L 8080:localhost:3000 user@server

# Copy files
scp file.txt user@host:/path/to/dest/
scp -r folder/ user@host:/path/to/dest/

# Copy between servers
scp user1@host1:/file user2@host2:/path/

# Config (~/.ssh/config)
Host myserver
    HostName 192.168.1.100
    User ubuntu
    IdentityFile ~/.ssh/id_rsa
    Port 22
# Now just: ssh myserver
Enter fullscreen mode Exit fullscreen mode

Git on the Command Line

# Quick status
git status -sb

# Nice log view
git log --oneline --graph -10

# Diff stats
git diff --stat

# Stash management
git stash push -m "WIP"
git stash list
git stash pop

# Undo last commit (keep changes)
git reset --soft HEAD~1

# Clean untracked files
git clean -fd

# Search commits
git log --grep="bug fix"
git log --oneline --all --grep="auth"
Enter fullscreen mode Exit fullscreen mode

My .bashrc Aliases

# Navigation
alias ..='cd ..'
alias ...='cd ../..'
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Git shortcuts
alias gs='git status'
alias gl='git log --oneline --graph -15'
alias gp='git push'
alias gpl='git pull'
alias gd='git diff'
alias gc='git commit -m'

# Docker
alias d='docker'
alias dc='docker compose'
alias dps='docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"'

# Quick servers
alias serve='python3 -m http.server 8000'
alias serve-php='php -S localhost:8000'

# Safety nets
alias rm='rm -I'          # Confirm before delete
alias mv='mv -i'          # Confirm before overwrite
alias cp='cp -i'          # Confirm before overwrite
Enter fullscreen mode Exit fullscreen mode

Which Linux commands can't you live without?

Follow @armorbreak for more developer content.

Top comments (0)