Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

How to Use `cat`, `less`, and `head` to Read Text Files in Linux

Use cat for short files and pipelines, head for a quick beginning-of-file preview, and less to scroll through or search longer text in a Linux terminal.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use cat to print a short file or send its contents into another command, head to preview the beginning, and less to scroll through or search a longer file. The examples below assume each named file exists and is readable.

Choose the command for the job

What you need Command What it does
Print a short file or pass its contents to another command cat file.txt Writes the file’s contents to standard output.
Check the beginning of a file head file.txt Shows the first 10 lines by default.
Scroll through or search a longer file less file.txt Opens an interactive pager for browsing.
Read several files in sequence cat one.txt two.txt or less one.txt two.txt cat streams their contents together; less lets you browse them interactively.

Print or combine content with cat

Run cat followed by a filename to write the file’s contents to the terminal:

As an Amazon Associate I earn from qualifying purchases.

cat README.txt

GNU Coreutils describes cat as copying each file—or standard input when no files are given—to standard output. That makes it useful for short files and pipelines, but it does not provide scrolling or search. A long file can fill the terminal’s scrollback; use less when you want to browse instead. See the GNU Coreutils cat documentation.

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

To stream two files one after another, list both names:

cat first.txt second.txt

With no filename, cat waits for standard input. In an interactive terminal, type the text and press Ctrl-D to signal the end of input. You can also pass file contents to another command with a pipe:

cat notes.txt | less

GNU Coreutils also documents options such as -n to number every output line, -b to number nonempty lines, and -A to make line endings, tabs, and nonprinting characters more visible. These are GNU-specific options, not a guarantee for every Unix-like system.

Preview the beginning with head

By default, head prints the first 10 lines of a file:

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Use -n to choose a line count, or GNU head -c to choose a byte count:

head -n 25 report.txt
head -c 300 report.txt

For example, to take just the first two lines from text produced by another command:

printf 'alphanbetangamman' | head -n 2

GNU head reads standard input if you give it no filenames, or if you use - as a filename. When given multiple files, it prints a header naming each file by default; -q suppresses those headers and -v requests them. Prefer explicit -n or -c forms in scripts; the GNU manual marks an older compact option syntax obsolete. See the GNU Coreutils head documentation.

head is a bounded preview, not a navigation tool: it shows the start rather than letting you move around the file.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Browse and search with less

Open a file in the pager by running:

less /var/log/example.log

Use these basic keys to navigate:

  • Press Space or f to move forward.
  • Press b to move backward.
  • Type /pattern and press Enter to search forward for a pattern; press n to go to the next match.
  • Press q to quit.

You can also pipe command output into the pager when it is too long to inspect in the terminal window:

journalctl | less

The Linux less(1) manual page says that less can start before it has read the entire input file. For a file that is changing, less +F filename enters forward-follow behavior at the end of the file; press Ctrl-C to return to ordinary navigation.

Version and portability notes

The GNU-specific cat and head behavior described here follows the GNU Coreutils 9.11 manual. The cited Linux less(1) page identifies less 704 and is dated 30 May 2026. Other Unix-like systems may have different implementations or options, so check the local manual page if a GNU-specific flag is unavailable. The general task choice—stream a short file with cat, preview its beginning with head, or browse with less—is based on the documented behavior of these commands.

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.

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

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.