Back to course

19. Viewing File Content: The `cat` and `head` Commands

Linux Basics: From Zero to CLI Hero

Inspecting File Contents

Once we have files, we need tools to read them. These are standard utility commands.

1. cat (Concatenate)

cat is the simplest viewer. It prints the entire contents of a file directly to the screen (standard output).

bash $ cat /etc/os-release PRETTY_NAME="Ubuntu 22.04.3 LTS" NAME="Ubuntu" VERSION_ID="22.04" ...

Warning: Use cat only for small configuration or text files. Using it on very large files will flood your terminal.

2. head

head displays only the beginning lines of a file (the 'head'). By default, it shows the first 10 lines.

bash $ head /etc/passwd

Use the -n option to specify the number of lines you want to see:

bash $ head -n 5 /etc/passwd

Shows only the first 5 lines