# Reading a file: cat

Course: Terminal Basics — https://zero2vibecode.com/learn/terminal-basics
Canonical URL: https://zero2vibecode.com/learn/terminal-basics/2-1-reading-files-with-cat

`cat` prints a file straight into the terminal. It is how you look inside something without opening an editor.

You can create files. Now look inside one.

## cat — print a file

```
cat shopping.txt
```

```
milk
bread
coffee
```

That is the whole command. `cat` reads the file and prints it into the terminal, then gives you your prompt back.

Nothing is opened and nothing can be edited, which means nothing can be accidentally saved either. `cat` is purely a read.

The name is short for *concatenate*, because its original job was joining files together. `cat a.txt b.txt` prints both in a row. Printing one file turned out to be the far more common use, and the name stuck.

## cat -n — numbered lines

```
cat -n shopping.txt
```

```
     1	milk
     2	bread
     3	coffee
```

Numbers make it possible to point at a spot. "The bug is on line 42" is a sentence you can say to a colleague or to an AI agent, and both will know exactly where to look.

## When cat is the wrong tool

`cat` prints the whole file. On a three-line shopping list that is perfect. On a ten-thousand-line log it dumps everything and scrolls the useful part off the top.

For big files:

- `head file` — the first ten lines
- `tail file` — the last ten lines (usually what you want in a log)
- `less file` — page through it a screen at a time

Both `head` and `tail` take `-n` to choose how many: `head -n 3 file`.

In `less`, press Space to go down a page and `q` to quit. Nobody discovers `q` on their own, and getting stuck in a pager is a genuinely common first-week experience. Now you know.

## Try it

The folder has two small files in it.

1. `ls` — see what is there.
2. `cat shopping.txt` — read it.
3. `cat -n shopping.txt` — read it again, numbered.

Then, if you like, try `cat shopping.txt readme.txt` to see both printed one after the other.
