Read

Module 10 · Putting it all together

Final project and course review

The final exam: a review of all ten modules, a twelve-question theory test and three practical tasks that combine files, pipes, find and grep, permissions, scripting, archives and checksums.

What you will learn

  • Review the key commands of every module in one place.
  • Pass a theory test that spans the whole course.
  • Solve three practical problems that each need several modules at once.

Ninety-nine lessons ago a blinking prompt was a mystery. Now you can move around the filesystem, bend text through pipes, find anything, control who may touch what, watch and stop processes, inspect the system, pack and fetch files, and write scripts that do all of it for you. This last lesson is the final exam. Read the review, answer the twelve questions, and then solve the three practical tasks in the VM. None of them needs anything new; each one needs several things you already know, used together.

The course on one page

ModuleKey ideas and commands
1. First stepsPrompt, pwd, ls -la, cd, absolute vs relative paths, --help, Tab and history
2. Files and directoriesmkdir -p, touch, cp -r, mv, rm -r, cat, less, head, tail -f, wildcards
3. Text and pipes>, >>, 2>, 2>&1, |, wc, sort, uniq -c, cut, tr, tee, vi
4. Finding thingsgrep -inrvc, regular expressions, find -name -type -size -mtime, -exec, sed, awk
5. Users and permissionsid, /etc/passwd, adduser, su, rwx, chmod 750 / u+x, chown, umask
6. Processesps, top, &, jobs, fg, kill, signals, nice, nohup, /proc
7. System and environmentuname, free, df -h, du -sh, mount, dmesg, date, export, .profile
8. Archives and networktar cf/tf/xf, gzip, gunzip -c, ifconfig, ping, nslookup, wget, netstat
9. ScriptingShebang, variables and quotes, $( ), $(( )), if [ ], for, while, functions, $1 $# $@, exit
10. Putting it togetherln -s, alias, PATH, xargs -0, diff -u/patch, &&/||/{ }, crontab, sha256sum -c

How to approach the practical tasks

Build every solution step by step. Run the first command of a pipeline alone and look at its output, then add the next stage. Before you redirect into a file, print to the screen. Before a script is executable, run it with sh -x. When a check fails, go back to the checklist of lesson 99: read the message, look at $?, test the path. Absolute paths everywhere make your commands independent of where you happen to be.

~% find /root/lab/l100/logs -name '*.log'
~% find /root/lab/l100/logs -name '*.log' | xargs grep -h ERROR
~% find /root/lab/l100/logs -name '*.log' | xargs grep -h ERROR | sort -u
~% … > /root/lab/l100/errors.txt     # only when the screen output is right

Remember two quirks of this VM while you work. BusyBox tar has no z option, so a .tar.gz is made in two steps, tar cf - DIR | gzip > file.tar.gz, and listed with gunzip -c file.tar.gz | tar tf -. And there is no bash: scripts start with #!/bin/sh and use POSIX syntax, exactly as you learned in module 9.

Where to go next

Everything here was BusyBox, the smallest common denominator. On a full distribution such as Debian, Fedora or Alpine you will find the same commands with more options, man pages for each of them, bash with arrays and [[ ]], a package manager (apt, dnf, apk) and systemd services instead of a bare crond. The habits transfer unchanged: read the usage line, test small, pipe small tools together, quote your variables and keep a backup before you change anything. Congratulations on finishing the course.

Commands in this lesson

CommandWhat it does
find DIR -name '*.log' | xargs grep -h PATTERNSearch matching files, lines only.
sort -uSort and drop duplicates.
chmod 750 script.shrwx owner, r-x group, nothing for others.
tar cf - DIR | gzip > DIR.tar.gzCompressed archive with BusyBox tar.
gunzip -c F.tar.gz | tar tf -List a compressed archive.
sha256sum F > F.sha256Publish a checksum next to a file.
ln -s F latestStable name pointing at the current version.

Quiz

  1. (Module 1) You are in `/root/lab/project`. Where does `cd ../..` take you?

    • `/root/lab`
    • `/root`
    • `/`
    • `/root/lab/project/..`, which is an error
  2. (Module 2) `docs` is an existing directory. What does `mv report.txt docs` do?

    • Renames report.txt to a file called docs, destroying the directory
    • Moves report.txt into docs/
    • Fails because docs exists
  3. (Module 3) Which line saves both normal output and errors of `cmd` into `all.log`?

    • `cmd 2>&1 > all.log`
    • `cmd > all.log 2>&1`
    • `cmd | all.log`
  4. (Module 3) What does `cut -d: -f1 /etc/passwd | sort | uniq -c | sort -rn | head -3` show?

    • The three most frequent values of the first field, with their counts
    • The first three lines of /etc/passwd
    • The three longest user names
  5. (Module 4) Which command prints the lines of `app.conf` that are neither comments nor blank?

    • `grep '^#' app.conf`
    • `grep -v '^#' app.conf | grep -v '^ `
    • `grep -c '#' app.conf`
  6. (Module 4) Which finds regular files under /var bigger than 1 MB?

    • `find /var -type f -size +1024k`
    • `find /var -name +1M`
    • `ls -lS /var | head`
  7. (Module 5) After `chmod 750 deploy.sh`, what can members of the file's group do?

    • Read, write and execute
    • Read and execute
    • Nothing
  8. (Module 6) What is the difference between `kill PID` and `kill -9 PID`?

    • None
    • `kill` sends TERM, which the program can catch to clean up; `-9` sends KILL, which cannot be caught
    • `-9` kills nine processes
  9. (Module 7) `df -h` and `du -sh` answer different questions. Which pairing is right?

    • df: how full each filesystem is; du: how much space a directory uses
    • df: memory; du: disk
    • Both list files by size
  10. (Module 8) How do you see what is inside `backup.tar` without extracting it?

    • `tar xf backup.tar`
    • `tar tf backup.tar`
    • `cat backup.tar`
  11. (Module 9) Inside a script run as `./s.sh a "b c"`, what is `$#`?

    • 3
    • 2
    • 1
    • `a b c`
  12. (Module 10) A symlink `latest -> app-2.1.tar.gz` and you delete `app-2.1.tar.gz`. Then…

    • `latest` still holds the data
    • `latest` dangles: it exists but leads nowhere
    • `latest` is deleted automatically

Practice

  1. Log hunt (find, grep, pipes). Under `/root/lab/l100/logs` there are `.log` files in several subdirectories, plus other files you must ignore. Write into `/root/lab/l100/errors.txt` every line containing `ERROR` from the `.log` files only, without file names, sorted alphabetically and without duplicates.

  2. A tool (scripting, permissions). Write `/root/lab/l100/bin/lines.sh`: given a file as its first argument it prints `FILE: N lines` (for example `/etc/passwd: 12 lines`); with no argument, or if the argument is not an existing file, it prints a usage message to stderr and exits with status 1. Its permissions must be exactly `rwxr-x---` (750).

  3. A release (archives, checksums, links). Package `/root/lab/l100/project` as `/root/lab/l100/release/project.tar.gz` (paths inside must start with `project/`), save its SHA-256 sum in `/root/lab/l100/release/project.tar.gz.sha256` so that `sha256sum -c` run in `release` passes, and create a symbolic link `/root/lab/l100/release/latest.tar.gz` pointing to `project.tar.gz`.

Open this lesson in the app to do the tasks in a real Linux machine and have them checked.