October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

How to Use the cat Command in Linux and Unix

The cat command copies files or standard input to standard output. Learn its basic syntax, common GNU inspection options, and portability limits.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to display or combine files

Display one file

Run cat notes.txt to write the contents of notes.txt to standard output.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.txt numbers every output line.
  • cat -b notes.txt numbers only nonblank lines.
  • cat -A notes.txt makes 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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.