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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Use cat to display a whole file, head to show its beginning, and tail to inspect its ending or watch new log entries appear. These commands display or stream file contents; they do not edit, move, or delete files.

Choose the right command

Command What it displays GNU default Example
cat All supplied input, including multiple files in sequence Entire input cat notes.txt
head The beginning of a file First 10 lines head -n 5 notes.txt
tail The ending of a file; can also follow appended output Last 10 lines tail -n 20 notes.txt

The defaults and options described here are documented for GNU Coreutils 9.11. Other implementations may differ, so check the manual installed on your system if an option behaves differently.

Display a complete file with cat

Run cat followed by a filename to send 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

To display several files one after another, list them in order:

cat part1.txt part2.txt

cat can also read standard input when no filename is supplied, or when you use - as an input name. For example, cat - reads from standard input and writes what it receives to standard output. Because it prints the whole input, cat is convenient for short files; for a large file, showing a selected section with head or tail is generally easier to inspect.

Show line numbers or make characters visible

GNU cat offers a few useful 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 shows tab characters.
  • cat -v notes.txt reveals nonprinting characters.
  • cat -s notes.txt squeezes repeated adjacent blank lines.

Preview a file’s beginning with head

GNU head prints the first 10 lines by default:

head notes.txt

Use -n with a number to choose a different line count. This example shows the first five lines:

head -n 5 notes.txt

When you supply multiple filenames, GNU head identifies each input with a header in its output.

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

Inspect a file’s ending with tail

GNU tail prints the last 10 lines by default. To see a longer ending, specify the number of lines with -n:

tail -n 20 notes.txt

For multiple input files, GNU tail prints a header identifying each file.

Follow a log as it grows

Use -f to keep displaying new content appended to a file. For example:

tail -f /var/log/example.log

This is useful when monitoring a log while another process is writing to it. The command continues running as new output arrives; stop it with Ctrl+C. Follow behavior and additional options can vary by implementation, so consult your system’s tail manual for specifics.

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

Know what these commands do—and do not do

cat, head, and tail output file contents; they are not file editors or general file-management commands. The GNU Coreutils manual treats displaying whole files and parts of files separately from operations such as copying, moving, and deleting. To check available options on your system, use man cat, man head, or man tail.

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.