Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsThe cat command copies file contents or standard input to standard output. Use it to display a file, send several files to the terminal in order, or pass their contents to another command. Its basic stream-copy behavior is broadly useful, but flags such as line numbering and visible-whitespace options can vary between implementations.
What does cat do?
The GNU Coreutils 9.11 manual describes it this way: “cat copies each file (‘-’ means standard input), or standard input if none are given, to standard output.” In practical terms, cat reads its input and writes it out unchanged unless an option requests a display transformation.
As an Amazon Associate I earn from qualifying purchases.
The GNU syntax is cat [option]... [file].... With several file operands, cat writes their contents consecutively in the order supplied. Standard output is usually the terminal, but it can also be redirected or connected to another command.
How to display or combine files
Display one file
Run cat notes.txt to write the contents of notes.txt to standard output.
#1 Best Overall
Display files consecutively
Supply the files in the order you want them emitted: cat first.txt second.txt. The command writes the contents of first.txt and then second.txt; it does not insert a separator between them.
Read from standard input
With no file operand, cat reads standard input and copies it to standard output. If you run cat interactively in a terminal, type the input and use the terminal or shell’s end-of-input keystroke to finish. In GNU cat, the operand - also means standard input.
Rank #2
Insert standard input between files
GNU cat can place standard input in the sequence of named files. For example, cat first.txt - second.txt writes first.txt, then reads standard input, then writes second.txt.
Useful GNU options for inspecting text
These option descriptions are for GNU Coreutils 9.11. Check man cat on the target system when portability matters.
| Option | Effect |
|---|---|
-n |
Number every output line, starting at 1. |
-b |
Number nonempty lines only; this takes precedence over -n. |
-s |
Suppress repeated adjacent blank lines, leaving one blank line. |
-E |
Show line endings with $. |
-T |
Show tab characters as ^I. |
-v |
Show many nonprinting characters using visible notation. |
-A |
Equivalent to -vET, showing nonprinting characters, line endings, and tabs. |
Examples
cat -n notes.txtnumbers every output line.cat -b notes.txtnumbers only nonblank lines.cat -A notes.txtmakes tabs, line endings, and many nonprinting characters easier to spot.
GNU also documents -e as equivalent to -vE and -t as equivalent to -vT. GNU cat ignores -u, retaining it for POSIX compatibility.
When to use cat, and when to check portability
Use cat when you want to emit one or more input streams to standard output, combine files in a specified order, or pass file contents into another command. Its job is to copy streams; options such as numbering or making whitespace visible change how output is presented.
Rank #4
For scripts intended to run on different Unix-like systems, the basic file and standard-input behavior is the safest assumption from the command references consulted. GNU’s -n, -b, -E, -T, and -A options may not be available everywhere. POSIX documents -u, while GNU says it ignores that flag, illustrating why option behavior should be checked on the system where a script will run.
GNU documents an exit status of zero for success and nonzero for failure. If a command fails, consult the local manual and check the named input files and the way standard input is being supplied.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




