Students print files with cat, find lines with grep (including -i, -c and paths to other folders), reveal hidden names with ls -a, and follow a clue trail to a hidden folder (AC9TDI10K01 node 1).
Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
SlidesDownload Present from the browser, or export to PowerPoint or PDF.
WorksheetDownload Print the student copy; the Teacher edition has the answers.
Students will be able to
I can print a file with cat.
I can find the lines I want with grep.
I can find hidden files with ls -a.
Timing
Predict and Try 6 min · Worked example 10 min · Vary 12 min · Practise and Make 12 min
Before class
Try the boards yourself, including the treasure hunt (fs: hunt): start.txt → library/shelf2/book.txt → gym/.locker/clue.txt. The hunt finishes in Pipes.
The one idea: you can read and search files you can't see, and "hidden" only means ls skips the name.
Running the lesson
Predict: students who said "everything" will meet .plans.txt in the Try.
Worked example: ask why catfish was printed.
Vary: ask why the third task didn't need cd.
Make: ask what made them try ls -a in the gym.
The hard part (on purpose)
grep matching inside words (catfish) surprises students; let the count come out wrong once, then look at the lines.
When students get stuck
What you will see
A question to ask
The fix
A student says there's nothing more in the gym (Sam's mistake).
What did ls -a show in your home folder that ls didn't?
Try ls -a in the gym too.
grep finds nothing.
Do the capitals match?
grep is case sensitive; grep -i ignores capitals.
Answers to the checks
what ls shows: In /home/sam, ls shows notes.txt, pets.txt, photos/ and projects/. Is that everything in the folder? Not everything: there's a hidden file, .plans.txt. ls skips names that start with a dot; ls -a shows them.
Try: find the hidden file: Find the hidden file in your home folder and print it with cat.
ls -a shows .plans.txt; cat .plans.txt prints it. Hidden only means ls skips it.
grep cat pets.txt, line by line: pets.txt has six lines: cat, dog, catfish, parrot, cat, hamster. How many lines does grep cat pets.txt print? 3 cat, catfish and cat: grep matches the letters anywhere in the line.
Find the mistake: Sam looks for a clue in the gym folder. Click the line where it first goes wrong. line 3 Line 3: ls skips hidden names. ls -a might show a hidden folder or file.
Capital letters: grep Friday notes.txt prints "Robot club on Friday". What does grep friday notes.txt print? Nothing: grep cares about capital letters (grep -i ignores them) grep -i friday notes.txt ignores capitals and finds it.
One line: Print only the line of notes.txt that mentions Friday.
grep Friday notes.txt: one line, without reading the whole file.
Count: How many pets have the letter a in them? Make grep count them with -c.
grep -c a pets.txt prints 5: it counts matching lines instead of printing them.
Read from here: Print level1.txt from your home folder, without using cd.
cat projects/game/level1.txt: commands take paths, so you don't have to go there first.
A huge log: A log file has 10,000 lines. You want only the lines with ERROR in them. Which command? grep ERROR log.txt This is how people read huge logs on servers: grep pulls out what matters.
Hidden: Which of these is a hidden file? .config Names that start with a dot are hidden from plain ls.
Review: paths: Review: you are in /home/sam/photos. What does cd .. do? Goes up to /home/sam .. is the folder above this one.
the treasure hunt, part 1: A treasure hunt starts in this folder. Follow the clues until you find the one hidden in the gym, and print it.
You followed the trail and spotted the hidden folder with ls -a. The last clue sends you to the office: you'll need pipes for that one (next lesson but one).
Solutions
One possible solution for each task. Other correct programs are fine.
Vary: find it fast › One line
Open task: any program that does what the step asks.
Vary: find it fast › Count
Open task: any program that does what the step asks.
Vary: find it fast › Read from here
Open task: any program that does what the step asks.
the treasure hunt, part 1
Open task: any program that does what the step asks.
Stretch and support
Stretch: grep -n shows line numbers and grep -v shows the lines that don't match. When would each be useful?
Support: Add to the card: cat file (print it), grep word file (lines with word), ls -a (hidden too).
Exit ticket
How would you print only the lines of notes.txt with the word maths in them, and how would you check for hidden files?
grep maths notes.txt; ls -a.
What each step is for
what ls shows: Committing to whether ls shows everything tests the new move: hidden names need ls -a.
Try: find the hidden file: Finding and printing the hidden file settles the prediction and introduces cat.
Worked example: grep: Working out which lines grep prints models the new move: grep matches the word anywhere in a line. Sam trusts plain ls, the misconception planted after the method.
Vary: find it fast: Each task changes one thing: one matching line, counting with grep -c, then reading a file in another folder without moving.
reading: Choosing the right reading command is the same move in mixed forms, plus a review of paths.
the treasure hunt, part 1: Following clue files through folders, one of them hidden, puts the moves together: look, move, read, and look again with -a.