>_ IzzyLab

Topic breakdown

A log is a file where a program writes, line by line, what's happening to it: it started, handled a request, crashed. Logs can be huge — thousands or millions of lines — and there's no point opening them in full. Most often you need the beginning (when the service started) or the end (what just happened).

head prints the first lines of a file, tail the last ones. Without flags it's 10 lines, and the -n flag with a number sets a different count:

head -n 3 /etc/passwd     # the first three lines
tail -n 2 /etc/passwd     # the last two

Like the output of any command, the result can be saved to a file with >.

What's checked

  1. The log is unchanged
  2. last.txt holds the last 15 lines of the log
  3. first.txt holds the first 5 lines of the log

What it looks like