Skip to content
ohsudo, Home

Module 1: First steps

Read files: cat, head, tail and less

Most troubleshooting starts by reading something: a config, a log, a message. Which command you use depends on how big the file is, and which part you care about.

● Runs 100% in your browser. Nothing here can harm a real system.

Step 1 of 6

Print a whole file

cat prints a file from start to end. That's best for short files.

Your task

Print todo.txt.

guest@ohsudo: ~ — Ubuntu 24.04

Starting the terminal…

What you'll practice

  1. Print a whole file. cat prints a file from start to end. That's best for short files.
  2. The start of a file. head prints the first lines of a file, 10 by default. -n chooses how many.
  3. The end of a file. tail prints the last lines. It's the one to use on logs, since the newest lines are at the end. On a real system, tail -f keeps showing new lines as they arrive.
  4. Page through a long file. less shows a long file one screen at a time. On a real system you scroll with the arrows, search with /, and leave with q. In this playground, it just prints the file.
  5. Which system is this?. /etc/os-release says which Linux you're on. It's worth checking first, as package managers and file locations differ between families.
  6. A protected log. Many logs can only be read as root. sudo runs one command with those rights. Debian and Ubuntu write general system messages to /var/log/syslog. Many logs can only be read as root. sudo runs one command with those rights. RHEL, Rocky and AlmaLinux write general system messages to /var/log/messages.

See also