← Teacher guide

Reading and finding

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).

The command line · Using a shell · about 40 minutes · Open the student lesson

Classroom resources

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.

Students will be able to

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

  1. Predict: students who said "everything" will meet .plans.txt in the Try.
  2. Worked example: ask why catfish was printed.
  3. Vary: ask why the third task didn't need cd.
  4. 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 seeA question to askThe 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. One line: Print only the line of notes.txt that mentions Friday.

    grep Friday notes.txt: one line, without reading the whole file.
  7. 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.
  8. 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.
  9. 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.
  10. Hidden: Which of these is a hidden file?
    .config
    Names that start with a dot are hidden from plain ls.
  11. Review: paths: Review: you are in /home/sam/photos. What does cd .. do?
    Goes up to /home/sam
    .. is the folder above this one.
  12. 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

Where it leads

Next: Changing files.