Linux Intermediate 06 — Boot, Services, Logs, and Timers

Linux course index · Linux Intermediate category · Lesson 6 of 9

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Trace the boot-to-service path, inspect logs, and create a timer that runs a tiny user service.

Concepts and setup

Firmware loads a boot path, a bootloader typically loads the kernel, and the kernel starts the first userspace process. On a systemd system, targets group units. A unit can be loaded but inactive, or active without being enabled for the next boot. journalctl adds time and unit filters when you need evidence.

This recreates the site’s periodic shell-log idea using a systemd user timer. Use a VM with a working user session and user journal, not a bare container. Without user lingering, a user manager may stop after logout. Do not enable linger for this exercise.

Inspect boot and one service

ps -p 1 -o comm=
systemctl get-default
systemctl --failed --no-pager
journalctl -b -n 3 --no-pager

Possible output

systemd
multi-user.target
0 loaded units listed.
Nov 16 14:00:05 labhost systemd[1]: Startup finished ...

Log access depends on permissions, and a desktop may show graphical.target. -b narrows logs to the current boot. Read the service’s exact unit before restarting it.

Run and remove a user timer

mkdir -p ~/.config/systemd/user
cat > ~/.config/systemd/user/oe-linux-tick.service <<'EOF'
[Unit]
Description=Open Education Linux lab tick
[Service]
Type=oneshot
ExecStart=/usr/bin/echo linux-lab-tick
EOF
cat > ~/.config/systemd/user/oe-linux-tick.timer <<'EOF'
[Unit]
Description=Run Open Education tick once
[Timer]
OnActiveSec=5s
AccuracySec=1s
EOF
systemctl --user daemon-reload
systemctl --user start oe-linux-tick.timer
systemctl --user list-timers --all | grep oe-linux-tick
# Wait about six seconds before running the following command.
journalctl --user -u oe-linux-tick.service -n 5 --no-pager
systemctl --user stop oe-linux-tick.timer
rm ~/.config/systemd/user/oe-linux-tick.{service,timer}
systemctl --user daemon-reload

Possible output

... oe-linux-tick.timer oe-linux-tick.service
Nov 16 14:01:07 labhost echo[3100]: linux-lab-tick

Use the oe-linux-tick name only if no files by that name already exist. The timer triggers the same-base-name service. An inactive oneshot after successful completion is normal. For repeated scheduling, add a suitable recurring timer expression rather than a busy shell loop.

Questions only

Quick-check questions

  1. What is the difference between active and enabled?
  2. Why run daemon-reload after writing a unit?

Assessment questions

  1. Show current-boot logs for the system unit ssh.service.
  2. Why might an Ubuntu SSH unit name differ from a Red Hat-family one?
  3. Where do you look if a timer appears active but the intended command failed?

Questions and answers

Quick-check answers

  1. What is the difference between active and enabled?
    Answer — Active means running or active in the unit’s defined sense now. Enabled means configured for start through an enablement relationship.
  2. Why run daemon-reload after writing a unit?
    Answer — It makes the manager reread changed unit definitions.

Assessment answer key

  1. Show current-boot logs for the system unit ssh.service.
    Answer — journalctl -b -u ssh.service –no-pager. First confirm that ssh.service is the unit name on your system.
  2. Why might an Ubuntu SSH unit name differ from a Red Hat-family one?
    Answer — Distributions package services with different names. Discover them with systemctl list-unit-files ‘ssh*.service’.
  3. Where do you look if a timer appears active but the intended command failed?
    Answer — Check the matching service’s status and journal and inspect list-timers for the actual trigger.

Source articles on this site

Continue the course

Previous lesson 05 — Package Managers and Repositories. Next lesson 07 — IP Addresses, Routes, and Name Resolution.

Linux course index · Linux Intermediate category · Lesson 6 of 9

Linux Intermediate 05 — Package Managers and Repositories

Linux course index · Linux Intermediate category · Lesson 5 of 9

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Inspect installed packages and repositories before taking action, and tell a package database from a dependency resolver.

Concepts and setup

On Debian and Ubuntu, dpkg tracks installed packages and apt resolves dependencies from repositories. On Red Hat-family systems, rpm is the low-level package tool and dnf manages repositories and dependencies. Older posts use yum and describe historical behavior. Follow the installed release’s documentation rather than assuming their commands behave identically.

A repository is not just a folder of packages. The package manager reads repository metadata and verifies signatures according to its trust policy. The archive’s FTP-based repository demonstration is historical. Use approved repositories and do not bypass verification to make a lab work.

Check software provenance on Ubuntu or Debian

dpkg-query -W -f='${Package} ${Version}\n' bash
apt-cache policy bash
apt-get -s install bash

Possible output

bash 5.2.21-2ubuntu4
bash:
  Installed: 5.2.21-2ubuntu4
  Candidate: 5.2.21-2ubuntu4
0 upgraded, 0 newly installed, 0 to remove ...

In the first command write the format exactly as displayed. The simulation plans changes but does not install packages. An available upgrade would produce a different plan. Mark the distribution, versions, and approved origin in your notes.

Inspect a Red Hat-family lab instead

rpm -q bash
dnf repolist
dnf info bash

Possible output

bash-5.1.8-EXAMPLE.x86_64
repo id                     repo name
baseos                      BaseOS
appstream                   AppStream
Installed Packages
Name        : bash

EXAMPLE is a placeholder, not a release number. Repository IDs vary. dnf may refresh cache metadata. Nothing in this walkthrough installs or removes a package.

Questions only

Quick-check questions

  1. Does rpm -q bash search the internet for updates?
  2. Why does repository trust matter even when a package name looks right?

Assessment questions

  1. Before upgrading bash, which Ubuntu command previews where a candidate comes from?
  2. Your Red Hat-family system does not list an expected repository. Which nonmutating checks come first?
  3. Why prefer a dependency resolver to installing individual local packages with rpm?

Questions and answers

Quick-check answers

  1. Does rpm -q bash search the internet for updates?
    Answer — No. It queries the local RPM database.
  2. Why does repository trust matter even when a package name looks right?
    Answer — Anyone can name a package bash. Trusted signatures and repository policy help establish provenance.

Assessment answer key

  1. Before upgrading bash, which Ubuntu command previews where a candidate comes from?
    Answer — apt-cache policy bash shows installed and candidate versions plus origins. apt-get -s install bash previews a transaction.
  2. Your Red Hat-family system does not list an expected repository. Which nonmutating checks come first?
    Answer — Start with dnf repolist and compare expected repository IDs and enabled states with the distribution’s configured sources. Do not disable signature checks.
  3. Why prefer a dependency resolver to installing individual local packages with rpm?
    Answer — A resolver can evaluate required packages, compatible versions, and the wider transaction.

Source articles on this site

Continue the course

Previous lesson 04 — Bash Conditions, Loops, Functions, and Debugging. Next lesson 06 — Boot, Services, Logs, and Timers.

Linux course index · Linux Intermediate category · Lesson 5 of 9

Linux Intermediate 04 — Bash Conditions, Loops, Functions, and Debugging

Linux course index · Linux Intermediate category · Lesson 4 of 9

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Use a case statement, a function, and a loop to generate a multiplication chart and test invalid input.

Concepts and setup

if tests a command’s exit status. case matches a value against shell patterns. for iterates a sequence and while repeats while a condition succeeds. until repeats while its condition fails. Bash functions can use local variables, accept arguments, and return status. Write results to stdout and errors to stderr so another program can use the output.

The site has separate while- and for-loop versions of this multiplication chart. This version checks the argument once and reuses one function rather than copying the same logic into ten case branches.

Build a chart and check the failure path

lab=$(mktemp -d)
cd "$lab" || exit
cat > chart.sh <<'EOF'
#!/usr/bin/env bash
chart() {
  local n=$1 i
  for ((i=1; i<=10; i++)); do
    printf '%d * %d = %d\n' "$n" "$i" "$((n*i))"
  done
}
case "$1" in
  [1-9]|10) chart "$1" ;;
  *) printf 'Usage: %s NUMBER (1-10)\n' "$0" >&2; exit 2 ;;
esac
EOF
bash -n chart.sh
bash chart.sh 9 > chart.txt
head -n 2 chart.txt
tail -n 1 chart.txt
bash chart.sh 11
printf 'status=%s\n' "$?"

Possible output

9 * 1 = 9
9 * 2 = 18
9 * 10 = 90
Usage: chart.sh NUMBER (1-10)
status=2

bash -n checks syntax but does not execute the script. bash -x shows command expansions when diagnosing a lab script. Avoid tracing scripts that handle secrets.

Verify the loop boundary

wc -l < chart.txt
grep -Fx '9 * 10 = 90' chart.txt
bash -x chart.sh 2 > two.txt 2> trace.txt
tail -n 1 two.txt

Possible output

10
9 * 10 = 90
2 * 10 = 20

Checking both the line count and the last value helps catch off-by-one errors.

Questions only

Quick-check questions

  1. When does the wildcard case branch run?
  2. What does bash -n detect that it cannot prove about output?

Assessment questions

  1. Rewrite the for loop as a while loop.
  2. What should be tested for arguments 1, 10, and 0?
  3. How would you save compiler-like traces without mixing them with chart output?

Questions and answers

Quick-check answers

  1. When does the wildcard case branch run?
    Answer — When none of the earlier patterns match, including when no argument is given.
  2. What does bash -n detect that it cannot prove about output?
    Answer — It detects syntax errors. It cannot prove the chart contains correct values.

Assessment answer key

  1. Rewrite the for loop as a while loop.
    Answer — Set local i=1, then use while ((i<=10)); do, print the row, increment i with ((i++)), and end with done.
  2. What should be tested for arguments 1, 10, and 0?
    Answer — 1 and 10 should succeed with 10 rows and correct endpoints. 0 should produce usage on stderr with status 2.
  3. How would you save compiler-like traces without mixing them with chart output?
    Answer — Run bash -x chart.sh 2 > two.txt 2> trace.txt in the lab.

Source articles on this site

Continue the course

Previous lesson 03 — Bash Variables, Quoting, and Input. Next lesson 05 — Package Managers and Repositories.

Linux course index · Linux Intermediate category · Lesson 4 of 9

Linux Intermediate 03 — Bash Variables, Quoting, and Input

Linux course index · Linux Intermediate category · Lesson 3 of 9

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Write Bash variables, capture a command result, and accept input without losing spaces or misinterpreting nonnumeric input.

Concepts and setup

Use name=value with no spaces around the equals sign. Single quotes preserve literal text. Double quotes still allow expansions while keeping the result a single argument. read -r keeps backslashes and IFS= avoids trimming leading or trailing whitespace. Export a variable only when child processes need to see it.

This adapts the site’s Korn shell date example and its two-number Bash arithmetic example. The two-digit validation in this lab keeps arithmetic bounded and a decimal prefix prevents accidental octal interpretation.

Capture the date and preserve a value with spaces

day=$(date +%F)
printf 'Today is %s.\n' "$day"
name='weekly report'
printf '<%s>\n' "$name"
printf '%s\n' '$name'
export name
bash -c 'printf "child sees: %s\n" "$name"'

Possible output

Today is 2026-11-16.
<weekly report>
$name
child sees: weekly report

The date is illustrative. printf has a fixed format string and one quoted argument. The child process sees name because it was exported.

Build a decimal arithmetic script

lab=$(mktemp -d)
cd "$lab" || exit
cat > calc.sh <<'EOF'
#!/usr/bin/env bash
IFS= read -r a || exit 2
IFS= read -r b || exit 2
if ! [[ $a =~ ^[0-9]{1,2}$ && $b =~ ^[0-9]{1,2}$ ]]; then
  printf 'Enter two integers from 0 to 99\n' >&2
  exit 2
fi
a=$((10#$a))
b=$((10#$b))
printf 'sum=%d product=%d\n' "$((a+b))" "$((a*b))"
if (( b == 0 )); then
  printf 'division skipped: zero divisor\n'
else
  printf 'integer quotient=%d\n' "$((a/b))"
fi
EOF
printf '20\n05\n' | bash calc.sh
printf '8\n0\n' | bash calc.sh

Possible output

sum=25 product=100
integer quotient=4
sum=8 product=0
division skipped: zero divisor

The quoted heredoc sends the script verbatim to cat. Use Bash to run it because [[ ]] and the arithmetic details here are Bash-specific.

Questions only

Quick-check questions

  1. Why do we use read -r?
  2. What does double quoting "$name" protect against?

Assessment questions

  1. Predict the output with inputs 9 and 2. Why not 4.5?
  2. What should the script return when fed an empty field?
  3. Add a line that prints a decimal remainder without dividing by zero.

Questions and answers

Quick-check answers

  1. Why do we use read -r?
    Answer — It prevents read from treating backslashes as escapes.
  2. What does double quoting "$name" protect against?
    Answer — It keeps the expanded value as one argument and prevents pathname expansion on that value.

Assessment answer key

  1. Predict the output with inputs 9 and 2. Why not 4.5?
    Answer — sum=11 product=18 and integer quotient=4. Bash arithmetic here uses integer division.
  2. What should the script return when fed an empty field?
    Answer — 2 for invalid input or a missing input line.
  3. Add a line that prints a decimal remainder without dividing by zero.
    Answer — Inside the nonzero-divisor branch, add printf ‘remainder=%d\n’ "$((a%b))".

Source articles on this site

Technical references

Continue the course

Previous lesson 02 — Access Control Lists and Shared Directories. Next lesson 04 — Bash Conditions, Loops, Functions, and Debugging.

Linux course index · Linux Intermediate category · Lesson 3 of 9

Linux Intermediate 02 — Access Control Lists and Shared Directories

Linux course index · Linux Intermediate category · Lesson 2 of 9

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Grant and remove a narrowly scoped named-user ACL and distinguish a grant from effective access.

Concepts and setup

In an extended POSIX ACL, the mask caps permissions for the owning group and named nonowner entries. Access ACLs affect the object itself. Default ACLs exist on directories and can affect newly created children. They do not rewrite children that already exist. A named-user grant on a file is not enough if the user cannot traverse its parents.

Use a VM with getfacl and setfacl installed. This demonstrates policy on a fixture, not access through the private mktemp parent. The command uses the numeric ID of the local nobody account only for a lab fixture.

Grant, limit, and remove a named-user entry

getent passwd nobody
lab=$(mktemp -d)
cd "$lab" || exit
printf 'training report\n' > report.txt
chmod 600 report.txt
guest=$(id -u nobody)
setfacl -m "u:$guest:rw-" report.txt
setfacl -m m::r-- report.txt
getfacl -n report.txt
setfacl -x "u:$guest" report.txt
getfacl -n report.txt

Possible output

# file: report.txt
# owner: 1000
# group: 1000
user::rw-
user:65534:rw-           #effective:r--
group::---
mask::r--
other::---
...
user::rw-
group::---
mask::---
other::---

Output omits the getent line and includes an illustrative numeric ID. After removing the named entry, the mask can still be present. Inspect the remaining entries rather than inferring that every access path is gone.

Compare a default ACL with the child’s access ACL

mkdir shared
setfacl -m "d:u:$guest:r-x" shared
touch shared/new.txt
getfacl -cn shared | grep '^default:user:'
getfacl -cn shared/new.txt | grep -E '^(user:[0-9]+:|mask::)'

Possible output

default:user::rwx
default:user:65534:r-x
user:65534:r-x           #effective:r--
mask::rw-

The new regular file’s creation mode can limit inherited permissions. Removing the default entry on shared will not remove an ACL on new.txt.

Questions only

Quick-check questions

  1. What does the mask mean for a named rw- grant?
  2. What is the difference between an access ACL and a default ACL?

Assessment questions

  1. Remove the named default ACL from shared without changing other entries.
  2. Why might the user still be unable to read the file after an ACL shows r–?
  3. Can removal of a named entry guarantee the user has no access? Explain.

Questions and answers

Quick-check answers

  1. What does the mask mean for a named rw- grant?
    Answer — Only the permitted intersection is effective. A mask of r– removes effective write.
  2. What is the difference between an access ACL and a default ACL?
    Answer — An access ACL is checked on its object. A default ACL can be inherited by new children.

Assessment answer key

  1. Remove the named default ACL from shared without changing other entries.
    Answer — setfacl -x "d:u:$guest" shared. Check the child separately.
  2. Why might the user still be unable to read the file after an ACL shows r–?
    Answer — A parent may lack traverse permission, or another policy such as SELinux may deny access.
  3. Can removal of a named entry guarantee the user has no access? Explain.
    Answer — No. Ownership, an owning-group rule, another group rule, or the others entry can independently matter. Check effective access as the intended user.

Source articles on this site

Continue the course

Previous lesson 01 — Users, Groups, sudo, and Special Permissions. Next lesson 03 — Bash Variables, Quoting, and Input.

Linux course index · Linux Intermediate category · Lesson 2 of 9

Linux Intermediate 01 — Users, Groups, sudo, and Special Permissions

Linux course index · Linux Intermediate category · Lesson 1 of 9

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Inspect identity records, understand sudo, and build a group-inheriting directory in a disposable VM.

Concepts and setup

UIDs and GIDs identify users and groups. Primary and supplementary groups can both matter. Query through getent instead of assuming every account lives in /etc/passwd. Never display or copy /etc/shadow into a report. Use sudo for a scoped task instead of working in a root shell. Administrative group policy differs by distribution, commonly sudo on Ubuntu and wheel on Red Hat-family systems. Verify the real sudo policy with sudo -l.

SUID on eligible executables can change the effective UID. Inspect it read-only on system programs. SGID on a directory makes new entries inherit the directory’s group. The sticky bit limits who can delete or rename entries in a shared writable directory.

Inspect the current identity and special bits without changing privileges

id
getent passwd "$(id -un)" | cut -d: -f1,3,4,6,7
stat -c '%a %A %n' /tmp
stat -c '%a %A %n' "$(command -v passwd)"

Possible output

uid=1000(learner) gid=1000(learner) groups=1000(learner),27(sudo)
learner:1000:1000:/home/learner:/bin/bash
1777 drwxrwxrwt /tmp
4755 -rwsr-xr-x /usr/bin/passwd

This illustrates common layouts. Do not change /tmp or the passwd binary. Lowercase s or t means the corresponding execute bit is also set.

Verify SGID group inheritance on a directory you own

lab=$(mktemp -d)
mkdir "$lab/shared"
chgrp "$(id -gn)" "$lab/shared"
chmod 2770 "$lab/shared"
touch "$lab/shared/report.txt"
stat -c '%a %A %G %n' "$lab/shared" "$lab/shared/report.txt"

Possible output

2770 drwxrws--- learner /tmp/tmp.ABC/shared
644 -rw-r--r-- learner /tmp/tmp.ABC/shared/report.txt

Actual paths, modes, and groups vary. SGID controls group inheritance, not guaranteed group write access. A directory inside this private temporary parent is not reachable by other users. Use an explicit ACL or a suitable group-owned parent in a shared lab.

Questions only

Quick-check questions

  1. What does getent do that reading a single local file might not?
  2. Does SGID on a directory make every new file writable by the group?

Assessment questions

  1. Why is -a important if a lab admin runs usermod -aG project labuser?
  2. What special bit often appears on /tmp, and what does it restrict?
  3. How would you verify the identity and policies of a newly authorized lab admin without exposing password data?

Questions and answers

Quick-check answers

  1. What does getent do that reading a single local file might not?
    Answer — It consults the configured name service, which may include nonlocal account records.
  2. Does SGID on a directory make every new file writable by the group?
    Answer — No. Group ownership inheritance and file write permission are separate.

Assessment answer key

  1. Why is -a important if a lab admin runs usermod -aG project labuser?
    Answer — It appends to supplementary groups rather than replacing the existing list. Existing sessions may need a fresh login.
  2. What special bit often appears on /tmp, and what does it restrict?
    Answer — The sticky bit limits deletion or renaming to authorized cases such as the entry owner, directory owner, or a privileged process.
  3. How would you verify the identity and policies of a newly authorized lab admin without exposing password data?
    Answer — Start a fresh session as the lab user. Use id and sudo -l to confirm groups and authorized commands.

Source articles on this site

Continue the course

Next lesson 02 — Access Control Lists and Shared Directories.

Linux course index · Linux Intermediate category · Lesson 1 of 9

Linux Basics 08 — Archives, Compression, and a Restore Test

Linux course index · Linux Basics category · Lesson 8 of 8

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Create and inspect an archive, then prove that you can recover a file from it.

Concepts and setup

An archive groups files and their metadata. Compression reduces size, along with the ability to inspect or restore only as supported by the format. tar -z uses gzip and tar -t lists members without extracting them. 7-Zip is another archive tool discussed on the site. This exercise adapts the site’s timed tar and selective restore script to your own lab data rather than copying real system configuration.

Archive a lab folder and restore one file

lab=$(mktemp -d)
cd "$lab" || exit
mkdir -p project restore
printf 'service=demo\n' > project/settings.txt
printf 'release notes\n' > project/notes.txt
tar -czf project.tgz -C project settings.txt notes.txt
tar -tzf project.tgz
tar -xzf project.tgz -C restore settings.txt
cmp project/settings.txt restore/settings.txt &&
  printf 'restore matches the original\n'

Possible output

settings.txt
notes.txt
restore matches the original

-C changes directory for the tar operation, and the member names do not include project/. Do not extract an untrusted archive over existing files. Inspect its member names and use an isolated destination.

Record an integrity check

sha256sum project.tgz > project.tgz.sha256
sha256sum -c project.tgz.sha256
ls -1 restore

Possible output

project.tgz: OK
settings.txt

An integrity checksum tells you whether this artifact matches a known digest. It does not authenticate an archive if an attacker can also replace the checksum file.

Questions only

Quick-check questions

  1. Which command lists the gzip archive without extracting?
  2. Did this restore extract notes.txt?

Assessment questions

  1. Change the extraction command to restore both members into a fresh directory.
  2. Explain why keeping only an archive on the same laptop is not enough for disaster recovery.
  3. Name a stronger acceptance test than archive creation returned 0.

Questions and answers

Quick-check answers

  1. Which command lists the gzip archive without extracting?
    Answer — tar -tzf project.tgz.
  2. Did this restore extract notes.txt?
    Answer — No. settings.txt was the only requested member.

Assessment answer key

  1. Change the extraction command to restore both members into a fresh directory.
    Answer — Run mkdir restore-all followed by tar -xzf project.tgz -C restore-all.
  2. Explain why keeping only an archive on the same laptop is not enough for disaster recovery.
    Answer — One failure or loss can take out both the original and archive. Keep a separate protected copy.
  3. Name a stronger acceptance test than archive creation returned 0.
    Answer — Restore selected content into a clean location and compare it to the expected data.

Source articles on this site

Continue the course

Previous lesson 07 — Processes, Jobs, and Signals. This is the last lesson in this level. See the course index for the next level.

Linux course index · Linux Basics category · Lesson 8 of 8

Linux Basics 07 — Processes, Jobs, and Signals

Linux course index · Linux Basics category · Lesson 7 of 8

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Identify a process you own, inspect its state, and stop it gracefully.

Concepts and setup

A program is code. A process is a running instance with a process ID (PID). A shell job is the shell’s record of one or more processes started together. top refreshes a system view, while ps shows a snapshot. Use a specific PID rather than a broad name match when acting on a process.

SIGTERM requests termination and can be caught by a process. SIGKILL is not catchable, so it prevents normal cleanup. The older source lists both. This lab starts and terminates only its own sleep process.

Start a job and verify termination

sleep 120 &
pid=$!
jobs -l
ps -p "$pid" -o pid,ppid,stat,comm
kill -TERM "$pid"
wait "$pid"
status=$?
printf 'wait status: %s\n' "$status"
ps -p "$pid" -o pid= || printf 'process no longer listed\n'

Possible output

[1]+  3184 Running                 sleep 120 &
    PID    PPID STAT COMMAND
   3184    3142 S    sleep
wait status: 143
process no longer listed

Run interactively in Bash. PID and job notifications vary. The common Bash status 143 is 128 plus signal number 15. wait handles the shell’s own child.

Inspect the shell’s process context

ps -p "$$" -o pid,ppid,stat,comm
uptime

Possible output

    PID    PPID STAT COMMAND
   3142    3072 Ss   bash
 14:09:38 up  2:12,  1 user,  load average: 0.07, 0.04, 0.01

Use the same shell when comparing its PID to the child’s PPID. Load average is not a simple percentage of CPU use.

Questions only

Quick-check questions

  1. What does $! contain after sleep 120 &?
  2. Why try SIGTERM before SIGKILL?

Assessment questions

  1. Name two fields from ps useful for checking the target before a signal.
  2. What happens if you use wait for a PID that is not a child of this shell?
  3. Explain why jobs in a new terminal does not list the old terminal’s sleep job.

Questions and answers

Quick-check answers

  1. What does $! contain after sleep 120 &?
    Answer — It contains the PID of the most recent background job’s last process, which is sleep here.
  2. Why try SIGTERM before SIGKILL?
    Answer — The process can handle SIGTERM and clean up. It cannot catch SIGKILL.

Assessment answer key

  1. Name two fields from ps useful for checking the target before a signal.
    Answer — PID and command name are a start. Verify owner and parent as needed.
  2. What happens if you use wait for a PID that is not a child of this shell?
    Answer — Bash normally reports that it is not a child and returns 127.
  3. Explain why jobs in a new terminal does not list the old terminal’s sleep job.
    Answer — The job table belongs to the shell that created the job.

Source articles on this site

Continue the course

Previous lesson 06 — File Permissions and umask. Next lesson 08 — Archives, Compression, and a Restore Test.

Linux course index · Linux Basics category · Lesson 7 of 8

Linux Basics 06 — File Permissions and umask

Linux course index · Linux Basics category · Lesson 6 of 8

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Read a permission string, predict umask results, and choose a minimal permission change.

Concepts and setup

Permissions are grouped into owner, group, and others. Read, write, and execute are 4, 2, and 1. A directory’s execute bit is search or traversal permission. Deleting a name normally depends on the parent directory’s permissions rather than the file’s write bit. A sticky directory can further restrict deletion.

The site’s 666 versus 777 example refers to the creation modes a program typically requests for regular files and directories. It is not a hard limit. umask clears requested bits. A parent default ACL can change creation-mode behavior, so use an ordinary lab filesystem for this drill.

Reproduce the umask example with fixed settings

lab=$(mktemp -d)
cd "$lab" || exit
( umask 022; touch file1.txt; mkdir dir1 )
stat -c '%a %A %n' file1.txt dir1
chmod g+w,o-r file1.txt
stat -c '%a %A %n' file1.txt
chmod 640 file1.txt
stat -c '%a %A %n' file1.txt

Possible output

644 -rw-r--r-- file1.txt
755 drwxr-xr-x dir1
660 -rw-rw---- file1.txt
640 -rw-r----- file1.txt

The subshell confines the changed umask. Numeric mode sets all three ordinary groups. A symbolic change can touch only the selected bits.

Apply a private creation mask

( umask 077; touch private.txt; mkdir private-dir )
stat -c '%a %n' private.txt private-dir

Possible output

600 private.txt
700 private-dir

For a shareable directory, choose group and traversal access deliberately rather than making it writable by everyone.

Questions only

Quick-check questions

  1. Why do ordinary new text files not execute by default?
  2. What does chmod g+w change?

Assessment questions

  1. Predict the default regular-file and directory modes for umask 027.
  2. Give the owner read/write and the group read access, with no access for others.
  3. Why might a directory with read but no execute permission list names but not let you open a named file?

Questions and answers

Quick-check answers

  1. Why do ordinary new text files not execute by default?
    Answer — The creating program normally requests 0666 rather than 0777.
  2. What does chmod g+w change?
    Answer — It adds write permission to the file’s group class without changing other bits.

Assessment answer key

  1. Predict the default regular-file and directory modes for umask 027.
    Answer — The usual results are 640 and 750 when there is no default ACL.
  2. Give the owner read/write and the group read access, with no access for others.
    Answer — chmod 640 file1.txt.
  3. Why might a directory with read but no execute permission list names but not let you open a named file?
    Answer — Reading lists names. Search permission is needed to traverse the directory and look up the named entry.

Source articles on this site

Continue the course

Previous lesson 05 — Finding Files and Filtering Text. Next lesson 07 — Processes, Jobs, and Signals.

Linux course index · Linux Basics category · Lesson 6 of 8

Linux Basics 05 — Finding Files and Filtering Text

Linux course index · Linux Basics category · Lesson 5 of 8

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Choose find for names, grep for lines, cut for fields, and sed for transforming text.

Concepts and setup

The site filters signed integers, tests Canadian postal-code shape, and selects account fields with cut. In the lab we use synthetic data. A postal-code shape check does not prove that a location or postal code exists. LC_ALL=C makes the ASCII-oriented regex and sort behave consistently. Quote patterns so the shell does not expand them.

Filter lines and fields without touching system files

lab=$(mktemp -d)
cd "$lab" || exit
printf '%s\n' '-7' '+12' '3.5' 'abc' > data.txt
printf '%s\n' 'M4C 5L7' 'm4c 5l7' 'wrong' > postal.txt
printf '%s\n' 'learner:x:1000' 'helper:x:1001' > accounts.txt
LC_ALL=C grep -E '^[+-]?[0-9]+$' data.txt
LC_ALL=C grep -E '^[A-Z][0-9][A-Z] ?[0-9][A-Z][0-9]$' postal.txt
cut -d ':' -f 1,3 accounts.txt | sed 's/^helper:/trainee:/'

Possible output

-7
+12
M4C 5L7
learner:1000
trainee:1001

The source uses egrep. grep -E is the straightforward modern spelling. sed writes the replacement to stdout and leaves accounts.txt unchanged.

Filter by file name

mkdir reports
cp data.txt reports/raw.txt
find reports -type f -name '*.txt' -print
grep -n '3[.]5' reports/raw.txt

Possible output

reports/raw.txt
3:3.5

Quoted *.txt reaches find as a pattern. In contrast, grep -n displays the line number of a content match.

Questions only

Quick-check questions

  1. What do ^ and $ mean in this regex?
  2. Why did the plain sed command leave the file unchanged?

Assessment questions

  1. Change the signed-integer pattern to accept only unsigned integers.
  2. Use cut to print the username and ID from colon-delimited accounts.txt.
  3. Distinguish the three exit statuses of GNU grep in ordinary use.

Questions and answers

Quick-check answers

  1. What do ^ and $ mean in this regex?
    Answer — They anchor the start and end of a line.
  2. Why did the plain sed command leave the file unchanged?
    Answer — It prints transformed text to standard output without in-place editing.

Assessment answer key

  1. Change the signed-integer pattern to accept only unsigned integers.
    Answer — Use LC_ALL=C grep -E ‘^[0-9]+$’ data.txt. None of the four starter lines match.
  2. Use cut to print the username and ID from colon-delimited accounts.txt.
    Answer — cut -d ‘:’ -f 1,3 accounts.txt.
  3. Distinguish the three exit statuses of GNU grep in ordinary use.
    Answer — 0 means match, 1 means no match, and 2 indicates an error in ordinary use.

Source articles on this site

Continue the course

Previous lesson 04 — Pipes, Redirection, and Exit Status. Next lesson 06 — File Permissions and umask.

Linux course index · Linux Basics category · Lesson 5 of 8