← Week 2 - Filesystem and files | My notes
Week 2 - Filesystem and files: detailed plan¶
Goal: Move around confidently and know where things live.
Budget: 6-8 hours in 5 sessions. The checklists to tick off live in week-02-notes.md; this file is the reference behind them.
Reading: Ch. 2 Navigation; Ch. 3 Exploring the System (including symbolic and hard links); Ch. 4 Manipulating Files and Directories (including ln); Ch. 17 Searching for Files (find). Optional: Ch. 15 Storage Media for df and mount.
Overview¶
| Session | Focus | Time | Exercise |
|---|---|---|---|
| 1 | Layout tour with ls and find |
1.5 h | 1 |
| 2 | Viewing files, disk usage, links, tree |
1.5 h | 2 |
| 3 | find in depth |
1 h | 2 |
| 4 | .NET app plus tail -f |
1 h | 3 |
| 5 (weekend) | Bandit 6-12, then cheatsheet and wrap-up | 2-3 h | 4 + deliverable |
Session 1: Layout tour (Exercise 1)¶
The directory table lists what each directory is for. The exercise asks you to explore them, so verify each one with evidence.
/etc:ls /etc | head -30,cat /etc/os-release,cat /etc/hostname,head /etc/passwd. These are plain-text configs. Runfind /etc -name "*.conf" 2>/dev/null | wc -l./var:ls /var/log,du -sh /var/* 2>/dev/null. Find out what grows here (logs, apt cache) and what is in/var/lib./usr:ls /usr/bin | wc -l,ls -l /bin /lib /sbin(confirm the symlinks),which dotnet gitand see where each lives./home,/tmp:ls -la ~for hidden dotfiles (.bashrc,.profile,.ssh). Runls -ld /tmpto confirm the sticky bit./proc:head /proc/cpuinfo,head /proc/meminfo,cat /proc/$$/cmdline,ls -l /proc/$$/fd.$$is the PID of your shell, so this shows a live process as files.- WSL-specific:
ls /mnt/c,findmnt /mnt/c,mount | head. Compare with the week 1 notes on Linux vs Windows filesystem performance.
Write down: three things that surprised you, plus a /proc example you found useful.
Session 2: Viewing, size and links (Exercise 2, part 1)¶
- Viewing:
less:/patternto search,nandNto move between matches,gandGto jump to start and end,qto quit,Fto follow liketail -f.head -n 5andtail -n 5.cat,wc -l,file.- Disk usage:
df -handdf -hT(note the 9p/drvfs mounts for Windows drives).du -sh dir,du -h --max-depth=1 | sort -h, anddu -ah | sort -rh | head.- Know the difference:
dfis per filesystem,duis per directory tree. tree:sudo apt install tree, thentree -L 2,tree -a -I node_modules,tree -d.- Links lab (in
/tmp/links-lab): - Create
a.txt, thenln a.txt hard.txtandln -s a.txt soft.txt. - Run
ls -liand compare inode numbers. The hard link shares the inode and the symlink does not. - Delete
a.txt. The hard link still works, andsoft.txtis now broken. Find the dangling link withfind . -xtype l. - Run
staton each, and watch the link count change. - Try a hard link to a directory and across filesystems. Note both errors, and why symlinks don't have those limits.
- Real-world symlink:
ls -l /etc/alternativesandreadlink -f $(which dotnet).
Session 3: find in depth (Exercise 2, part 2)¶
Practice these patterns, each on a real directory:
- By name and type:
find . -name "*.cs",-iname,-type f|d|l. - By size and time:
-size +10M,-mtime -1,-mmin -30. - By owner and permissions:
-user,-perm. This is the groundwork for Bandit. - Actions:
-exec cmd {} \;vs-exec cmd {} +, and-delete. Run it without-deletefirst. - Pruning:
find . -name bin -prune -o -name "*.cs" -print. - Errors:
2>/dev/nullto hide permission-denied noise. Learn why it goes at the end. - Mini challenges:
- Largest 10 files under
~/src. - All
.csprojfiles modified this week. - All empty directories in a repo.
- Compare
findwithlocate(sudo updatedb) andfdif installed.
Session 4: .NET app with tail -f (Exercise 3)¶
- Create
dotnet new webapi -o ~/src/tail-demo(or reuse an existing app). - In one terminal, write the console output to a file:
dotnet run > /tmp/app.log 2>&1. - In a second terminal, run
tail -f /tmp/app.log. - In a third terminal, send requests with
curl -i localhost:<port>/weatherforecast. Also send a request to a non-existent route for a 404. - Experiment:
tail -n 50 -ftail -F(survives log rotation)grep --line-bufferedon a live streamless +F- Add logging in code (
logger.LogInformation(...)) and find it in the output. - Bonus:
ls -l /proc/<pid>/fdfor the dotnet process to see the open log file and sockets.
Notes to capture: why stdout and stderr both need redirecting, and what happens to tail -f when the file is deleted or truncated.
Session 5: Bandit 6-12 and wrap-up (Exercise 4 + deliverable)¶
Bandit 6-12 are almost all find, grep, sort, uniq, strings, base64, tr and xxd. Per bandit.md:
- Use the level template. Write the approach and the concept learned, but never passwords or solutions.
- Try each level with
manand your own notes first. Time-box each level to 30 minutes before looking for hints. - Expect these themes:
findby size/owner/group (6-7),grepandsort | uniq -u(8-9),strings(9),base64 -d(10),trrot13 (11), and repeated decompression withxxd -r(12). - Update the progress table in overthewire/README.md.
Cheatsheet (deliverable): add to cheatsheet.md the Viewing files, Disk usage, Links, Finding files and Tricky file names sections. Include one-line "what I'd forget" examples. Only commands you have actually run.
Wrap-up:
- Tick the exercises and the Done box in week-02-filesystem-and-files.md.
- Set the status in week-02-notes.md to Done.
- Run the markdownlint check before pushing (see the README).
- Commit via a branch like
docs/week-02-..., matching the week 1 PR flow.
Self-check before moving on¶
- Can you explain the difference between a hard link and a symlink, and what
rmdoes to each? - Can you tell where config, logs, binaries and user data live without looking?
- Can you find "files over 100 MB modified in the last week" in one command?
- Can you tell why
dfandducan disagree? - Can you follow a live log and filter it?
Risks and tips¶
- WSL-specific:
/mnt/cis slow and has odd permissions, so dofindandduexercises under~, not there. - Safety: never run
find / -deleteor-exec rm. Dry run first, and stay in/tmpor~/src. - Bandit 6+ requires reading man pages carefully, and that is the real skill being trained.