🐧 Module 0.4 ✅ Assessment Answers Linux CLI

Module 0.4 —
Assessment Answers

Complete answers for all three sections — multiple choice, short answer, and scenario-based questions on Linux command line for embedded systems.

Section A10 MCQs
Section B5 Short Answers
Section C4 Scenarios
✅  Section A — Multiple Choice Questions
ASelect the single best answer for each question
A1How do you display the last 50 lines of a log file and follow new output?
✅ (b)tail -n 50 -f log.txt

-n 50 sets the line count; -f follows new lines in real time. Press Ctrl+C to stop.

A2Which tool searches source code recursively and is significantly faster than grep?
✅ (b)rg (Ripgrep)

rg is purpose-built for source code, searches recursively by default, and respects .gitignore.

A3Which signal does Ctrl+C send to the foreground process?
✅ (c)SIGINT

SIGINT (signal 2) — interrupt request. The process can catch and handle it. Ctrl+Z sends SIGTSTP (suspend).

A4What happens when you press Ctrl+Z in the terminal?
✅ (b)Suspends the foreground process (SIGTSTP); resume with fg

The process is paused, not killed. Use fg to bring it back or bg to continue it in the background.

A5Why must your Linux user be in the dialout group?
✅ (b)To use serial devices like /dev/ttyUSB0 without sudo

Serial device files in /dev/ are owned by the dialout group. Without membership, access is denied unless you use sudo.

A6What does set -euo pipefail do in a Bash script?
✅ (b)-e: exit on error, -u: no unset vars, pipefail: pipe errors

All three flags together make scripts safe: they fail loudly instead of continuing with broken state.

A7What is the tmux prefix key used before every shortcut?
✅ (b)Ctrl + B

Press Ctrl+B first, then the command key. e.g., Ctrl+B D to detach, Ctrl+B % to split vertically.

A8What permissions does chmod 644 give a file?
✅ (a)Owner: read+write; Group & Others: read-only

644 = rw-r--r--. Owner (6=4+2): read+write. Group/Others (4): read only. Standard for config files.

A9Which command shows active listening ports with their process names?
✅ (b)ss -tlnp

-t TCP, -l listening only, -n numeric ports, -p process names. Use this to debug which program is using a port.

A10What is the primary use of dmesg | tail in embedded development?
✅ (b)Check kernel messages to confirm USB device was detected

Run immediately after plugging in a board. Linux logs the driver load and device file assignment (/dev/ttyUSB0) here.

📄  Section B — Short Answer Questions
B1Explain why picocom is preferred over the Arduino IDE Serial Monitor for serious embedded work.

picocom is a lightweight serial terminal designed for direct terminal use. Unlike the Arduino IDE's Serial Monitor, it works seamlessly over SSH, inside tmux sessions, and in automation scripts. It allows serial data to be logged, redirected, and processed using standard Linux commands.

🏭
Key Advantages
Works over SSH — log into a remote build server and still monitor your board. Runs inside tmux — stays active even if the terminal is closed. Pipeable output — picocom | grep ERROR filters live serial data.
B2Write a one-line pipe that finds all .c files, counts lines in each, sorts by descending length, and shows the top 10.
bash — answer
find . -name "*.c" -exec wc -l {} \; | sort -rn | head -10

How each part works

PartMeaning
find . -name "*.c"Search all .c files from current directory
-exec wc -l {} \;Run wc -l (line count) on every file found
| sort -rnSort numerically (-n) in reverse/descending (-r) order
| head -10Keep only the top 10 results

Workflow summary

  • 1.Find all .c source files.
  • 2.Count lines in each file.
  • 3.Sort by line count, largest first.
  • 4.Display only the top 10 files.
B3What is the difference between > and >> in shell redirection?
> — Overwrite

Redirects stdout to a file. If the file exists, its content is erased first. If it doesn't exist, it is created.

ls > files.txt
>> — Append

Adds new output to the end of an existing file. Does not erase previous content. Creates the file if it doesn't exist.

date >> log.txt
💡
When to use each
Use > for fresh output you want to overwrite on each run (e.g., latest build status). Use >> for cumulative logs where you need to keep all history (e.g., firmware run logs).
B4Describe a real-life tmux setup you would use during STM32 driver debugging.

A practical tmux setup uses three panes running simultaneously:

bash — set up the session
tmux new -s stm32-debug     # create a named session
# Ctrl+B %  → split to get Pane 2
# Ctrl+B "  → split to get Pane 3
PaneCommandPurpose
Pane 1make / pio runBuild firmware — see compile errors immediately
Pane 2st-flash write / west flashFlash the latest build to the board
Pane 3picocom -b 115200 /dev/ttyACM0Monitor UART output from the STM32
SSH Resilience
Since tmux sessions survive SSH disconnects, you can detach (Ctrl+B D) and reconnect later with tmux attach -t stm32-debug — the build and monitor stay running.
B5What does the 2>&1 part of cmd > out.txt 2>&1 do, and why does the order matter?

In Linux, every process has numbered file descriptors: stdout = 1 and stderr = 2. The notation 2>&1 means: "redirect file descriptor 2 (stderr) to wherever file descriptor 1 (stdout) currently points."

bash
make > build.log 2>&1    # stdout goes to file, then stderr follows stdout

Why the order matters

CommandResult
cmd > out.txt 2>&1stdout → file, then stderr → same file ✓ Both captured
cmd 2>&1 > out.txtstderr → terminal (old stdout), stdout → file ✗ Errors on screen
💡
Embedded Use
west build > build.log 2>&1 — captures everything including compiler errors into one log file. Then grep error build.log to find failures quickly.
🔌  Section C — Scenario-Based Questions
C1Your ESP32 does not appear as a serial port after connecting. Describe your diagnostic steps.

Work through these steps in order — each one narrows down the cause:

bash — step 1: check kernel detection
dmesg | tail
🔍
What to look for
A successful detection shows: usb X-X: new full-speed USB device followed by cp210x converter now attached to ttyUSB0. If nothing appears, Linux didn't detect the hardware at all — try a different USB cable or port.
bash — step 2: list serial device files
ls /dev/ttyUSB* /dev/ttyACM*
bash — step 3: confirm USB is detected
lsusb
bash — step 4: check group membership
groups $USER
bash — step 5: check device file permissions
ls -l /dev/ttyUSB0
Common Fixes
Not in dialout group → sudo usermod -aG dialout $USER then log out and back in. Driver not installed → sudo apt install cp210x-dkms. Cable only provides power (no data lines) → swap for a data USB cable.
C2Find every TODO comment across the entire project, with line numbers.

Primary answer — using Ripgrep:

bash — recommended
rg -n TODO
FlagMeaning
rgRun Ripgrep (searches recursively by default)
-nShow line numbers alongside each match
TODOThe search pattern

Alternative — using grep:

bash — alternative
grep -rn TODO .
💡
Why rg is preferred here
rg automatically skips build/, .git/, and other directories in .gitignore, so results contain only real source code matches — not false positives from build artifacts.
C3Capture raw UART output from /dev/ttyACM0 at 921600 baud for exactly 30 seconds into a log file.
bash — answer
stty -F /dev/ttyACM0 921600 raw && timeout 30 cat /dev/ttyACM0 > capture.log
PartPurpose
stty -F /dev/ttyACM0 921600 rawConfigure serial port: set baud rate 921600, enable raw mode (no line processing)
&&Run the next command only if stty succeeded (exit status 0)
timeout 30Automatically stop after exactly 30 seconds
cat /dev/ttyACM0Read raw bytes from the serial device file
> capture.logRedirect all output into the log file
💡
Why raw mode matters
Without raw mode, the terminal driver processes the data — interpreting control characters, adding newlines, etc. raw passes bytes through completely unmodified, which is what you want for binary firmware logs.
C4Run a long automated test over SSH that must survive SSH disconnects and remain accessible when you reconnect.
bash — step 1: create a tmux session
tmux new -s test

Inside the tmux session, start your test script or long-running process normally:

bash — step 2: run the test
./run_long_test.sh

Detach from the session (the process keeps running in the background):

keyboard — step 3: detach
Ctrl+B, then D    # session keeps running after SSH disconnects

Reconnect at any time — even after SSH drops:

bash — step 4: reattach
tmux attach -t test
🌟
Why tmux solves this
When an SSH connection drops, all processes attached to that terminal session die — including your test. tmux runs sessions independently of SSH connections. The session lives on the remote server, not inside the SSH tunnel. Detach → disconnect → reconnect → reattach, and the test has been running the whole time.

Module 0.4 — Linux Command Line Assessment Answers · Embedded Systems Foundations