shio

~/shio.sh/learn/reading-files $ ./read

chapter 03 · learn the terminal

Reading files (cat, head, tail)

cat prints a file. head shows the top. tail shows the bottom. The terminal is a reader before it's a writer.

$ cat — concatenate and print

cat prints the entire contents of a file to your screen. The name is short for concatenate, because if you pass it several files, it prints them one after another. For one file, just think "show me this."

Try reading your notes.txt:

try: cat notes.txt

$ head and tail

When a file is huge, you don't always want to cat the whole thing. Two small helpers:

  • head -n 3 notes.txt — show the first 3 lines
  • tail -n 3 notes.txt — show the last 3 lines

Without -n, both default to 10 lines. head for the beginning, tail for the end. The names are literal.

try: head -n 3 notes.txt

$ less — read in pages

For really long files, less shows them one screen at a time. In a real terminal you'd press space to scroll down and q to quit. In this sandbox, less behaves like cat — short files don't need the help.

$ a small habit

When you land in a new folder, a good instinct is: pwd, ls, then cat something interesting. You'll get fast at it. The terminal rewards small habits.

Next: how to make things — folders, files, written-from-thin-air content.

~/shio.sh/learn/reading-files $ cd ..