Skip to content
- Why Shell Scripts? — Automating repetitive tasks
- Use Cases — Real-world scenarios (backups, log parsing, deployments)
- How to Script — Creating
.sh files, shebang (#!/bin/bash)
- Making scripts executable (
chmod +x)
- Variable Basics — Declaration, assignment, referencing
- Variable Types — Strings, integers, typecasting (
declare)
- Indirect Referencing — Evaluating a variable’s value as a variable name
- Environment Variables —
export, $HOME, $USER, $PATH
- PATH Variable — How the shell finds commands
- Special Variable Types — Read-only, local, integer
- Positional Parameters —
$0, $1–$9, ${10}
$@ vs $* — Differences in quoting and iteration
$# — Argument count
$? — Exit code of last command
$$ — PID of current shell
$! — PID of last background process
- Defining Arrays — Indexed and associative
- Accessing Elements — Index, slicing, length
- Array Operations — Replace, delete, iterate
- Environment Variable Arrays
- Prefix & Suffix Removal —
#, ##, %, %%
- Replacement —
/ (first match), // (all matches)
- Anchored Replacement —
# prefix, % suffix
- Parameter Substitution
- Default Values —
${var:-default}
- Assign Default —
${var:=default}
- Alternative Values —
${var:+alt}
- Error Handling —
${var:?error msg}
- Conditional Operators
- String Conditionals —
=, !=, z, n
- Integer Conditionals —
eq, ne, lt, gt, le, ge
- File Conditions —
f, d, e, r, w, x
- Others —
&&, ||, !
if / elif / else Statements
case Statement — Pattern matching
- Real World Examples — Menu-driven scripts, option parsing
for Loop — Iterating over lists, ranges, files, arguments
while Loop
- Basic usage
- Use Cases — Infinite loop console, reading lines, watching file size
- Reading user input with
p
until Loop
- Logic — Executes while condition is FALSE
- Use Cases — File size monitoring, retry loops
- Function Syntax — Multiple valid forms
- Defining and Calling Functions
- Scope — Local vs global variables
- Return Values — Exit codes, echoed values
- Passing Arguments to Functions
- Child function ordering — Forward declaration rules
- Pipes (
|) — Chaining commands
- Data Streams — stdin, stdout, stderr
- File Descriptors —
0, 1, 2
- Redirection
> — Overwrite stdout
>> — Append stdout
2> — Redirect stderr
&> — Redirect both
< — Redirect stdin
- Heredoc — Sending multi-line input to a command
- Practical Task — Writing to files, outputting to terminal and stderr
- Shell Options Summary
- Flag Behavior Table
set -e — Exit immediately on error
set +e — Continue on error (default behavior)
set -x — Debug mode (print each command)
set -u — Treat unset variables as errors
- Basic substitution syntax —
s/find/replace/
- Global flag —
g
- In-place editing —
i
- Address ranges — Line numbers, patterns
- Delete lines —
d
- Regex patterns —
., , +, ?, [], ^, $
- Zero or more occurrences
- AWK syntax and structure
- Built-in variables —
$0, $1, NF, NR, FS, OFS
- Pattern matching
BEGIN and END blocks
- Length of each line/row
- Data processing practice
- Backup Script — Archive local files and upload to S3
- Retry Logic — While loop for reliable upload
- Log Parsing — Extract patterns from log files
- Error handling in scripts — Exit codes, conditional checks
- Task 1–4: Core scripting challenges
- Task 5: Power calculation function
- Task 6: Shortest string function
- Task 7: Log function
- Task 8: Advanced scripting
- Task 9: Log parsing with
sys_logs.log
- Linux Distributions — Fixed Release vs Rolling Release
- Comparison at a Glance — Which is better?
- Linux Families — Debian, RHEL, Arch, SUSE
- What is a Shell — Definition, role in OS
- Basic Architecture of the Shell
- Shell Types — bash, sh, zsh, ksh, fish
- Comparison of Shell Types
- Interactive Login Shell vs Interactive Non-Login Shell
- Shell Auto-completion — The Tab trick
- When NOT to Use Shell Scripts
- Navigation —
ls, cd, pwd, tree
- File Operations —
cp, mv, rm, touch, mkdir, rmdir
- Viewing Files —
cat, less, more, head, tail
- Searching —
grep, find, locate
- Information —
man, whatis, which, type
- Commands List — Comprehensive reference
- Unix/Linux vs Windows directory structure
- The Filesystem Hierarchy Standard (FHS)
- What is a Filesystem?
- Mounting —
mount, umount, /etc/fstab
- Steps to Mount
/dev/sr0 to /mnt/test
- Inodes — What they are, how they work
- Hard Links vs Soft Links (Symbolic Links)
- Hard Links — Same inode, same partition only
- Soft Links — Separate file, pointer to path
- Why Hard Links stay in one Partition
- Key Differences
- Sockets
- Communication on the Same Machine (Unix sockets)
- Communication Across Different Machines (TCP/IP sockets)
- Pipes
- Standard Pipe (
|) — One-Way Communication
- Named Pipe / FIFO (
mkfifo) — Custom Pipe
- Summary of Types of Pipes
- Permission Structure —
rwx for owner, group, others
- Numeric (Octal) notation —
chmod 755
- Symbolic notation —
chmod u+x
- Ownership —
chown, chgrp
- UMASK — Default permission mask
- Checking current defaults
- Calculating file permissions from umask
- Temporarily and permanently changing umask
- Symbolic mode modification
- Sticky Bit — Safety lock for shared folders (
/tmp)
- SUID (Set-User ID) — Run as file owner
- SGID (Set-Group ID) — Inherit group of directory
- File Attributes with
chattr and lsattr
- Immutable flag (
+i), append-only (+a)
- Summary Table — All special permissions
- The “Gotcha” Patterns
- User management —
useradd, usermod, userdel, passwd
- Group management —
groupadd, groupmod, groupdel
/etc/passwd, /etc/shadow, /etc/group
su vs sudo — Switching users safely
sudoers file — /etc/sudoers, visudo
- User profiles —
.bashrc, .bash_profile, .profile
- Process Commands —
ps, top, htop, jobs, fg, bg
- Process States — Running, Sleeping, Stopped, Zombie
- Signals —
kill, pkill, killall
- SIGTERM (15), SIGKILL (9), SIGHUP (1), SIGINT (2)
- Process Priority —
nice, renice
- Background processes —
&, nohup
- Memory —
free, vmstat
- CPU — Load average explained
- 1-minute, 5-minute, 15-minute averages
- Single-CPU vs Multi-CPU interpretation
- Disk Commands
df — Disk free space
du — Disk usage per directory
lsof — List open files
iostat — I/O statistics
- Software Packages & Managers
- The Two Main Families — Debian (APT) and RHEL (YUM/DNF)
- APT (Advanced Packaging Tool)
- Essential
apt-get commands
apt-cache for searching
- Sources list — Where software lives
- Daily Life Application
- YUM / DNF Config
- Repo configuration
- Alternatives Command — Managing multiple versions
- Java: JDK and OpenJDK management
- Boot Sequence — BIOS/UEFI → Bootloader → Kernel → Init
- Chain Loading: The Bootstrap Logic
- Bootloader Evolution
- LILO (Linux Loader) — Legacy
- GRUB (Grand Unified Bootloader) — Modern
- Runlevels & Systemd Targets
- Legacy: SysVinit Runlevels (0–6)
- Modern: Systemd Targets
- Command Dictionary
- What is Systemd?
- Types of Units — service, socket, timer, mount, target
- Anatomy of a
.service Unit File
[Unit] — Metadata & Dependencies
[Service] — Execution Logic (ExecStart, Restart)
[Install] — Boot Configuration (WantedBy)
- Commands for Managing Services
systemctl start/stop/restart/reload/enable/disable/status
- Working with Common Services — nginx, sshd, docker
- Journalctl — Log querying
- View logs by tag/unit
- Log file locations
- What is Cron — Purpose and daemon
- Crontab Syntax —
min hour day month dow command
- Common Operators — ,
,, , /
- Types of Crontabs — User, system,
/etc/cron.d/
- Essential Commands —
crontab -e/-l/-r
- Common Scheduling Examples
- Key Tips & Best Practices — Full paths, output redirection
- Vi / Vim — The Powerhouse
- Modes: Normal, Insert, Visual, Command
- Essential commands
- Nano — The User-Friendly Choice
- Visudo — The Safety Guard for sudoers
- Zip and Unzip — Windows-Compatible (
.zip)
- TAR — The “Tape Archive” (
.tar)
c create, x extract, t list, v verbose, f file
- GZIP — The Compressor (
.gz)
- Combined
.tar.gz workflow
- Daily Life Usage — Backup and restore patterns
find — The Precision Search
- By name, type, size, permissions, modified time
locate — The High-Speed Search (uses database)
grep — The Content Search
xargs — Building commands from input
- Essential flags for daily use
- Practical examples — Delete files, batch process
- SSH Architecture
- Key Pair Logic — The “Challenge-Response”
- Setup walkthrough (Windows → CentOS)
- Confirm SSH is running
- Find VM IP (NAT mode)
- Port Forwarding setup
- Generate SSH key on Windows
- Copy public key to CentOS
- Connect from Windows
- Essential Commands & File Management
- SCP — Secure Copy (upload/download files)
- SSH Command Flags —
i, p, L, R, D
- Bastion Hosts — The “Jump” Server
- Accessing Private Instances via bastion
- SSH Config File —
~/.ssh/config for simplifying connections
- SFTP & Chroot — Secure File Transfer
- Security Hardening — Disable password auth, restrict users
- Remote Command Execution — Running local scripts on remote VMs
- Finding Network Interfaces —
ip link, ifconfig
- The
ip Command (Modern Standard)
ip addr, ip route, ip link
- Key Usage Examples
- Permanent Configuration
- Ubuntu: Netplan (
/etc/netplan/*.yaml)
- CentOS: Network Scripts (
ifcfg-* files)
nmcli — NetworkManager CLI
- DNS & Hostnames —
/etc/hosts, /etc/resolv.conf, hostnamectl
- The Troubleshooting Mindset
- The Layered Strategy — OSI model approach
- Toolkit
- Connectivity & Pathing —
ping, traceroute, mtr
- Service & Protocol Checks —
curl, wget, telnet, nc
- Deep Packet & Port Inspection —
ss, netstat, nmap, tcpdump
- The Firewall Concept
- The Logic of the Rules
- iptables deep dive
- The Tables — filter, nat, mangle, raw
- The Chains — INPUT, OUTPUT, FORWARD, PREROUTING, POSTROUTING
- The Targets — ACCEPT, DROP, REJECT, LOG
- Writing Rules — Flag reference
- Practical Examples
- Saving the Configuration
- Stateful Firewalls — Connection tracking
- Firewalld
- Firewalld vs. Iptables: The Logic
- The Concept of Zones — public, internal, trusted, dmz
- Essential Commands —
firewall-cmd
- Masquerading (NAT) & Port Forwarding
- Making rules permanent
- DAC vs. MAC — The Logic
- SELinux Modes — Enforcing, Permissive, Disabled
- Configuration and Persistence —
/etc/selinux/config
- Booleans — The On/Off switches (
getsebool, setsebool)
- Policy Modules
- Daily Life Application — Fixing denied access
- The Core Logic of NAT
- Types of NAT
- Static SNAT (Source NAT)
- MASQUERADE (Dynamic SNAT)
- DNAT (Destination NAT / Port Forwarding)
- Deleting Rules
- The Logic of the Strict Rule
- Lab Task & Final Execution
- The Firewall Rule for DNAT
- Enabling IP Routing on Linux
- View Routing Table —
ip route, route -n
- Temporary Configuration —
ip route add (lost on reboot)
- Permanent Configuration — via netplan/ifcfg files
- Route Priority and Optimization — Metric values
- Dynamic Routing with Quagga
- Lease Process — DORA (Discover, Offer, Request, Acknowledge)
- Ubuntu DHCP Server Installation & Setup
- Configuring
dhcpd.conf — Subnet, range, gateway, DNS
- Advanced Controls — Static leases, lease time
- Client-Side Configuration
- Verification & History —
dhclient, lease files
- NAT (Network Address Translation)
- Bridged Adapter
- Internal Network
- Host-Only Adapter
- Generic Networking
- NAT Network
- Not Attached
- Logical Summary Table — VM perspective
- What is LVM & Why Use It?
- LVM Architecture
- Physical Volume (PV) —
pvcreate, pvdisplay
- Volume Group (VG) —
vgcreate, vgdisplay, vgextend
- Logical Volume (LV) —
lvcreate, lvdisplay, lvextend
- Format and Mount LV —
mkfs, mount, /etc/fstab
- Resizing
- Extend LV — Add space live
- Reduce LV — Shrink safely
- LVM Snapshots — Create, restore, remove
- Remove LVM Components — LV → VG → PV order
- Resizing Operations
- Resize Volume Group (add physical disk)
- Resize Logical Volume (extend + resize filesystem)
- XFS (
xfs_growfs) vs EXT4 (resize2fs)
- DUMMY Disks and Partitions — Loop devices for practice
- What is Swap — Virtual memory on disk
- Swappiness — The Control Valve (
/proc/sys/vm/swappiness)
- Creating Swap
- Method 1: LVM Partition (Recommended)
- Method 2: Swap File
- Removing a Swap File
- Resizing SWAP
- Disk Quota Implementation Workflow
- Enabling quotas on filesystem
quotacheck, edquota, repquota
- Practical Use Cases — SRE / DevOps / SysAdmin
- Task 1 — Static Routing & DHCP
- Assign Static Routes to Server and Client
- Assign IP through DHCP
- SSH Key Process between VMs
- Generate keys, copy to server, verify, lock down
- Multi-machine restoration plan after reboot
- Installing Git
- Global Config —
git config --global user.name/email
- Core Structure —
.git/ directory anatomy
.gitignore — Ignoring OS files, build dirs, env vars, IDE folders
.git/hooks — The Automation layer
git init / git clone
git add — Staging changes
git commit — Creating commits
git status / git log / git diff
git push / git pull / git fetch
- Changing Branches —
git checkout <branch>, git switch
- Recovering/Restoring Files
- From Staging — Undo local changes
- From a Commit — Recover deleted or old files
- Detached HEAD — Inspecting history without a branch
- Reset Command
- Soft Reset (
-soft) — Move HEAD, keep changes staged
- Mixed Reset (
-mixed) — Move HEAD, unstage changes (default)
- Hard Reset (
-hard) — Move HEAD, discard all changes
- Revert Command — Safe undo via new commit
- Brain Freak — Understanding revert vs reset mentally
- Creating and switching branches
- Branch naming conventions
- Listing and deleting branches
- Tracking remote branches
git merge — Fast-forward and three-way merges
- Merge Conflicts — Resolving manually
-ff-only — Only merge if linear
-no-ff — Always create merge commit
-squash — Combine all commits into one staged change
- What is Rebase — Replaying commits on new base
git rebase <branch> — Interactive and non-interactive
- Interactive Rebase —
pick, squash, reword, drop
- The History Flattener — DAG understanding
git cherry-pick <hash> — Apply a specific commit
- The Diff Extractor — DAG understanding
- Use cases — Hotfixes to multiple branches
- Lightweight tags vs Annotated tags
git tag, git tag -a
- Pushing tags —
git push --tags
- The Immutable Pointer — What tags mean
git stash — Save uncommitted work
git stash list / pop / apply / drop
- The LIFO Clipboard — Understanding stash order
- Centralized Strategy / Git Flow (The “Simple” Way)
- GitHub Flow / Feature Branch Workflow (The “Standard” Way)
- Gitflow (The “Structured” Way) — feature, develop, release, hotfix
- Distributed / Forking Workflows (The “Open Source” Way)
- Trunk Based Development
- Normal Merge — Graph before & after, what happens, benefits
- Squash Merge — Graph before & after, what happens
- Key Differences — History preservation vs clean log
- Real Team Usage — When to use each
- The One Critical Difference Most Devs Miss
- Build a baseline DAG — Initialize, branch, commit
- Practice all operations on the same repo:
- Git Reset (The State Mutator)
- Git Revert (The Safe Inverse)
- Git Rebase (The History Flattener)
- Git Merge (The DAG Integrator)
- Git Cherry-Pick (The Diff Extractor)
- Git Pull (The Network Synchronizer)
- Git Stash (The LIFO Clipboard)
- Git Tags (The Immutable Pointer)
- Packet Data Transfer Principle
- Historical Networks — ARPANET to modern internet
- Dial-Up Connection — How it worked
- Packet Transmission Process — Fragmentation, routing, reassembly
- LAN, WAN, MAN, PAN
- Network Topologies
- Bus, Star, Ring, Mesh, Hybrid
- Access Layer Devices
- Hub — Broadcasts to all ports
- Bridge — Connects two networks, learns MACs
- Switch — Intelligent forwarding by MAC table
- Unknown MAC behavior
- Broadcast behavior
- Router — Routes between networks (Layer 3)
- Scenarios
- Network A ↔︎ Bridge ↔︎ Network B
- PC-A → Switch → PC-B
- Layer 1 — Physical (cables, signals)
- Layer 2 — Data Link (MAC, frames, switches)
- Layer 3 — Network (IP, routing)
- Layer 4 — Transport (TCP/UDP, ports)
- Layer 5 — Session (session management)
- Layer 6 — Presentation (encoding, encryption)
- Layer 7 — Application (HTTP, DNS, FTP)
- What is a VLAN — Logical segmentation
- Why use VLANs — Security, performance, broadcast control
- VLAN tagging — 802.1Q
- Access ports vs Trunk ports
- DORA Process — Discover, Offer, Request, Acknowledge
- DHCP Server, Client, Relay Agent
- Lease time and renewal
- DNS Resolution Process — Recursive vs Iterative
- DNS Record Types — A, AAAA, CNAME, MX, NS, PTR, TXT
- DNS Servers — Root, TLD, Authoritative, Resolver
- Caching and TTL
- FTP — Active vs Passive mode, architecture
- NFS (Network File System) — Linux file sharing
- SMB / CIFS — Windows file sharing
- Telnet — Unencrypted, insecure, legacy
- RDP — Remote Desktop Protocol (Windows)
- SSH — Secure Shell (deep dive)
- SSH connection process (9 steps)
- Client connects to server
- Encryption protocol agreement
- Server identity verification
- Diffie-Hellman key exchange
- Public parameters
- Private key generation
- Public key exchange
- Shared secret computation
- Symmetric session key creation
- Encrypted channel established
- User authentication
- Shell session opened
- Secure session active
- Why NAT exists — Private vs public IP space
- Types of NAT
- Static NAT — One-to-one mapping
- Dynamic NAT — Pool-based
- PAT / Overloading — Many-to-one (most common)
- What is NTA and why it matters
- Basic Filters — Wireshark / tcpdump syntax
- Capturing and analyzing packets
- VPN — Virtual Private Network types (Site-to-Site, Remote Access)
- Tunneling protocols
- Proxy — Forward proxy vs Reverse proxy
- Use cases — Security, caching, load balancing
- Why Docker exists — Application-level management
- Running the right version of applications
- Docker Architecture Overview
- The Docker Client
- The Docker Daemon (
dockerd)
- The Docker Registry
- Docker Workflow — Build → Ship → Run
- Docker Components: The Core Infrastructure Pipeline
- Docker Image — Layers, base images
- Docker Storage (Graph) Drivers
- Virtual Machines vs Containers
- Isolation Technologies: Functional Requirements
- Namespaces — Process, network, mount, IPC, UTS, user
- Control Groups (cgroups) — Resource limits
- Chroot — Filesystem isolation
- Docker Engine internals
- Remote Docker CLI — Connecting to remote daemon
- Namespaces (Process ID Isolation)
- Control Groups (Resource Restriction)
- Image commands —
pull, images, rmi, inspect
- Container lifecycle —
run, start, stop, rm, ps
- Docker Commits — Saving container state as image
- Environment variables —
e, -env-file
- Entrypoint vs CMD — Key differences and use cases
- Docker Compose — Basic intro
- The Default Bridge Isolation
- How
link works
- Namespacing the Names (Environment Variables)
- The
/etc/hosts Hack
FROM — Base image selection
RUN — Execute commands during build
COPY vs ADD — Copying files in
WORKDIR — Set working directory
ENV — Set environment variables
EXPOSE — Document ports
ENTRYPOINT vs CMD — Deep dive
VOLUME — Declare mount points
USER — Set runtime user
- Multi-stage builds — Reducing image size
- Docker Storage and File Systems
- Docker Layered Architecture — How layers stack
- The Container Writable Layer — Copy-on-Write
- Copy-on-Write Mechanism in Practice
- Storage Types
- Persistent Storage: Volume Mounts (
v, -mount)
- Persistent Storage: Bind Mounts
tmpfs Mounts — In-memory, non-persistent
- The Modern
-mount Option vs v
- Storage Drivers — overlay2, aufs, devicemapper
- Example Lab — Named volumes, bind mounts, isolation verification
- Docker Networking overview
- Network Drivers
- Bridge Network — Default, isolated
- Host Network — Shares host network stack
- None Network — Completely isolated
- Custom Bridge Networks — Better DNS, isolation
- Container Inspection —
docker inspect, network details
- Docker DNS and Service Discovery
- The Problem with Static IPs
- How Docker DNS Works (Name-to-IP Mapping)
- Underlying Technology
- Network Management Commands —
docker network create/ls/inspect/rm
- Tasks including BIG TASK
- Architecture and YAML Specifications
- Core Definitions — services, networks, volumes
- Evolution of Docker Compose Versions
- Version 1 (Legacy / Deprecated)
- Version 2 (Single-Host Standard)
- Version 3 (Swarm & Production Ready)
- Key YAML Configuration Directives
- Advanced Networking Isolation
- Essential Command Reference
- Lab Task & Solution
- Image Tagging conventions
- Attached vs Detached Mode —
d, it
- Saving Container State —
docker commit
docker run Command — All flags
- Restart Policies —
no, always, on-failure, unless-stopped
- Docker Hub & Registries
- Storage & Data Persistence
- The Syntax Debate:
v vs -mount
- Bind Mounts — Read-only bind mounts
- Named Volumes
tmpfs Mounts
- System Cleanup —
prune commands
docker system prune, image prune, container prune, volume prune
- Namespaces & Cgroups (hands-on)
- Process Isolation examples
- Memory Limit Examples
- CPU Limit Examples
- The Core Philosophy — What is a Container?
- Linux Namespaces & Docker Equivalents (Deep Dive)
- PID Namespace — Process ID isolation
- NET Namespace — Network stack isolation
- IPC Namespace — Inter-Process Communication
- MNT Namespace — Mount / Filesystem isolation
- UTS Namespace — Hostname isolation
- User Namespace — UID/GID isolation
- Kubernetes Isolation Logic
- K8s Namespaces vs. Linux Namespaces
- How a Pod is Implemented (The “Pause” Container)
- Isolation: Container vs. Container (Inside same Pod)
- Isolation: Pod vs. Pod in same Node
- The Matrix — Summary of all isolation levels
- Docker Registry — Public and private
- Image Naming Convention —
registry/repo:tag
- Running Your Own Private Registry
- Pushing to a Custom Registry
- Local Private Registry — Windows host ↔︎ CentOS VM lab
- Start the Private Registry
- Build, Tag, Push
- Configure Insecure Registry on client
- Pull and Run from registry
- Docker Logging — json-file driver, log rotation
- Monitoring & Inspecting Containers
docker stats, docker top, docker inspect
- Useful Monitoring CLI Commands
- Advanced Monitoring Tools — cAdvisor, Prometheus
- Container Vulnerabilities
- Least-privilege principles
- Read-only filesystems
- Capability dropping
- 12-Factor App alignment
- One process per container
- Stateless containers
- Config via environment variables
- The Core Problems Orchestration Solves
- Docker Swarm — The Native (But Basic) Solution
- Architecture & Workflow — Manager, worker nodes
- Kubernetes (K8s) — The Industry Standard
- The Kubernetes Architecture overview
- Docker on Windows
- Legacy: Docker Toolbox
- Modern: Docker Desktop for Windows
- Native Windows Containers
- Docker on Mac
- Legacy: Docker Toolbox
- Modern: Docker Desktop for Mac
- Summary of the Architecture
- YAML syntax fundamentals for Docker Compose
- Docker REST API
- Remote daemon access
- Task 1 through Task 8 — Progressive Dockerfile challenges
- Python Core Characteristics — Interpreted, dynamic, high-level
- Pros and Cons
- Execution Modes — Script, interactive, module
- The Zen of Python (
import this)
- Origins & Authorship — Guido van Rossum
- Version History & Evolution — Python 2 vs 3
- Resources & Installation
- PEP 8 — Python Enhancement Proposal 8 (style guide)
- Package Management (PIP) —
install, freeze, uninstall
requirements.txt vs pyproject.toml
- Execution Environments & Tooling
- Virtual Environments
- The Logic of Virtual Environments
- Architectural Breakdown — How isolation works
- Command Reference Toolkit
- Practical Implementation
- Step 1: Install Python versions (
pyenv)
- Step 2: Create two isolated virtual environments
- Step 3 & 4: Setup Workspace 1 & 2
- Step 5: Verifying the Isolation
pyenv activate, deactivate, uninstall
- Syntax Rules & Structure
- Variables & Dynamic Typing
- The Python Data Model
- Immutable types — int, float, str, tuple, frozenset
- Mutable types — list, dict, set
- Operators — Arithmetic, comparison, logical, bitwise, identity, membership
- Control Flow & I/O —
input(), print(), if/elif/else
- Lists — Built-in methods (
append, pop, sort, extend, etc.)
- Tuples — Immutable sequences, operations reference
- Sets — Unique collections, set operations (union, intersection, difference)
- Dictionaries (Associative Arrays) — Keys, values, methods
- Python Loops & Iteration —
for, while, break, continue, else
- String Indexing & Slicing —
s[start:stop:step]
- String Formatting — f-strings,
.format(), raw strings
- Top 10 Essential String Methods
- Function Anatomy & Definition —
def, docstrings
- Execution & Memory — Pass-by-reference behavior
- Argument Passing Rules — Positional, keyword, default
- Arbitrary Argument Lists
args — Variable positional arguments
*kwargs — Variable keyword arguments
- Advanced List Input — One-line extraction
- Output Formatting & Unpacking
- Parsing Dictionary Input via JSON
- Variable Scopes — Local vs. Global
- The
global Keyword
- Name Resolution: The LEGB Rule — Local, Enclosing, Global, Built-in
- Anonymous Functions (Lambda)
- Namespace Introspection —
globals() and locals()
- Package Architecture & Namespace Organization
- The Module & Import System —
import, from x import y
- Execution Context —
if __name__ == "__main__":
- The Module Search Path —
sys.path
- Module Introspection —
dir()
- Project Architecture for Distribution
- The Setup Configuration (
setup.py)
entry_points — Console scripts
- Building Distributives —
sdist, bdist_wheel
- Package Installation & Management (PIP)
- Classes, Instances, and State
__init__, instance variables, class variables
- Dynamic Attribute Modification —
setattr, getattr, delattr
- Inheritance & Method Resolution Order (MRO)
- Single inheritance
- Multiple inheritance
- MRO with
super()
- “Private” Variables & Name Mangling —
__var
- Magic (Dunder) Methods & Operator Overloading
__str__, __repr__, __add__, __len__
try / except / else / finally structure
- Catching & Inspecting Exceptions —
as e, str(e)
- Raising & Chaining Exceptions —
raise, raise X from Y
- Custom Exceptions — Defining your own exception classes
- File Initialization & Attributes —
open(), modes r/w/a/rb
- Writing to Files —
write(), overwrite vs append
- Reading File Data —
read(), readline(), readlines()
- OS-Level File Handling —
os.rename(), os.remove()
- Advanced Application: Log Parsing Engine
- Debugging in Python —
pdb, breakpoint()
- Syslog Integration
- The Logging Module & Severity Levels
- DEBUG, INFO, WARNING, ERROR, CRITICAL
- File Output and Formatting — Log file with timestamps
- Complex Configuration via External Files (YAML-based logging config)
- Directory Listing & Pattern Matching —
os.listdir(), glob
- Directory Creation & Traversal —
os.makedirs(), os.walk()
- Temporary Directories —
tempfile.TemporaryDirectory()
- Deleting, Copying, and Moving —
shutil
shutil.copy(), shutil.move(), shutil.rmtree()
- Archiving — Zipping and Extracting
- Manual with
zipfile module
- Quick with
shutil.make_archive()
- The Automated Testing Paradigm & CI/CD alignment
- Testing Frameworks
unittest — Built-in, setUp/tearDown
pytest — Modern, simpler syntax
setUp and tearDown — Before/after each test
- Standard assertion methods
- Mocking External Dependencies —
unittest.mock
@patch decorator
- Mock return values, side effects
- Test Runners and Code Coverage —
coverage.py
- Multi-Environment Matrix Testing —
tox and tox.ini
- Python Web Application Layers — WSGI, framework, app, DB
- Flask Framework Basics — Routes, views, templates
- Flask with Jinja2 Templates
- HTTP Protocol & URL Formatting
- The Requests Library
- Basic Auth, Bearer Token, Query Parameters
- JSON Parsing & Extraction Logic
- Jinja2 Basics & Template Syntax —
{{ variable }}
- Control Structures —
{% if %}, {% for %}
- YAML Integration & Rendering Engine — Generate configs from data
- What is Flask & Why Use It — WSGI, Flask vs Django
- Project Planning & Feature List
- Environment Setup — venv, packages,
requirements.txt
- Project Structure & Architecture — Application factory pattern
- Configuration Management — Config classes,
.env, python-dotenv
- Routing & URL Building —
@app.route, url_for()
- Request & Response Lifecycle —
request, g, response objects
- Jinja2 Templating — Inheritance, macros, filters
- Static Files Management
- Flask-SQLAlchemy & Database Modeling — ORM, models, relationships
- Database Migrations with Flask-Migrate —
flask db migrate/upgrade
- Flask Blueprints — Modular architecture
- Forms with Flask-WTF & WTForms — CSRF, validation, custom validators
- User Authentication with Flask-Login —
current_user, @login_required
- Password Hashing & Security —
bcrypt
- Session Management — Client-side cookies, Flask-Session
- Flash Messages — Post-Redirect-Get pattern
- File Uploads & Image Handling — Security, Pillow
- REST API with Flask — Versioning, status codes, token auth, Marshmallow
- Flask-RESTful — Resource classes,
reqparse
- Pagination — SQLAlchemy
.paginate()
- Search Functionality
- Email Sending with Flask-Mail — SMTP, async emails
- Error Handling & Custom Error Pages
- Logging — Python logging, Sentry
- Caching with Flask-Caching — Backends, strategies, invalidation
- Role-Based Access Control (RBAC)
- Comments System — Threaded, moderation, spam prevention
- Tags & Categories — Slugs, hierarchical vs flat taxonomy
- Rich Text Editor — Markdown storage, syntax highlighting
- Context Processors & Template Globals
- Signals with Blinker
- Testing Flask Applications — Test client,
conftest.py
- Flask CLI & Custom Commands
- Admin Panel with Flask-Admin
- Rate Limiting with Flask-Limiter
- Background Tasks with Celery — Celery Beat periodic tasks
- WebSockets with Flask-SocketIO
- Security Best Practices — OWASP Top 10, HTTP security headers
- Performance Optimization — DB indexing, caching, static files
- Deployment Stack — Gunicorn, Nginx, PostgreSQL, systemd, SSL/TLS
- Environment Variables & Secrets Management — 12-Factor App
- Docker & Containerization for Flask — Dockerfile, Compose, multi-stage
- Full Data Flow Walkthrough — Creating a blog post end-to-end
- Python Packaging Ecosystem
- The Dockerfile Architecture for Python
- Base image → WORKDIR → COPY requirements → pip install → COPY app → CMD
- Docker Execution & Deployment
- Base Image Selection Logic —
python:3.x-slim vs full vs alpine