by LARP LAB TH

Make things

Create folders and files, write into them and read them back, all from the keyboard.

Lesson 3 of 312 min

LARP it

Mission. Set up a secret base on this machine: a folder, a file with your codename in it, and a log of the mission. Then prove it worked by reading it back.

cd ~
mkdir secret-base
cd secret-base
touch notes.txt
echo "codename: ghost" > notes.txt
echo "mission 1: complete" >> notes.txt
cat notes.txt
ls -l

Learn it

Command What it does
mkdir secret-base make a directory (folder)
touch notes.txt creates an empty file, or updates the time on an existing one
echo "text" prints the text back to you
cat notes.txt prints the whole file (short for concatenate)

The new idea here is redirection. Normally a command prints to the screen. The > and >> arrows send that output into a file instead:

  • > replaces the file’s contents. Run it twice and only the last line is left.
  • >> appends to the end of the file and keeps what was there.

So echo "codename: ghost" > notes.txt writes one line into the file, and the >> line adds a second one below it.

Careful: > overwrites without asking. If you point it at a file that matters, its old contents are gone. When in doubt, use >>.

That’s the core loop of the terminal: small commands, each doing one thing, joined together by arrows. Most developer tools (git, npm, python) are just more commands that work the same way.

Check it

  1. Add a third line to notes.txt without losing the first two. Read the file to prove it.
  2. Run echo "oops" > notes.txt, then cat notes.txt. What happened, and why?
  3. Make a folder secret-base/intel and a file inside it, using only paths from your home folder (no cd).

Course complete. You can open a terminal, move around a computer and create files without a mouse. Next, try it on a real task: next time you’d open a folder in Finder or Explorer, use cd and ls instead.