Build the complete Assignment 5 manual on trusted branch pushes
Assignment 5 manual PDF / manual (push) Successful in 47s
Assignment 5 manual PDF / manual (push) Successful in 47s
This commit is contained in:
parent
fa9a32f8a9
commit
c74087a93b
@@ -0,0 +1,607 @@
|
||||
\chapter{Linux Command Problem Set}
|
||||
\ChapterLabel{LinuxProblemSet}
|
||||
\index{Linux!problem set}
|
||||
|
||||
\section{Execution Guidance}
|
||||
The following answers are written for the test environment created in \ChapterRef{LinuxCommands}. Commands were suggested by AI for the team to run, then verified by the team before execution; the team made changes as needed, ran the commands, and gathered the outputs. All problem-set commands and recorded outputs were executed and collected by humans, not by AI. Commands were executed from \texttt{/root/lx-test}.
|
||||
|
||||
\section{Problem Set}
|
||||
|
||||
\subsection*{A) Navigation \& File Ops}
|
||||
\begin{enumerate}[label=\textbf{\arabic*.},leftmargin=*,start=1]
|
||||
\item \textbf{Show your present working directory path only.}
|
||||
\index{Linux command!pwd}
|
||||
\begin{lstlisting}[language=bash]
|
||||
pwd
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
/root/lx-test
|
||||
\end{lstlisting}
|
||||
The command reports the current working directory used for the problem set.
|
||||
\item \textbf{List all entries in the current directory, one per line, including dotfiles.}
|
||||
\index{Linux command!ls}
|
||||
\begin{lstlisting}[language=bash]
|
||||
ls -a1
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
.
|
||||
..
|
||||
archive
|
||||
blob.bin
|
||||
link-to-file1
|
||||
old.txt
|
||||
people.csv
|
||||
src
|
||||
sys.log
|
||||
tmp
|
||||
words.txt
|
||||
\end{lstlisting}
|
||||
The `-a` option includes dotfiles and the `-1` option displays one entry per line.
|
||||
\item \textbf{Copy `src/file1.txt` to `tmp/` only if `tmp` exists; do it verbosely.}
|
||||
\index{Linux command!cp}
|
||||
\begin{lstlisting}[language=bash]
|
||||
[ -d tmp ] && cp -v src/file1.txt tmp/
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
'src/file1.txt' -> 'tmp/file1.txt'
|
||||
\end{lstlisting}
|
||||
The conditional copy runs only when `tmp` exists, and verbose mode reports the copy operation.
|
||||
\item \textbf{Move `old.txt` into `archive/` and keep its original timestamp.}
|
||||
\index{Linux command!mv}
|
||||
\begin{lstlisting}[language=bash]
|
||||
mv -v old.txt archive/
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
renamed 'old.txt' -> 'archive/old.txt'
|
||||
\end{lstlisting}
|
||||
The move is performed as a rename within the same filesystem, so the file's modification timestamp is retained.
|
||||
\item \textbf{Create a new empty file `notes.md` only if it does not already exist.}
|
||||
\index{Linux command!touch}
|
||||
\begin{lstlisting}[language=bash]
|
||||
[ -e notes.md ] || touch notes.md
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
(no terminal output)
|
||||
\end{lstlisting}
|
||||
The existence test prevents `touch` from changing an existing file's timestamp.
|
||||
\item \textbf{Show human-readable disk usage for the `src` directory only.}
|
||||
\index{Linux command!du}
|
||||
\begin{lstlisting}[language=bash]
|
||||
du -sh src
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
16K src
|
||||
\end{lstlisting}
|
||||
The command reports the allocated disk usage for `src` in human-readable form.
|
||||
\end{enumerate}
|
||||
|
||||
\subsection*{B) Viewing \& Searching}
|
||||
\begin{enumerate}[label=\textbf{\arabic*.},leftmargin=*,start=7]
|
||||
\item \textbf{Print line numbers while displaying `sys.log`.}
|
||||
\index{Linux command!nl}
|
||||
\begin{lstlisting}[language=bash]
|
||||
nl -ba sys.log
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
1 INFO boot ok
|
||||
2 WARN disk low
|
||||
3 ERROR fan fail
|
||||
4 INFO shutdown
|
||||
\end{lstlisting}
|
||||
The `-b` option numbers all lines, including blank lines if present.
|
||||
\item \textbf{Show only lines in `sys.log` containing `ERROR`, case-sensitively.}
|
||||
\index{Linux command!grep}
|
||||
\begin{lstlisting}[language=bash]
|
||||
grep 'ERROR' sys.log
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
ERROR fan fail
|
||||
\end{lstlisting}
|
||||
The pattern is matched with case sensitivity, so only matching lines are returned.
|
||||
\item \textbf{Count the distinct words in `words.txt`, case-insensitively.}
|
||||
\index{Linux command!sort}
|
||||
\begin{lstlisting}[language=bash]
|
||||
sort -fu words.txt | wc -l
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
3
|
||||
\end{lstlisting}
|
||||
Sorting with `-f` and `-u` provides a case-insensitive unique count.
|
||||
\item \textbf{Show lines in `words.txt` that start with `g` or `G`.}
|
||||
\index{Linux command!grep}
|
||||
\begin{lstlisting}[language=bash]
|
||||
grep -i '^g' words.txt
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
Gamma
|
||||
gamma
|
||||
\end{lstlisting}
|
||||
The case-insensitive anchored pattern selects lines beginning with the letter `g`.
|
||||
\item \textbf{Display the first two lines of `people.csv` without an editor.}
|
||||
\index{Linux command!head}
|
||||
\begin{lstlisting}[language=bash]
|
||||
head -n 2 people.csv
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
id,name,dept
|
||||
1,Ada,EE
|
||||
\end{lstlisting}
|
||||
The command returns the first two lines of the CSV.
|
||||
\item \textbf{Show the last three lines of `sys.log` and keep following if it grows.}
|
||||
\index{Linux command!tail}
|
||||
\begin{lstlisting}[language=bash]
|
||||
tail -n 3 -f sys.log
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
WARN disk low
|
||||
ERROR fan fail
|
||||
INFO shutdown
|
||||
^C
|
||||
\end{lstlisting}
|
||||
The command displays the current final three lines and then waits for additional lines until interrupted.
|
||||
\end{enumerate}
|
||||
|
||||
\subsection*{C) Text Processing}
|
||||
\begin{enumerate}[label=\textbf{\arabic*.},leftmargin=*,start=13]
|
||||
\item \textbf{Print only the second, name column from `people.csv`, excluding the header.}
|
||||
\index{Linux command!awk}
|
||||
\begin{lstlisting}[language=bash]
|
||||
awk -F, 'NR > 1 {print $2}' people.csv
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
Ada
|
||||
Linus
|
||||
Grace
|
||||
Dennis
|
||||
\end{lstlisting}
|
||||
The `awk` field separator is a comma, and records after the header print field 2.
|
||||
\item \textbf{Sort `words.txt` case-insensitively and remove duplicates.}
|
||||
\index{Linux command!tr}
|
||||
\begin{lstlisting}[language=bash]
|
||||
tr '[:upper:]' '[:lower:]' < words.txt | sort -u
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
alpha
|
||||
beta
|
||||
gamma
|
||||
\end{lstlisting}
|
||||
The pipeline lowercases the input before sorting uniquely.
|
||||
\item \textbf{Replace every `three` with `3` in all files under `src/` in place, creating `.bak` backups.}
|
||||
\index{Linux command!sed}
|
||||
\begin{lstlisting}[language=bash]
|
||||
find src -type f ! -name '*.bak' -exec sed -i.bak 's/three/3/g' {} +
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
(no terminal output)
|
||||
\end{lstlisting}
|
||||
The command edits matching files in place while excluding existing backup files and creating `.bak` copies.
|
||||
\textbf{Verification step:}
|
||||
\begin{lstlisting}
|
||||
$ cat src/file1.txt
|
||||
one two 3 four
|
||||
\end{lstlisting}
|
||||
The verification command is included as evidence of the resulting file state and is not part of the solution command.
|
||||
\item \textbf{Print the line, word, and byte counts for every `*.txt` file in `src/`.}
|
||||
\index{Linux command!wc}
|
||||
\begin{lstlisting}[language=bash]
|
||||
find src -type f -name '*.txt' -exec wc -l -w -c {} +
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
1 4 15 src/file1.txt
|
||||
1 4 16 src/file2.txt
|
||||
2 8 31 total
|
||||
\end{lstlisting}
|
||||
The command reports line, word, and byte counts for the matching text files and a total.
|
||||
\end{enumerate}
|
||||
|
||||
\subsection*{D) Permissions \& Ownership}
|
||||
\begin{enumerate}[label=\textbf{\arabic*.},leftmargin=*,start=17]
|
||||
\item \textbf{Make `tmp/` readable, writable, and searchable only by its owner.}
|
||||
\index{Linux command!chmod}
|
||||
\begin{lstlisting}[language=bash]
|
||||
chmod 700 tmp
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
(no terminal output)
|
||||
\end{lstlisting}
|
||||
Mode `700` grants the owner read, write, and execute \phantomsection\label{GlossaryRef:permissions}\gls{permissions} while granting none to group or others.
|
||||
\item \textbf{Give group execute permission to `src/lib` recursively without changing owner or other bits.}
|
||||
\index{Linux command!chmod}
|
||||
\begin{lstlisting}[language=bash]
|
||||
chmod -R g+x src/lib
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
(no terminal output)
|
||||
\end{lstlisting}
|
||||
The recursive `g+x` operation adds group execute permission without changing the other \gls{permissions}.
|
||||
\item \textbf{Show the numeric octal permissions of `src/file2.txt`.}
|
||||
\index{Linux command!stat}
|
||||
\begin{lstlisting}[language=bash]
|
||||
stat -c '%a' src/file2.txt
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
644
|
||||
\end{lstlisting}
|
||||
The command prints the file's numeric \gls{permissions} mode.
|
||||
\item \textbf{Make `notes.md` append-only via file attributes, if supported.}
|
||||
\index{Linux command!chattr}
|
||||
\begin{lstlisting}[language=bash]
|
||||
chattr +a notes.md && lsattr notes.md
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
-----a--------e------- notes.md
|
||||
\end{lstlisting}
|
||||
The command sets the append-only attribute and then displays the file attributes to verify it.
|
||||
\end{enumerate}
|
||||
|
||||
\section*{E) Links and Find}
|
||||
\begin{enumerate}[label=\textbf{\arabic*.},leftmargin=*,start=21]
|
||||
\item \textbf{Verify that `link-to-file1` is a symbolic link and show its target.}
|
||||
\index{Linux command!symbolic links}
|
||||
\begin{lstlisting}[language=bash]
|
||||
[ -L link-to-file1 ] && readlink link-to-file1
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
src/file1.txt
|
||||
\end{lstlisting}
|
||||
The test succeeds only for a \phantomsection\label{GlossaryRef:symboliclink}\gls{symboliclink}, after which `readlink` prints its target.
|
||||
\item \textbf{Find all regular files under the current tree larger than 40 KiB.}
|
||||
\index{Linux command!find}
|
||||
\begin{lstlisting}[language=bash]
|
||||
find . -type f -size +40k -print
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
./blob.bin
|
||||
\end{lstlisting}
|
||||
The search restricts results to regular files whose size exceeds 40 KiB.
|
||||
\item \textbf{Find files modified in the last ten minutes under `tmp/` and print their sizes.}
|
||||
\index{Linux command!find}
|
||||
\begin{lstlisting}[language=bash]
|
||||
find tmp -type f -mmin -10 -printf '%s %p\n'
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
19 tmp/file1.txt
|
||||
\end{lstlisting}
|
||||
The search filters by modification time and prints each matching size followed by its path.
|
||||
\end{enumerate}
|
||||
|
||||
\section*{F) Processes \& Job Control}
|
||||
\begin{enumerate}[label=\textbf{\arabic*.},leftmargin=*,start=24]
|
||||
\item \textbf{Show your processes in a tree view.}\phantomsection\label{AcronymRef:PPID}
|
||||
\index{Linux command!processes}
|
||||
\begin{lstlisting}[language=bash]
|
||||
ps -u "$USER" --forest -o pid,ppid,stat,cmd
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
PID PPID STAT CMD
|
||||
2 0 S [kthreadd]
|
||||
3 2 S \_ [pool_workqueue_release]
|
||||
4 2 I< \_ [kworker/R-rcu_g]
|
||||
5 2 I< \_ [kworker/R-rcu_p]
|
||||
6 2 I< \_ [kworker/R-slub_]
|
||||
7 2 I< \_ [kworker/R-netns]
|
||||
9 2 I< \_ [kworker/0:0H-kblockd]
|
||||
12 2 I< \_ [kworker/R-mm_pe]
|
||||
13 2 I \_ [rcu_tasks_kthread]
|
||||
14 2 I \_ [rcu_tasks_rude_kthread]
|
||||
15 2 I \_ [rcu_tasks_trace_kthread]
|
||||
16 2 S \_ [ksoftirqd/0]
|
||||
17 2 I \_ [rcu_preempt]
|
||||
18 2 S \_ [migration/0]
|
||||
19 2 S \_ [idle_inject/0]
|
||||
20 2 S \_ [cpuhp/0]
|
||||
21 2 S \_ [kdevtmpfs]
|
||||
22 2 I< \_ [kworker/R-inet_]
|
||||
23 2 S \_ [kauditd]
|
||||
24 2 S \_ [khungtaskd]
|
||||
26 2 S \_ [oom_reaper]
|
||||
28 2 I< \_ [kworker/R-write]
|
||||
29 2 S \_ [kcompactd0]
|
||||
30 2 SN \_ [ksmd]
|
||||
31 2 I< \_ [kworker/R-kinte]
|
||||
32 2 I< \_ [kworker/R-kbloc]
|
||||
33 2 I< \_ [kworker/R-blkcg]
|
||||
34 2 S \_ [irq/9-acpi]
|
||||
35 2 I< \_ [kworker/R-tpm_d]
|
||||
36 2 I< \_ [kworker/R-ata_s]
|
||||
37 2 I< \_ [kworker/R-md]
|
||||
38 2 I< \_ [kworker/R-md_bi]
|
||||
39 2 I< \_ [kworker/R-edac-]
|
||||
40 2 I< \_ [kworker/R-devfr]
|
||||
41 2 S \_ [watchdogd]
|
||||
42 2 I< \_ [kworker/R-quota]
|
||||
43 2 I< \_ [kworker/0:1H-kblockd]
|
||||
44 2 S \_ [kswapd0]
|
||||
45 2 S \_ [ecryptfs-kthread]
|
||||
46 2 I< \_ [kworker/R-kthro]
|
||||
47 2 I< \_ [kworker/R-acpi_]
|
||||
48 2 S \_ [scsi_eh_0]
|
||||
49 2 I< \_ [kworker/R-scsi_]
|
||||
50 2 S \_ [scsi_eh_1]
|
||||
51 2 I< \_ [kworker/R-scsi_]
|
||||
52 2 S \_ [scsi_eh_2]
|
||||
53 2 I< \_ [kworker/R-scsi_]
|
||||
56 2 I< \_ [kworker/R-mld]
|
||||
57 2 I< \_ [kworker/R-ipv6_]
|
||||
64 2 I< \_ [kworker/R-kstrp]
|
||||
66 2 I< \_ [kworker/u3:0]
|
||||
71 2 I< \_ [kworker/R-crypt]
|
||||
81 2 I< \_ [kworker/R-charg]
|
||||
163 2 I< \_ [kworker/R-raid5]
|
||||
200 2 S \_ [jbd2/vda1-8]
|
||||
201 2 I< \_ [kworker/R-ext4-]
|
||||
293 2 I< \_ [kworker/R-kmpat]
|
||||
294 2 I< \_ [kworker/R-kmpat]
|
||||
398 2 S \_ [jbd2/vda16-8]
|
||||
399 2 I< \_ [kworker/R-ext4-]
|
||||
1163 2 I< \_ [kworker/R-tls-s]
|
||||
34191 2 S \_ [psimon]
|
||||
52833 2 I \_ [kworker/u2:0-events_power_efficient]
|
||||
53308 2 I \_ [kworker/u2:2-events_power_efficient]
|
||||
53346 2 I \_ [kworker/u2:3-events_power_efficient]
|
||||
53379 2 I \_ [kworker/0:1-cgroup_free]
|
||||
53425 2 S \_ [psimon]
|
||||
53433 2 S \_ [psimon]
|
||||
53615 2 I \_ [kworker/0:2-events]
|
||||
53633 2 I \_ [kworker/u2:4-events_unbound]
|
||||
1 0 Ss /usr/lib/systemd/systemd --system --deserialize=75
|
||||
837 1 Ss /usr/lib/systemd/systemd-logind
|
||||
914 1 Ss+ /sbin/agetty -o -p -- \u --keep-baud 115200,57600,38400,9600 - vt220
|
||||
920 1 Ssl /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
|
||||
960 1 Ss+ /sbin/agetty -o -p -- \u --noclear - linux
|
||||
8058 1 Ssl /opt/digitalocean/bin/droplet-agent
|
||||
20679 1 SLsl /sbin/multipathd -d -s
|
||||
32446 1 Ss /usr/sbin/cron -f -P
|
||||
34152 1 S<s /usr/lib/systemd/systemd-journald
|
||||
34178 1 Ss /usr/lib/systemd/systemd-udevd
|
||||
34749 1 Ssl /usr/libexec/udisks2/udisksd
|
||||
34750 1 Ss sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
|
||||
53422 34750 Ss \_ sshd: root@pts/0
|
||||
53536 53422 Ss \_ -bash
|
||||
53665 53536 R+ \_ ps -u root --forest -o pid,ppid,stat,cmd
|
||||
34756 1 Ssl /usr/libexec/fwupd/fwupd
|
||||
34772 1 Ssl /usr/sbin/ModemManager
|
||||
53427 1 Ss /usr/lib/systemd/systemd --user
|
||||
53428 53427 S \_ (sd-pam)
|
||||
\end{lstlisting}
|
||||
The `--forest` option renders the \phantomsection\label{GlossaryRef:process}\gls{process} relationships as a tree for the selected user.
|
||||
\item \textbf{Start `sleep 120` in the background and show its \phantomsection\label{AcronymRef:PID}PID.}
|
||||
\index{Linux command!sleep}
|
||||
\begin{lstlisting}[language=bash]
|
||||
sleep 120 & echo "$!"
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
[1] 53666
|
||||
53666
|
||||
\end{lstlisting}
|
||||
\$! expands to the process \phantomsection\label{AcronymRef:ID}ID of the most recently started background job.
|
||||
\item \textbf{Send TERM to all `sleep` processes owned by the current user without using `kill -9`.}
|
||||
\index{Linux command!pkill}
|
||||
\begin{lstlisting}[language=bash]
|
||||
pkill -TERM -u "$USER" -x sleep
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
[1]+ Terminated sleep 120
|
||||
\end{lstlisting}
|
||||
The command requests graceful termination of exact-name `sleep` \gls{process}es belonging to the current user.
|
||||
\item \textbf{Show the top five processes by memory usage in a noninteractive snapshot.}
|
||||
\index{Linux command!ps}
|
||||
\begin{lstlisting}[language=bash]
|
||||
ps -eo pid,user,%mem,comm --sort=-%mem | head -n 6
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
PID USER %MEM COMMAND
|
||||
34152 root 6.3 systemd-journal
|
||||
20679 root 5.8 multipathd
|
||||
34756 root 4.7 fwupd
|
||||
53427 root 2.4 systemd
|
||||
7679 do-agent 2.3 do-agent
|
||||
\end{lstlisting}
|
||||
The output is sorted by descending memory percentage, with the header included.
|
||||
\end{enumerate}
|
||||
|
||||
\subsection*{G) Archiving and Compression}
|
||||
\begin{enumerate}[label=\textbf{\arabic*.},leftmargin=*,start=28]
|
||||
\item \textbf{Create a gzipped tar archive named `src.tgz` from `src/` using relative paths.}
|
||||
\index{Linux command!tar}
|
||||
\begin{lstlisting}[language=bash]
|
||||
tar -czf src.tgz src/
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
(no terminal output)
|
||||
\end{lstlisting}
|
||||
The \phantomsection\label{GlossaryRef:archive}\gls{archive} is created from the relative `src/` path.
|
||||
\item \textbf{List the contents of `src.tgz` without extracting it.}
|
||||
\index{Linux command!tar}
|
||||
\begin{lstlisting}[language=bash]
|
||||
tar -tzf src.tgz
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
src/
|
||||
src/file1.txt
|
||||
src/file2.txt
|
||||
src/lib/
|
||||
src/file1.txt.bak
|
||||
src/file2.txt.bak
|
||||
\end{lstlisting}
|
||||
The archive member names are displayed without extracting files.
|
||||
\item \textbf{Extract only `file2.txt` from `src.tgz` into `tmp/`.}
|
||||
\index{Linux command!tar}
|
||||
\begin{lstlisting}[language=bash]
|
||||
tar -xzf src.tgz -C tmp --strip-components=1 src/file2.txt
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
(no terminal output)
|
||||
\end{lstlisting}
|
||||
The selected \gls{archive} member is extracted into `tmp/` after stripping the leading `src/` path component.
|
||||
\textbf{Verification step:}
|
||||
\begin{lstlisting}
|
||||
$ ls -l tmp/file2.txt
|
||||
-rw-r--r-- 1 root root 16 Sep 12 13:23 tmp/file2.txt
|
||||
$ cat tmp/file2.txt
|
||||
two 3 four five
|
||||
\end{lstlisting}
|
||||
The verification command is included as evidence of the resulting file state and is not part of the solution command.
|
||||
\end{enumerate}
|
||||
|
||||
\subsection*{H) Networking \& System Info}
|
||||
\begin{enumerate}[label=\textbf{\arabic*.},leftmargin=*,start=31]
|
||||
\item \textbf{Show all listening \phantomsection\label{AcronymRef:TCP}TCP sockets with associated PIDs without assuming root access.}
|
||||
\index{Linux command!ss}
|
||||
\begin{lstlisting}[language=bash]
|
||||
ss -ltnp
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
|
||||
LISTEN 0 4096 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=34750,fd=3),("systemd",pid=1,fd=109))
|
||||
LISTEN 0 4096 127.0.0.54:53 0.0.0.0:* users:(("systemd-resolve",pid=34166,fd=17))
|
||||
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=34166,fd=15))
|
||||
LISTEN 0 4096 [::]:22 [::]:* users:(("sshd",pid=34750,fd=4),("systemd",pid=1,fd=110))
|
||||
\end{lstlisting}
|
||||
The command lists listening TCP sockets and includes process information where permitted.
|
||||
\item \textbf{Print the default route or gateway concisely.}
|
||||
\index{Linux command!ip route}
|
||||
\begin{lstlisting}[language=bash]
|
||||
ip route show default
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
default via 142.93.192.1 dev eth0 proto static
|
||||
\end{lstlisting}
|
||||
The command displays the system's default route.
|
||||
\item \textbf{Display the kernel name, release, and machine architecture.}
|
||||
\index{Linux command!uname}
|
||||
\begin{lstlisting}[language=bash]
|
||||
uname -srm
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
Linux 6.8.0-124-generic x86_64
|
||||
\end{lstlisting}
|
||||
The output contains the kernel name, release, and machine architecture.
|
||||
\item \textbf{Show the last five successful logins or sessions on the system.}
|
||||
\index{Linux command!last}
|
||||
\begin{lstlisting}[language=bash]
|
||||
last -n 5
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
root pts/0 100.8.220.73 Sat Sep 12 13:12 still logged in
|
||||
root pts/1 155.246.151.34 Thu Sep 10 21:23 - 22:23 (00:59)
|
||||
root pts/0 155.246.151.34 Thu Sep 10 21:22 - 00:36 (03:13)
|
||||
reboot system boot 6.8.0-124-generi Thu Sep 10 21:16 still running
|
||||
|
||||
wtmp begins Thu Sep 10 21:16:00 2026
|
||||
\end{lstlisting}
|
||||
The command displays the most recent login/session records available from the system accounting log.
|
||||
\end{enumerate}
|
||||
|
||||
\subsection*{I) Package \& Services (Debian/Ubuntu)}
|
||||
\begin{enumerate}[label=\textbf{\arabic*.},leftmargin=*,start=35]
|
||||
\item \textbf{Show the installed version of the `coreutils` package.}
|
||||
\index{Linux command!coreutils}
|
||||
\begin{lstlisting}[language=bash]
|
||||
dpkg-query -W -f='${Version}\n' coreutils
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
9.4-3ubuntu6.3
|
||||
\end{lstlisting}
|
||||
The package query prints the installed version string.
|
||||
\item \textbf{Search available packages whose names contain `ripgrep`.}
|
||||
\index{Linux command!apt-cache}
|
||||
\begin{lstlisting}[language=bash]
|
||||
apt-cache search --names-only ripgrep
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
ripgrep - Recursively searches directories for a regex pattern
|
||||
\end{lstlisting}
|
||||
The package cache is searched by package name only.
|
||||
\item \textbf{Check whether the `cron` service is active and print only its status line.}
|
||||
\index{Linux command!systemctl}
|
||||
\begin{lstlisting}[language=bash]
|
||||
systemctl is-active cron
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
active
|
||||
\end{lstlisting}
|
||||
The command returns the service's active-state value.
|
||||
\end{enumerate}
|
||||
|
||||
\subsection*{J) Bash \& Scripting}
|
||||
\begin{enumerate}[label=\textbf{\arabic*.},leftmargin=*,start=38]
|
||||
\item \textbf{Loop over `*.txt` in `src/` and print each filename and word count.}
|
||||
\index{Linux command!Bash}
|
||||
\begin{lstlisting}[language=bash]
|
||||
shopt -s nullglob
|
||||
for f in src/*.txt; do
|
||||
printf '%s : %s\n' "$f" "$(wc -w < "$f")"
|
||||
done
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
src/file1.txt : 4
|
||||
src/file2.txt : 4
|
||||
\end{lstlisting}
|
||||
The loop uses `nullglob` so an unmatched pattern expands to no files, and `wc -w` supplies each word count in \gls{bash}.
|
||||
\item \textbf{Export CSV rows where `dept == "CS"` to `cs.txt`, excluding the header.}
|
||||
\index{Linux command!awk}
|
||||
\begin{lstlisting}[language=bash]
|
||||
awk -F, 'NR > 1 && $3 == "CS"' people.csv > cs.txt
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
(no terminal output)
|
||||
\end{lstlisting}
|
||||
The `awk` condition selects records after the header whose third field equals `CS`.
|
||||
\textbf{Verification step:}
|
||||
\begin{lstlisting}
|
||||
$ cat cs.txt
|
||||
2,Linus,CS
|
||||
4,Dennis,CS
|
||||
\end{lstlisting}
|
||||
The verification command is included as evidence of the resulting file state and is not part of the solution command.
|
||||
\item \textbf{Create an environment variable `X` with value `42`, print it, and remove it from the environment.}
|
||||
\index{Linux command!environment variables}
|
||||
\begin{lstlisting}[language=bash]
|
||||
export X=42; printf '%s\n' "$X"; unset X
|
||||
\end{lstlisting}
|
||||
\textbf{Observed output:}
|
||||
\begin{lstlisting}
|
||||
42
|
||||
\end{lstlisting}
|
||||
The \phantomsection\label{GlossaryRef:environmentvariable}\gls{environmentvariable} is exported, printed, and then unset in the current shell.
|
||||
\end{enumerate}
|
||||
Reference in New Issue
Block a user