cat: Reading Files
Printing a file.
You've made files, copied them, and moved them. Now let's look inside them. The simplest way to read a file in the terminal is the cat command.

- Time to look inside
- Reading files
- cat is the simplest
Print a file
Cat, followed by a file name, prints the whole file to the screen. Cat notes dot TXT shows Sam's three notes. Cat with a path works too, so we can read the report inside Documents, without going there.
cat notes.txt Buy milk Call Mum Learn Linux cat Documents/report.txt Sales report January: 120 February: 135 March: 150
Several files at once
Cat is short for concatenate, which means joining things together. Give it several files, and it prints them one after another, as if they were one file. Dash N adds line numbers, which is handy when you're talking about a particular line.
cat notes.txt todo.txt Buy milk Call Mum Learn Linux 1. Install Ubuntu 2. Learn the terminal 3. Write a script cat -n todo.txt 1 1. Install Ubuntu 2 2. Learn the terminal 3 3. Write a script
When not to use cat
Cat is perfect for short files. But cat dumps everything at once. On a file with thousands of lines, the text flies past, and you only see the end. For long files, there are better tools, which we'll meet next. And cat on a photo or a program prints garbage, because those aren't text.
| key | value |
|---|---|
| Great for | short text files |
| Not for | very long files |
| Not for | photos or programs |
| Instead | head, tail, less |
Summary
Cat prints a file, cat with several names joins them, and dash N adds line numbers. Next, reading just the start or the end of a long file.
Key takeaways- cat <file>
- cat a b joins
- cat -n numbers lines