-
7.1 Process Management
-
ps aux # All processes
-
ps -eo pid,ppid,cmd,%cpu,%mem –sort=-%cpu
-
top # Real-time view
-
htop # Interactive (install first)
-
pgrep nginx # PID by name
-
kill 1234 # SIGTERM (graceful)
-
kill -9 1234 # SIGKILL (force)
-
killall nginx # Kill by name
-
pkill -u alice # Kill by user
-
# Background jobs
-
command & # Run in background
-
jobs # List background jobs
-
fg %1 # Bring job 1 to foreground
-
bg %1 # Resume in background
-
nohup command & # Persist after logout
-
screen / tmux # Terminal multiplexers
-
7.2 Systemd & Service Management
-
# systemctl
-
systemctl status nginx # Check status
-
systemctl start|stop|restart nginx
-
systemctl enable nginx # Enable on boot
-
systemctl disable nginx # Disable on boot
-
systemctl list-units –type=service
-
# Logs with journald
-
journalctl -u nginx # Logs for nginx
-
journalctl -f # Follow all logs
-
journalctl –since “1 hour ago”
-
journalctl -p err # Errors only
-
7.3 System Resources
-
free -h # Memory usage
-
df -h # Disk space
-
du -sh /var/log/ # Directory size
-
iostat -x 1 5 # Disk I/O
-
vmstat 1 5 # System stats
-
lscpu # CPU info
-
lsblk # Block devices
-
netstat -tulpn # Open ports
-
ss -tulpn # Modern netstat
-
lsof -i :80 # Processes on port 80
-
7.4 Scheduling with cron
-
# crontab syntax: min hour day month weekday command
-
crontab -e # Edit your crontab
-
crontab -l # List crontab
-
# Examples
-
0 2 * * * /backup.sh # Daily at 2am
-
*/15 * * * * /check-health.sh # Every 15 minutes
-
0 9 * * 1 /weekly-report.sh # Mondays at 9am
-
0 0 1 * * /monthly-cleanup.sh # Monthly
-
@reboot /start-services.sh # On system boot
-
# System-wide cron
-
/etc/cron.d/
-
/etc/cron.daily/
-
/etc/cron.weekly/