Linux Basic/Linux Self Assessment

From HPCwiki
Revision as of 09:32, 11 June 2026 by Honfi001 (talk | contribs)
Jump to navigation Jump to search

Linux Basics — Self-Assessment

This page lets you verify that you have mastered the material from the Linux Basics Course. Work through the parts in order on Anunna. The final challenge produces a report file that proves you completed every step — submit (or keep) that file as evidence.

Prerequisites: an Anunna account and the course data at /lustre/shared/hpcCourses/shell-lesson-data.zip.

Rules:

  • Do everything from the command line. No file-manager GUIs, no OnDemand file browser (the shell is fine).
  • If you get stuck, use man, --help, or the Software Carpentry shell course — that is part of the skill.

Part 1 — Connect and orient

  1. Connect to Anunna via SSH.
  2. Confirm where you are with pwd. You should be in your home directory (/home/WUR/yourusername).

Part 2 — Build the workspace (directories and navigation)

  1. In your home directory, create this directory tree with a single command:
    ~/linux_test/
    ├── data/
    ├── scripts/
    └── results/
    Hint: one mkdir flag makes parent directories for you.
  2. Change into ~/linux_test/data using a relative path from your home directory.
  3. Go back to your home directory using only cd shortcuts (no full paths).

Part 3 — Work with files

  1. Copy the course archive into your home directory and extract it:
    cp /lustre/shared/hpcCourses/shell-lesson-data.zip ~/
    unzip ~/shell-lesson-data.zip -d ~/
    
  2. Find the file unicorn.dat inside the extracted data and copy it to ~/linux_test/data/sample.dat.
  3. Inside ~/linux_test/data, create 12 empty files named run_01.log through run_12.log with a single command (brace ranges).
  4. Delete only the even-numbered log files using wildcards/ranges — in as few commands as you can. Check with ls that exactly 6 odd-numbered files remain.

Part 4 — Pipes, filters, redirects

  1. Count how many lines in sample.dat contain the pattern TACCGGACAA, using grep piped into wc.
  2. Redirect that number into ~/linux_test/results/pattern_count.txt (it should contain a single number, nothing else).

Part 5 — Environment variables

  1. Create an environment variable holding your full name and export it:
    export REPORT_AUTHOR="Your Name"
    
  2. Verify it exists with echo $REPORT_AUTHOR and find it in the output of env.
  3. Question to yourself: why is export needed here? You will find out in the final challenge — your script runs as a child process, and only exported variables reach it.

Part 6 — Final challenge: the report script

Using a command-line text editor (nano is what the course taught, but vim or emacs are equally fine), create the file ~/linux_test/scripts/generate_report.sh with exactly this behaviour. Write it yourself — the skeleton below shows the required output labels, you fill in the commands.

The script must:

  • start with the correct interpreter header for bash,
  • write all output to ~/linux_test/results/report.txt (overwriting any previous report),
  • produce one labelled line per check, in this order:
Label Content What it proves
USER: output of whoami you ran it yourself
DATE: output of date when
AUTHOR: value of $REPORT_AUTHOR you understand export
SHEBANG: first line of the script itself (head -n 1 "$0") interpreter header present
PERMS: permission octal of the script itself (stat -c '%a' "$0") you made it executable
LOGFILES: number of .log files in ~/linux_test/data Part 3 globbing done
PATTERN: contents of ~/linux_test/results/pattern_count.txt Part 4 done

A starting skeleton (the first two lines are done for you):

#!/bin/bash

REPORT=~/linux_test/results/report.txt

echo "USER: $(whoami)" > "$REPORT"
echo "DATE: $(date)" >> "$REPORT"
# ... your turn: AUTHOR, SHEBANG, PERMS, LOGFILES, PATTERN ...

Mind the difference between > and >> — only the first line should overwrite.

Run it

  1. Make the script executable for yourself with chmod.
  2. Change into ~/linux_test/scripts and run it with a relative path:
    cd ~/linux_test/scripts
    ./generate_report.sh
    
  3. Run it once more from your home directory using the full path. Both must work.
  4. Bonus question: why does plain generate_report.sh (no ./) fail? Which environment variable is responsible?

Check yourself

Display the report:

cat ~/linux_test/results/report.txt

You pass if all of the following hold:

  • AUTHOR: shows your name (not empty — if it is empty, you forgot export);
  • SHEBANG: shows #!/bin/bash;
  • PERMS: starts with a 7 (e.g. 744, 755) — owner has read, write and execute;
  • LOGFILES: is 6;
  • PATTERN: is a number greater than 0.

If any line is wrong, fix the corresponding part and re-run the script — that is the whole point of scripts.

For instructors

A submitted report.txt is verifiable at a glance, or in bulk:

grep -E '^(AUTHOR: .+|SHEBANG: #!/bin/bash|PERMS: 7..|LOGFILES: 6|PATTERN: [1-9])' report.txt | wc -l
# Expect: 5

Asking students to also submit the script itself catches copy-pasted reports: the SHEBANG: and PERMS: lines must be consistent with the actual file.