The Linux Picture Book
Hardware · CPU · RAM · disk · NIC Kernelprocesses · memory · drivers · filesystems · network Shellbash · zsh Programsls · grep · nginx · python You type commands
PLATE 0 — You never touch the hardware. You ask the shell, the shell asks the kernel.
A picture book for grown-ups · with commands

How Linux Works, and How to Drive It

Nine spreads. Each has a picture, the idea, and the commands you'd actually type in a terminal. Every example works on Ubuntu, Debian, and most other distros.

Say it like a pro

"Everything's a file. I pipe small tools together, lock things down with permissions and sudo, and run services under systemd."

Use the tabs or the ← → keys to turn pages.

/ /etc /home /var /usr /dev /tmp config your stuff logs, data programs devices scratch /home/ama/projects/site/index.html absolute path: starts at / relative path: starts where you are (pwd) ~ = /home/ama . = here .. = parent /proc and /dev aren't on disk: the kernel fakes them
PLATE 1 — One tree. No C: or D:. Disks get mounted somewhere inside it.
Chapter 1 · The filesystem

One tree, and everything hangs off /

Linux has a single directory tree. Extra disks and USB sticks are mounted onto a folder. Even hardware shows up as files under /dev.

Move around and look
$ pwd                    # where am I?
$ ls -lah                # list, long, all, human sizes
$ cd /var/log; cd ~; cd -  # go there, home, back
$ mkdir -p a/b/c         # make nested dirs
$ cp -r src dst; mv old new; rm -r dir
$ find / -name "*.conf" 2>/dev/null
$ df -h; du -sh *        # disk free / usage
/etc
system config (text files)
/var/log
logs
/usr/bin
most commands live here
/dev/null
the black hole; writes vanish
Say it like a pro

"Check /var/log, then diff the config in /etc against the package default."

cat grep sort uniq -c head stdout of one → stdin of the next cat access.log | grep 404 | sort | uniq -c | head Three streams per program 0 stdin · keyboard or a pipe 1 stdout · normal output (screen) 2 stderr · errors (screen) > file overwrite · >> append · 2> errors · < input
PLATE 2 — Small tools, each doing one job, snapped together with |.
Chapter 2 · The shell

Pipes: the Linux superpower

The shell reads your line, expands wildcards and variables, then runs the program. Each program reads text in and writes text out, so you can chain them.

The everyday text toolbox
$ less file          # page through (q to quit)
$ head -n 5 f; tail -f log   # top lines / follow live
$ grep -rni "error" /var/log
$ wc -l file         # count lines
$ cut -d: -f1 /etc/passwd
$ sed 's/old/new/g' f ; awk '{print $1}' f
$ ls *.txt > list.txt ; cmd 2>&1 | tee out.log
$ history | grep ssh ; !!   # Ctrl+R searches too
man ls
the manual; --help is shorter
Tab
autocomplete; press twice for options
Ctrl+C
stop the running command
Say it like a pro

"I'll grep the logs, sort and count by IP, and tail the top ten."

-rwxr-xr-- - rwx = 7 r-x = 5 r-- = 4 type owner (u) group (g) others (o) r = 4read w = 2write x = 1execute / enter chmod 754 script.sh 7 = 4+2+1 · 5 = 4+0+1 · 4 = 4+0+0 on a directory, x means "may cd into it"
PLATE 3 — Three people, three switches each. Add the numbers to get the digit.
Chapter 3 · Permissions & ownership

Who may read, write, and run

Every file has an owner and a group. ls -l shows the nine permission bits. The kernel checks them on every access.

Change them
$ ls -l script.sh
-rwxr-xr-- 1 ama devs 220 Oct 30 run.sh
$ chmod 755 file        # numeric
$ chmod u+x,g-w file    # symbolic
$ chown ama:devs file
$ chmod 600 ~/.ssh/id_ed25519   # private key: owner only
$ umask                 # default mask for new files
755
programs and directories
644
normal files
600
secrets
777
everyone can do everything. Almost never right.
Say it like a pro

"Permission denied? Check the owner, the mode, and whether the parent directory is searchable."

systemd · PID 1 sshd nginx cron bash python app.py Signals SIGINT (2) Ctrl+C, please stop SIGTERM (15) polite shutdown (default) SIGKILL (9) cannot be caught. Last resort. SIGHUP (1) reload config
PLATE 4 — Every process has a parent and a PID. Signals are how you talk to them.
Chapter 4 · Processes

What's running, and how to stop it

A program that's running is a process. The kernel starts systemd first (PID 1), and everything else descends from it.

Watch and control
$ ps aux | grep nginx
$ top      # or htop; q to quit
$ free -h  ;  uptime  ;  lsof -i :80
$ kill 1234          # SIGTERM
$ kill -9 1234       # SIGKILL
$ pkill -f app.py
$ sleep 300 &       # background job
$ jobs; fg %1        # Ctrl+Z pauses, bg resumes
$ nohup ./job.sh &   # survives logout
load avg
in uptime; compare to your CPU count
zombie
finished, but its parent hasn't collected it
Say it like a pro

"I sent SIGTERM first. It ignored it, so I escalated to SIGKILL."

Your PC apt / dnfpackage manager Repo request .deb / .rpm install nginx 1 · check signature (GPG) 2 · pull dependencies too (libssl, pcre…) 3 · unpack files into /usr, /etc · run setup
PLATE 5 — You never download installers. The package manager does the shopping.
Chapter 5 · Installing software

Package managers and repositories

Software comes from signed repositories. The package manager resolves dependencies, installs, and updates everything in one go.

TaskDebian / UbuntuFedora / RHEL
refreshapt updatednf check-update
upgradeapt upgradednf upgrade
installapt install pkgdnf install pkg
removeapt remove pkgdnf remove pkg
searchapt search worddnf search word
$ sudo apt update && sudo apt install -y nginx git curl
$ apt show nginx ; dpkg -L nginx   # info / files it installed
$ which python3 ; type ls
Say it like a pro

"Update the index, install from the distro repo, and pin the version if prod can't drift."

ama UID 1000 · normal user sudoasks sudoers root UID 0 · can do anything Where accounts live /etc/passwd name, UID, home, shell /etc/shadow password hashes (root only) /etc/group who's in which group least privilege: use sudo per command, not a root shell
PLATE 6 — Work as yourself. Borrow root for one command at a time.
Chapter 6 · Users, groups & sudo

Root is powerful, so you ask nicely

Day to day you're a normal user. sudo runs one command as root if the sudoers policy says you may, and it logs the attempt.

Manage accounts
$ whoami ; id ; groups
$ sudo adduser dev            # create user
$ sudo usermod -aG sudo,docker dev
$ sudo passwd dev
$ sudo userdel -r dev         # remove + home
$ sudo visudo                 # edit sudoers safely
$ su - dev                     # switch user
-aG
append to groups. Without -a you replace them!
log out
group changes apply at next login
Say it like a pro

"Service accounts get no login shell and own only their own data directory."

Laptop Internet Server encrypted SSH tunnel · port 22 Key login, no passwords private key ~/.ssh/id_ed25519 (stays on laptop) public key ~/.ssh/authorized_keys (on server) server proves itself via known_hosts fingerprint scp / rsync ride the same tunnel
PLATE 7 — SSH: a locked pipe straight into someone else's terminal.
Chapter 7 · Networking & SSH

Look at the network, then reach across it

Inspect
$ ip addr ; ip route        # addresses, gateway
$ ping -c 3 1.1.1.1 ; ping -c 3 example.com
$ ss -tulpn                 # who's listening
$ dig example.com ; curl -I https://example.com
$ sudo ufw allow 22/tcp && sudo ufw enable
Remote work
$ ssh-keygen -t ed25519
$ ssh-copy-id ama@203.0.113.9
$ ssh ama@203.0.113.9
$ scp file.txt ama@host:/tmp/
$ rsync -avz ./site/ ama@host:/var/www/site/
$ ssh -L 8080:localhost:80 ama@host   # port forward
Say it like a pro

"Ping works but curl fails, so DNS and routing are fine and the service or firewall is the suspect."

systemctl systemd nginx.service journald journalctl A unit file says how to run it ExecStart=… User=… Restart=on-failure enable = start at boot · start = start now
PLATE 8 — systemd starts services, restarts them if they die, and keeps their logs.
Chapter 8 · Services & logs

Keep it running, and find out why it didn't

Control a service
$ systemctl status nginx
$ sudo systemctl start|stop|restart nginx
$ sudo systemctl reload nginx    # re-read config, no downtime
$ sudo systemctl enable --now nginx
$ systemctl --failed ; systemctl list-units --type=service
Read the logs
$ journalctl -u nginx -f          # follow one service
$ journalctl -p err -b            # errors since boot
$ journalctl --since "1 hour ago"
$ dmesg | tail                   # kernel messages
/etc/systemd/system/myapp.service
[Unit]
Description=My app
After=network.target
[Service]
User=ama
ExecStart=/usr/bin/python3 /opt/app/app.py
Restart=on-failure
[Install]
WantedBy=multi-user.target
Say it like a pro

"Status says failed, so I'll check journalctl for the exit code before I restart anything."

#!/usr/bin/env bash set -euo pipefail for f in *.log; do gzip "$f" done echo "done" cron 30 2 * * 1-5 minute hour day month weekday = 02:30, Monday to Friday
PLATE 9 — Write the steps once. Let cron run them forever.
Chapter 9 · Automation

Shell scripts and cron

A script is just commands in a file. Add a shebang, make it executable, and it behaves like any other program.

#!/usr/bin/env bash
set -euo pipefail            # stop on error / unset var / pipe fail
dir="${1:-/var/log}"          # arg 1, default /var/log
if [ ! -d "$dir" ]; then echo "no such dir" >&2; exit 1; fi
for f in "$dir"/*.log; do
  echo "$f: $(wc -l < "$f") lines"
done
Run it, schedule it
$ chmod +x report.sh && ./report.sh /var/log
$ crontab -e
30 2 * * 1-5 /home/ama/report.sh >> /tmp/report.log 2>&1
$ crontab -l ; echo $?       # 0 = success
quote
always "$var", so spaces don't split it
cron PATH
minimal; use full paths in jobs
Say it like a pro

"Strict mode, quoted variables, full paths, and log both streams, or cron will fail silently."