The cat command in Linux concatenates files and writes them to standard output. With one file it simply prints that file; with several files it prints them one after another. On Ubuntu and other GNU/Linux systems (GNU coreutils):
cat [OPTION]... [FILE]...
With no FILE, or when FILE is -, cat reads standard input. Success means the content appears on your terminal (or in a redirected file). For long files, prefer less or more so you can scroll—Ubuntu’s CLI tutorials recommend less for paging.
Official reference: Ubuntu man page cat(1) — run man cat or cat --help locally.
If you already know your goal, jump to: create a file, append, concatenate, line numbers, or cat vs less.
Building a broader CLI toolkit? See essential Linux commands and the cheat sheet.

What Cat Is For
| Use | Example idea |
|---|---|
| Show a short file | cat notes.txt |
| Join files | cat a.txt b.txt > all.txt |
| Create/overwrite a file | cat > new.txt then type, Ctrl+D |
| Append to a file | cat >> log.txt |
| Pipe content into another command | cat file | grep error |
| Reveal hidden characters | cat -A file / cat -T file |
cat does not open an interactive editor (use nano/vim) and is a poor pager for huge logs.
Basic: Print a File
cat file.txt
cat /etc/hostname
Multiple files print in order:
cat part1.txt part2.txt part3.txt
Create or Overwrite a File (cat >)
cat > hello.txt
Hello from cat
This is line 2
Press Ctrl+D (EOF) to finish. This overwrites hello.txt if it already exists.
Safer for beginners: confirm the path before using > so you do not wipe an important file.
Append to a File (cat >>)
cat >> hello.txt
Extra line added later
Ctrl+D again. >> appends; > truncates.
Heredoc: Write Multi-Line Content in One Shot
Common shell pattern (also used in install scripts):
cat > config.env << 'EOF'
NAME=demo
DEBUG=true
EOF
Quoted 'EOF' keeps variables from expanding. Unquoted EOF allows $VAR expansion.
Concatenate Files into One
# Print joined content on screen
cat chapter1.md chapter2.md
# Write joined content to a new file
cat chapter1.md chapter2.md > book.md
# Append more files onto an existing file
cat chapter3.md >> book.md
Name comes from catenate—this is the original purpose.
Mix Files and Standard Input
From the man page examples:
# Print f, then whatever you type, then g
cat f - g
# Copy stdin to stdout (filter/pass-through)
cat
- means “read stdin at this position in the list.”
Useful Cat Options (GNU)
| Option | Meaning |
|---|---|
-n / --number | Number all output lines |
-b / --number-nonblank | Number nonempty lines only (overrides -n) |
-s / --squeeze-blank | Squeeze repeated blank lines |
-E / --show-ends | Show $ at end of each line |
-T / --show-tabs | Show tabs as ^I |
-v / --show-nonprinting | Show non-printing chars (^ / M- notation) |
-A / --show-all | Same as -vET |
-e | Same as -vE |
-t | Same as -vT |
-u | Ignored (POSIX compatibility) |
Examples:
cat -n script.sh # numbered lines
cat -b messy.txt # skip numbering blank lines
cat -s doublespaced.txt # squeeze blank lines
cat -A weird.txt # see tabs, line ends, odd chars
Cat in Pipelines
cat access.log | grep "404"
cat *.conf | wc -l
Often you can skip cat and pass the file to the next tool (grep "404" access.log)—a classic Unix efficiency tip. Keep cat when you need to join multiple files first or when teaching stdin flow.
Cat vs Less (and Related Tools)
| Tool | Best for |
|---|---|
cat | Short files; joining; simple create/append |
less | Long files you need to scroll (q to quit) |
tac | Reverse line order (GNU) |
less big.log
cat -n script.sh
zcat file.txt.gz | less
Ask Ubuntu and Ubuntu docs often point people to less when cat floods the terminal. For the last lines of a log—or live follow—use the tail command in Linux guide instead of stretching cat.
Permissions and Common Errors
cat: file.txt: No such file or directory
cat: secret.key: Permission denied
- Check the path with
ls/pwd - Use
sudo cat /etc/shadowonly when you truly need root-readable files—avoid redirecting sudo output wrongly:
# Wrong: shell opens out.txt as you, before sudo
sudo cat /etc/hosts > /root/out.txt
# Better pattern
sudo tee /root/out.txt < /etc/hosts >/dev/null
# or
sudo bash -c 'cat /etc/hosts > /root/out.txt'
Redirection under root is easier with tee—covered in depth in the sudo and echo guides.
Quick Cheat Sheet
cat file.txt # view
cat a.txt b.txt > c.txt # concatenate
cat > new.txt # create (Ctrl+D to end)
cat >> new.txt # append
cat -n file.txt # number lines
cat -A file.txt # show tabs/ends/nonprinting
man cat # full manual
From Terminal Text to Shareable Documents
cat is perfect for printing, joining, and redirecting plain text. Once that text needs to become a formatted handoff, you usually want a desktop document instead of another shell redirect.
WPS Office for Linux fills that next step with Writer, Spreadsheet, Presentation, and PDF tools on Ubuntu.

| What you need next | What WPS gives you |
|---|---|
| Move plain text into DOCX, sheets, or PDFs | Strong .docx / .xlsx / .pptx layout fidelity when files move between Linux, Windows, and macOS |
| One place for notes, sheets, slides, and PDFs | Free core suite: Writer, Spreadsheet, Presentation, plus PDF view/edit/convert tools |
| A familiar desktop UI for switchers | Ribbon-style apps with a lighter footprint than many heavy suites |
| A trusted install path | Official DEB (Ubuntu/Debian/Mint) and RPM packages from the vendor |
Download the package from the official WPS Office for Linux download page, install it with sudo apt install ./wps-office_VERSION_amd64.deb, then paste your terminal text into Writer or export it as PDF when it needs a cleaner final form.
FAQ
What does the cat command do in Linux?
It concatenates files and prints them to standard output—commonly used to display or join text files.
How do I create a file with cat?cat > filename, type content, then Ctrl+D. Use >> to append instead of overwrite.
How do I merge two files with cat?cat file1 file2 > merged.txt
When should I use less instead of cat?
When the file is long and you need scrolling, search, or to avoid flooding the terminal.
What does cat -n do?
Numbers all output lines. Use cat -b to number only nonempty lines.
Where is the official documentation?
Run man cat or see the Ubuntu cat(1) man page.




