cat - Read Files in the Terminal
Learn cat for displaying file contents. The simplest way to read files and start pipelines.
cat: See What's in a File
You want to see what's in a file. You could open it in an editor. Or:
cat file.txt
The entire contents appear in your terminal. That's cat.
The name comes from "concatenate" - its original purpose was joining files together. But 99% of the time, you're just using it to read stuff.
Reading a File
cat readme.txt
The whole file, printed to your screen.
Reading Multiple Files
cat file1.txt file2.txt
Both files, one after the other. This is the "concatenate" part.
Starting a Pipeline
cat is often how you feed data into other commands:
cat log.txt | grep "error"
Read the file, then filter for errors.
cat data.txt | sort | uniq -c
Read the file, then run it through analysis.
Wildcards
cat .txt
All text files in the current directory, concatenated.
That's Really It
cat is dead simple. It reads files and outputs them. The power comes from what you pipe that output into.
Quick Reference
| What you want | Command |
|---------------|---------|
| Read a file | cat file.txt |
| Read multiple files | cat file1.txt file2.txt |
| All matching files | cat .log |
| Start a pipeline | cat file \| grep pattern |
See Also
- head - just the beginning
- tail - just the end
- grep - search within
Practice
In CTF challenges, cat flag.txt is often how the challenge ends. Simple, but satisfying.
cat is the "hello world" of file reading. Everyone starts here.