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.
"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.
Linux has a single directory tree. Extra disks and USB sticks are mounted onto a folder. Even hardware shows up as files under /dev.
$ 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
"Check /var/log, then diff the config in /etc against the package default."
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.
$ 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
--help is shorter"I'll grep the logs, sort and count by IP, and tail the top ten."
Every file has an owner and a group. ls -l shows the nine permission bits. The kernel checks them on every access.
$ 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
"Permission denied? Check the owner, the mode, and whether the parent directory is searchable."
A program that's running is a process. The kernel starts systemd first (PID 1), and everything else descends from it.
$ 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
uptime; compare to your CPU count"I sent SIGTERM first. It ignored it, so I escalated to SIGKILL."
Software comes from signed repositories. The package manager resolves dependencies, installs, and updates everything in one go.
| Task | Debian / Ubuntu | Fedora / RHEL |
|---|---|---|
| refresh | apt update | dnf check-update |
| upgrade | apt upgrade | dnf upgrade |
| install | apt install pkg | dnf install pkg |
| remove | apt remove pkg | dnf remove pkg |
| search | apt search word | dnf 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
"Update the index, install from the distro repo, and pin the version if prod can't drift."
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.
$ 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
-a you replace them!"Service accounts get no login shell and own only their own data directory."
$ 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
$ 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
"Ping works but curl fails, so DNS and routing are fine and the service or firewall is the suspect."
$ 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
$ journalctl -u nginx -f # follow one service $ journalctl -p err -b # errors since boot $ journalctl --since "1 hour ago" $ dmesg | tail # kernel messages
[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
"Status says failed, so I'll check journalctl for the exit code before I restart anything."
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
$ 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
"$var", so spaces don't split it"Strict mode, quoted variables, full paths, and log both streams, or cron will fail silently."