cat prints a file straight to the screen. Learn how to add line numbers, join files together, and why it is the wrong tool for long files, by running the commands in a real terminal in your browser.
Updated: 2026-09-05
cat [options] file...
Prints the contents of a file, from the first line to the last. Given several files, it prints them one after another as a single stream.
The terminal on this page has a few short text files in it.
$ cat notes.txt
buy milk
call the bank
fix the login bug
That is the whole file.
cat only reads, it never writes anything back.
-n prints a line number in front of every line.
That saves you counting when someone says the error is on line 12.
$ cat -n notes.txt
1 buy milk
2 call the bank
3 fix the login bug
List several files and they come out in that order.
$ cat notes.txt todo.txt
buy milk
call the bank
fix the login bug
write tests
update the docs
Nothing marks where one file ends and the next begins. When you need that boundary, look at the files one at a time.
cat earns its keep as the way to feed a file into the next command.
| Situation | What you type |
|---|---|
| Glance at a config file | cat config.json |
| Pull specific lines out of it | cat app.log | grep ERROR |
| Join two files into one | cat part1.txt part2.txt > all.txt |
| Count the lines | cat notes.txt | wc -l |
For a long file, piping into head keeps it from scrolling away.
$ cat logs/app.log | head -3
INFO request handled
INFO request handled
INFO request handled
It is the wrong tool for long files.
A file with thousands of lines prints all of them, and everything but the last screenful is gone.
Use less to read, or head and tail for the ends.
A missing file is an error.
$ cat nope.txt
cat: nope.txt: No such file or directory
Either the name is misspelled, or you are not in the directory you think you are in.
Directories are not files.
cat reads file contents, so use ls when you want to see what is inside a directory.
webterm.appthis site
Terminal Fundamentals
Learn commonly used commands
learn.webterm.appa separate site

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.
See the course