Linux command list

cat command: print the contents of a file

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying cat. Nothing here can touch your real files.
user@webterm:~/project$
 

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

Syntax

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.

Try it first

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.

Adding line numbers

-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

Joining files together

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.

When you actually reach for it

cat earns its keep as the way to feed a file into the next command.

SituationWhat you type
Glance at a config filecat config.json
Pull specific lines out of itcat app.log | grep ERROR
Join two files into onecat part1.txt part2.txt > all.txt
Count the linescat 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

Things that trip people up

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.

Practise it hands-on

webterm.appthis site

learn.webterm.appa separate site

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

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

Related commands

less / head / tail / grep

Frequently asked questions

What does cat stand for?
Concatenate. It was built to join files together and print them, so passing a single file is really the special case.
What happens if I cat a long file?
Every line scrolls past at once and only the last screenful stays visible. For long files reach for less, head or tail instead.
When should I use cat and when less?
Use cat for short files that fit on screen, and less for anything you need to scroll. cat prints and exits, less opens a screen for reading.
What if I accidentally cat a binary file?
Bytes that are not text get printed as-is, which can scramble your terminal. Typing reset restores it.
Can I create a file with cat?
Yes. cat > filename writes what you type into that file, but it replaces the existing contents. Use >> when you want to append.