Linux – Beginner to Advanced

Architecture, filesystem, users, processes, networking, pipelines, and scripting.

Overview

Learn Linux from fundamentals to advanced topics: architecture, filesystem, users, processes, networking, packaging, pipelines, and scripting.

Architecture & Filesystem

Linux consists of the kernel, system libraries, and user space. Filesystem hierarchy includes /, /bin, /etc, /var, /home, /proc, and more.

# Explore filesystem
ls /
tree -L 1 /etc
mount | column -t

Why/Usage

  • ls /: list top-level directories so you learn where things live.
  • tree -L 1 /etc: show first-level configs inside /etc.
  • mount: display mounted filesystems and mount points.

User Management & Permissions

Users & Groups

sudo adduser dev
sudo passwd dev
groups dev
su - dev
sudo usermod -aG sudo dev

Why/Usage

  • adduser: create a new account.
  • passwd: set or change the user password.
  • groups: show which groups a user belongs to.
  • su -: switch to another user’s shell (login environment).
  • usermod -aG sudo: grant sudo privileges by adding to the sudo group.

Permissions

chmod 644 file.txt   # rw-r--r--
chmod +x script.sh
sudo chown dev:dev /srv/app
umask 022

Why/Usage

  • chmod: change read/write/execute bits for owner, group, others.
  • +x: make a script executable.
  • chown: change file owner and group.
  • umask: default permission mask for new files.

File Operations & Search

touch a.txt && mkdir logs
cp a.txt logs/a.bak && mv a.txt a1.txt
rm -rf old_dir
find /var/log -type f -name "*.log" -size +10M -mtime -7
locate sshd_config

Why/Usage

  • touch: create empty file or update timestamp.
  • mkdir: create a directory.
  • cp/mv/rm: copy, move/rename, and remove files or directories.
  • find: search files by type, name, size, and age.
  • locate: search via prebuilt index (very fast).

Viewing & Editing Files

cat /etc/os-release
head -n 20 app.log
tail -f app.log
nano /etc/hosts
vim ~/.bashrc

Why/Usage

  • cat: print a file’s content.
  • head/tail: see the beginning or end of files; -f follows updates (logs).
  • nano/vim: edit files in terminal; vim is powerful once learned.

Process & Service Management

ps aux | grep nginx
top
htop
sudo systemctl status nginx
sudo systemctl restart nginx
pkill -f "python app.py"

Why/Usage

  • ps: list running processes; combine with grep to filter.
  • top/htop: interactive process monitors; htop is more user friendly.
  • systemctl: inspect and control systemd services.
  • pkill: terminate processes by name or pattern.

Disk, Memory, Compression

df -h
du -sh * | sort -h | tail -n 20
free -h
lsblk
sudo mount /dev/xvdf1 /data
tar -czf backup.tar.gz /var/www
zip -r site.zip public && unzip site.zip -d /tmp/site

Why/Usage

  • df: disk usage per filesystem.
  • du: disk usage per directory/file.
  • free: memory and swap usage.
  • lsblk: list block devices.
  • mount: attach a device to a path.
  • tar/zip: archive and compress files.

Networking

ping -c 4 8.8.8.8
curl -I https://example.com
wget https://example.com/file.tar.gz
ssh -i key.pem ubuntu@host
scp -i key.pem file ubuntu@host:/tmp/
ss -tulpen
ip a
  • ping: connectivity and latency test.
  • curl: HTTP client for APIs and headers; -I fetches headers only.
  • wget: download files from URLs.
  • ssh/scp: remote login and secure copy.
  • ss: list listening and established sockets.
  • ip a: show network interfaces and addresses.

Package Managers

sudo apt update && sudo apt install -y nginx
sudo dnf install git
brew install htop
  • apt/dnf: install packages on Debian/Ubuntu or RHEL/Fedora.
  • brew: macOS/Linux package manager for developer tools.

Pipelines: grep | sort | uniq | awk | sed

# Top IPs hitting Nginx
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr | head

# Errors by endpoint
grep " 500 " access.log | awk '{print $7}' | sort | uniq -c | sort -nr | head

# Replace text in files
sed -i 's/foo/bar/g' config.yaml
  • awk {print $1}: extract the first column (IP) from logs.
  • sort | uniq -c | sort -nr: count and rank frequent values.
  • grep "500": filter error lines; {print $7} extracts path.
  • sed -i: in-place text replacement across files.

Shell Scripting Project: Log Cleanup + Backup

#!/usr/bin/env bash
set -euo pipefail

LOG_DIR=/var/log/myapp
BACKUP_DIR=/var/backups/myapp
RETENTION_DAYS=7

mkdir -p "$BACKUP_DIR"
find "$LOG_DIR" -type f -name "*.log" -mtime +$RETENTION_DAYS -print -delete
tar -czf "$BACKUP_DIR/logs-$(date +%F).tar.gz" "$LOG_DIR"
aws s3 cp "$BACKUP_DIR" s3://my-bucket/logs/ --recursive
echo "Cleanup and backup done."