Linux Commands Complete Guide 2026: Server Administration and Shell Scripting

Sanjeev SharmaSanjeev Sharma
5 min read

Advertisement

Linux for Developers 2026: Own Your Server

Every production environment runs Linux. Understanding Linux commands is the difference between debugging in 5 minutes or 5 hours.

Essential Navigation and File Operations

# Navigation
pwd                         # Print working directory
ls -la                      # List with hidden files + details
cd /var/log                 # Change directory
cd ~                        # Go to home
cd -                        # Go to previous directory

# File operations
cp -r src/ dest/            # Copy recursively
mv old.txt new.txt          # Move/rename
rm -rf directory/           # Delete directory (careful!)
mkdir -p /path/to/dir       # Create with parents
ln -s /actual/path link     # Create symlink

# Find files
find / -name "*.log" -newer /tmp/marker  # Modified recently
find . -size +100M                        # Files larger than 100MB
find . -type f -name "*.ts" | wc -l      # Count TypeScript files

# Content search
grep -r "TODO" src/                      # Recursive search
grep -n "error" app.log                  # With line numbers
grep -E "ERROR|WARN" app.log             # Regex
grep -v "DEBUG" app.log                  # Exclude DEBUG lines

# View files
cat file.txt                             # Entire file
head -n 50 file.txt                      # First 50 lines
tail -n 100 -f app.log                   # Last 100 lines, follow
less file.txt                            # Page through (q to quit)

File Permissions

# Permission format: [type][owner][group][others]
# rwxrwxrwx = read(4) write(2) execute(1)

ls -la
# drwxr-xr-x 2 ubuntu ubuntu  4096 Mar 26 10:00 uploads
# -rw-r--r-- 1 ubuntu ubuntu  1234 Mar 26 10:00 app.js

# Change permissions
chmod 755 script.sh         # rwxr-xr-x (owner all, others read+exec)
chmod 644 config.json       # rw-r--r-- (owner rw, others read)
chmod +x deploy.sh          # Add execute permission
chmod -R 755 public/        # Recursive

# Change owner
chown ubuntu:ubuntu file.txt
chown -R www-data:www-data /var/www/

# Numeric shorthand
# 4=read, 2=write, 1=execute
# 7=rwx, 6=rw-, 5=r-x, 4=r--

# Check effective permissions
sudo -u www-data ls /var/www

Process Management

# View processes
ps aux                      # All processes
ps aux | grep node          # Find node processes
top                         # Real-time view
htop                        # Better real-time view (if installed)

# Manage processes
kill 1234                   # Terminate PID
kill -9 1234                # Force kill
pkill node                  # Kill by name
killall nginx               # Kill all nginx

# Background processes
command &                   # Run in background
nohup command &             # Continue after logout
jobs                        # List background jobs
fg %1                       # Bring job 1 to foreground

# System resources
free -h                     # Memory usage
df -h                       # Disk usage
iostat -x 1                 # I/O stats
netstat -tuln               # Open ports (or ss -tuln)
lsof -i :3000               # What's using port 3000

SSH and Remote Access

# Connect to server
ssh ubuntu@192.168.1.100
ssh -i ~/.ssh/my-key.pem ubuntu@ec2-xxx.amazonaws.com

# SSH config for shortcuts
# ~/.ssh/config
Host myserver
  HostName ec2-xxx.amazonaws.com
  User ubuntu
  IdentityFile ~/.ssh/my-key.pem

# Then just: ssh myserver

# Copy files
scp file.txt ubuntu@server:/home/ubuntu/
scp -r local/dir ubuntu@server:/remote/path/
rsync -avz --progress local/ ubuntu@server:/remote/  # Better than scp

# Tunnel: forward local port to remote
ssh -L 5432:localhost:5432 ubuntu@server
# Access remote PostgreSQL at localhost:5432

# Background tunnel
ssh -fNL 5432:localhost:5432 ubuntu@server

Nginx Configuration

# /etc/nginx/sites-available/webcoderspeed
server {
    listen 80;
    server_name webcoderspeed.com www.webcoderspeed.com;

    # Redirect HTTP to HTTPS
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    server_name webcoderspeed.com www.webcoderspeed.com;

    ssl_certificate /etc/letsencrypt/live/webcoderspeed.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/webcoderspeed.com/privkey.pem;

    # Security headers
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;
    add_header Strict-Transport-Security "max-age=31536000" always;

    # Rate limiting
    limit_req_zone $binary_remote_addr zone=api:10m rate=30r/m;

    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /api/ {
        limit_req zone=api burst=10 nodelay;
        proxy_pass http://localhost:3000;
    }

    location /_next/static/ {
        alias /app/.next/static/;
        add_header Cache-Control "public, max-age=31536000, immutable";
    }
}
# Enable site
sudo ln -s /etc/nginx/sites-available/webcoderspeed /etc/nginx/sites-enabled/
sudo nginx -t  # Test config
sudo systemctl reload nginx

# SSL with Let's Encrypt
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d webcoderspeed.com -d www.webcoderspeed.com

Shell Scripting

#!/bin/bash
# deploy.sh

set -euo pipefail  # Exit on error, unset vars, pipe failures
IFS=$'\n\t'

# Variables
APP_DIR="/app"
BACKUP_DIR="/app/backups"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)

log() { echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*"; }
error() { log "ERROR: $*" >&2; exit 1; }

# Check prerequisites
[[ -d "$APP_DIR" ]] || error "App directory not found: $APP_DIR"

# Backup
log "Creating backup..."
mkdir -p "$BACKUP_DIR"
tar -czf "$BACKUP_DIR/backup_$TIMESTAMP.tar.gz" "$APP_DIR"

# Deploy
log "Pulling latest code..."
cd "$APP_DIR"
git pull origin main

log "Installing dependencies..."
npm ci --production

log "Building app..."
npm run build

log "Restarting service..."
pm2 restart app --update-env

log "Deploy completed successfully!"

Cron Jobs

crontab -e   # Edit crontab

# Format: minute hour day month weekday command
# ┌───────────── minute (0-59)
# │ ┌───────────── hour (0-23)
# │ │ ┌───────────── day of month (1-31)
# │ │ │ ┌───────────── month (1-12)
# │ │ │ │ ┌───────────── weekday (0-7, Sunday=0/7)
# │ │ │ │ │

0 * * * *   /app/scripts/hourly.sh          # Every hour
0 0 * * *   /app/scripts/daily-backup.sh    # Daily at midnight
0 0 * * 1   /app/scripts/weekly-report.sh   # Every Monday
*/5 * * * * /app/scripts/health-check.sh    # Every 5 minutes

# Redirect output to log
0 0 * * * /app/scripts/backup.sh >> /var/log/backup.log 2>&1

Key Command Reference

# System info
uname -a           # Kernel info
uptime             # How long running
whoami             # Current user
id                 # User ID + groups
hostname           # Server hostname
cat /etc/os-release  # OS version

# Network
curl -I https://google.com  # HTTP headers
wget -O file.txt url        # Download
dig webcoderspeed.com       # DNS lookup
nslookup webcoderspeed.com  # DNS lookup
ip addr show                # Network interfaces
ping -c 4 google.com        # Ping 4 times

Linux mastery comes from daily use. Set up a VPS, deploy your app manually first — it teaches you more than any tutorial.

Advertisement

Sanjeev Sharma

Written by

Sanjeev Sharma

Full Stack Engineer · E-mopro