1. Engineering a Production-Grade Automated Backup Script
Backing up critical user directories is the quintessential administrative task. Below is a complete, production-hardened Bash script synthesizing file validation, timestamping, tar compression, and exit status logging:
#!/bin/bash
# ==============================================================================
# Script Name : auto_backup.sh
# Purpose : Automated timestamped compressed backup of critical user data
# ==============================================================================
# Strict error handling: exit immediately if an unhandled command fails
set -euo pipefail
# Configuration Variables
SOURCE_DIR="$HOME/Documents"
BACKUP_DEST="$HOME/backups"
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
ARCHIVE_NAME="backup_documents_${TIMESTAMP}.tar.gz"
LOG_FILE="${BACKUP_DEST}/backup.log"
# Step 1: Ensure destination directory exists
mkdir -p "$BACKUP_DEST"
echo "[$(date)] --- Starting Backup Routine ---" | tee -a "$LOG_FILE"
# Step 2: Verify source directory exists
if [ ! -d "$SOURCE_DIR" ]; then
echo "[$(date)] ERROR: Source directory '$SOURCE_DIR' does not exist!" | tee -a "$LOG_FILE"
exit 1
fi
# Step 3: Execute compressed tar archive creation
# -c : create archive | -z : compress with gzip | -v : verbose | -f : output filename
echo "[$(date)] Compressing '$SOURCE_DIR' into '${BACKUP_DEST}/${ARCHIVE_NAME}'..." | tee -a "$LOG_FILE"
tar -czf "${BACKUP_DEST}/${ARCHIVE_NAME}" -C "$HOME" "Documents"
# Step 4: Verify archive integrity and calculate storage size
ARCHIVE_SIZE=$(du -h "${BACKUP_DEST}/${ARCHIVE_NAME}" | cut -f1)
echo "[$(date)] SUCCESS: Backup created successfully (Size: ${ARCHIVE_SIZE})." | tee -a "$LOG_FILE"
# Step 5: Retention Policy: Automatically purge backups older than 14 days
echo "[$(date)] Cleaning archives older than 14 days..." | tee -a "$LOG_FILE"
find "$BACKUP_DEST" -type f -name "backup_documents_*.tar.gz" -mtime +14 -exec rm {} ;
echo "[$(date)] --- Backup Process Completed ---" | tee -a "$LOG_FILE"2. Job Scheduling with Cron
The cron daemon executes tasks automatically in the background on scheduled intervals according to the user's crontab (cron table).
* * * * * /path/to/command
| | | | |
| | | | +--- Day of the Week (0 - 7, 0 and 7 = Sunday)
| | | +----- Month of Year (1 - 12)
| | +------- Day of Month (1 - 31)
| +--------- Hour (0 - 23)
+----------- Minute (0 - 59)Common Crontab Schedules
| Schedule Expression | Frequency & Description |
|---|---|
0 2 * * * | Run every night at 2:00 AM |
0 */4 * * * | Run every 4 hours at minute 0 |
30 18 * * 1-5 | Run Monday through Friday at 6:30 PM |
0 0 1 * * | Run on the 1st of every month at midnight |
@reboot | Run once immediately upon operating system startup |
# Edit the current user's crontab file in nano
crontab -e
# Example crontab entry: execute the backup script daily at 2:30 AM and log output
30 2 * * * /bin/bash /home/anupam/scripts/auto_backup.sh >> /home/anupam/backups/cron.log 2>&1
# View active scheduled cron tasks
crontab -l3. Real-Time System Monitoring & Resource Sizing
Understanding how to diagnose system performance bottlenecks ensures applications run smoothly:
# 1. Inspect real-time process table, CPU usage, and memory (press 'q' to quit)
top
# 2. Modern colorful interactive process viewer (install via 'sudo apt install htop')
htop
# 3. Display physical RAM and Swap usage in human-readable megabytes
free -h
# 4. Display filesystem disk capacity, mount points, and remaining space
df -h
# 5. Check system uptime, logged in users, and load average over 1, 5, 15 minutes
uptime
# 6. Locate a rogue process by name and terminate it gracefully
pgrep -l python
kill -15 <PID> # SIGTERM (Graceful shutdown request)
kill -9 <PID> # SIGKILL (Forceful kernel termination)4. Linux on Embedded Systems: The Raspberry Pi Ecosystem
The guide highlights the synergy between Linux and the Raspberry Pi—the revolutionary single-board computer powered by ARM architecture:
- Raspberry Pi OS (formerly Raspbian): An optimized Debian derivative tailored specifically for ARM processors with built-in educational and programming tools (Python, Scratch, Thonny).
- Headless SSH Access: Enabling SSH by creating a blank file named
sshin the boot partition allows remote administration without needing a dedicated monitor, keyboard, or mouse:
# Remote shell access over local network
ssh pi@raspberrypi.local- Physical Computing (GPIO): 40-pin General Purpose Input/Output header allows direct hardware interaction with sensors, relays, LEDs, and robotic motors via Python libraries (
gpiozero,RPi.GPIO).
5. Essential A–Z Linux Administrator Command Reference
| Command | Category | Functional Purpose & Key Flags |
|---|---|---|
| adduser | User Mgmt | Interactively add a new user account with home folder and skeleton files |
| alias | Shell Customization | Create a persistent shorthand macro for complex commands (alias ll='ls -la') |
| apt | Package Mgmt | Advanced package tool to search, update, install, and purge packages |
| cat | File I/O | Concatenate and display file content to standard output |
| chmod | Security | Change file mode bits / permissions (chmod 755 script.sh) |
| chown | Security | Change file owner and group ownership (chown anupam:www-data site.html) |
| cp | File I/O | Copy files and directories recursively (cp -r src/ dest/) |
| crontab | Scheduling | Schedule automated background tasks with timing expressions |
| curl | Networking | Transfer data from or to a server using HTTP, HTTPS, FTP, or SFTP |
| df | Storage | Report filesystem disk space usage across partitions (df -h) |
| du | Storage | Estimate file space usage for directories (du -sh /var/log) |
| find | Search | Search for files in a directory hierarchy by name, type, size, or mtime |
| free | Performance | Display amount of free and used memory and swap space (free -m) |
| grep | Text Processing | Print lines matching regular expression patterns (grep -rn "TODO" .) |
| htop | Performance | Interactive, ncurses-based real-time process viewer and system monitor |
| ip | Networking | Show and manipulate routing, network devices, interfaces, and IP addresses (ip a) |
| kill | Process Mgmt | Send execution control signals to processes (kill -9 <PID>) |
| ls | File I/O | List directory contents with timestamps, permissions, and sizes |
| mkdir | File I/O | Create directories (mkdir -p path/to/nested/folder) |
| mv | File I/O | Move or rename files and directories |
| nano | Text Editor | User-friendly command-line text editor with intuitive keyboard shortcuts |
| ping | Networking | Send ICMP ECHO_REQUEST packets to verify network connectivity |
| pwd | File I/O | Print full path of the current working directory |
| rm | File I/O | Remove files or directories (rm -rf path/) |
| rsync | File I/O | Fast, versatile, remote and local file-copying and synchronization tool |
| sudo | Security | Execute a command with elevated superuser privileges |
| systemctl | Service Mgmt | Control the systemd system and service manager (systemctl status ufw) |
| tar | Archiving | Tape archive utility to create and extract compressed archives (tar -czvf) |
| top | Performance | Display live Linux processes, CPU allocation, and memory load averages |
| touch | File I/O | Create empty files or update file access and modification timestamps |
| ufw | Security | Uncomplicated Firewall interface for configuring packet filtering rules |
| uname | System Info | Print system information, machine architecture, and kernel release (uname -a) |
| uptime | System Info | Tell how long the system has been running and load averages |
| whoami | User Mgmt | Print the current effective username |
| zip / unzip | Archiving | Package and compress or extract ZIP archives |