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 desk3 min

How to Read a File’s Start or End in Linux

Use cat for whole files, head for the beginning, and tail for the ending or for watching appended log output. Includes practical examples and GNU option notes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use cat to display or combine whole files, head to inspect the beginning, and tail to inspect the end or watch new output as it appears. These commands show or stream content; they do not edit, move, or delete files.

Which command should you use?

Command What it displays GNU default Example
cat All supplied input; can display several files in sequence All input cat notes.txt
head The beginning of a file First 10 lines head -n 5 notes.txt
tail The end of a file, or new content as it is appended Last 10 lines tail -n 20 notes.txt

The defaults in this table are those documented for GNU Coreutils 9.11; other Unix-like systems may use different options or behavior. See the GNU cat manual and the GNU head and GNU tail manuals for details.

As an Amazon Associate I earn from qualifying purchases.

Display a whole file with cat

Run cat followed by a filename to write the file’s contents to standard output, which normally appears in your terminal:

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

With multiple filenames, cat writes their contents one after another:

cat part1.txt part2.txt

It does not add a separator between files. If the first file does not end with a newline, the next file’s content can begin on the same displayed line. Use cat for short files or when you intentionally want to combine input streams; for a long file, showing only a portion with head or tail is usually easier to inspect.

With no filename, or with - as an input name, GNU cat reads standard input. For example, some-command | cat passes that command’s output through to the terminal.

Useful GNU cat display options

  • cat -n notes.txt numbers every output line.
  • cat -b notes.txt numbers nonempty lines.
  • cat -E notes.txt marks line endings.
  • cat -T notes.txt makes tab characters visible.
  • cat -v notes.txt displays many nonprinting characters in a visible form.
  • cat -s notes.txt squeezes repeated adjacent blank lines into one.

These options affect what is shown, not the contents saved in the file.

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

Preview the beginning with head

Use head when you want a quick look at the first lines, such as the opening of a text file or log:

head notes.txt

GNU head displays the first 10 lines by default. Specify a different line count with -n:

head -n 5 notes.txt

This prints up to the first five lines. When given multiple filenames, GNU head prints a heading identifying each input file.

Inspect the ending or follow updates with tail

Use tail to see the most recent lines at the end of a file:

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

GNU tail shows the last 10 lines by default. To request more or fewer, use -n:

tail -n 20 notes.txt

To keep displaying content as it is appended, use follow mode:

tail -f /var/log/example.log

This is useful for observing a log while another process writes to it. Stop the running command with Ctrl+C. Follow behavior and available options can vary by implementation; consult the manual installed on your system if the file is replaced or rotated and you need specific follow behavior. With multiple input files, GNU tail prints a heading identifying each one.

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

Do these commands manage or change files?

In this context, “manage” means inspect or stream file contents. cat, head, and tail write output; they are not substitutes for an editor and do not provide general file operations such as copying, moving, or deleting. The GNU Coreutils basic operations documentation treats those operations separately from displaying whole files or parts of files.

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

Check options on your Linux system

The examples use common GNU forms, but Linux distributions and other Unix-like systems may ship different implementations. If an option is rejected or behaves differently, check the local manual pages with man cat, man head, or man tail. The Debian Bookworm cat(1) manual is one example of distribution-specific documentation.

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 *

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.

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
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.