Bash View Start of File

head prints the first lines of a file, which is the quickest way to peek at how a file begins without loading the whole thing.

Why Use head Instead of cat

Opening a huge log file or CSV with cat floods your terminal with thousands of lines. head solves this by printing only the beginning — 10 lines by default — so you can quickly check a file's format, header row, or first entries.

Default: first 10 lines

$ head access.log
192.168.1.5 - - [16/Jul/2026:09:00:01] "GET /"
192.168.1.5 - - [16/Jul/2026:09:00:02] "GET /style.css"
192.168.1.5 - - [16/Jul/2026:09:00:03] "GET /app.js"
... (7 more lines)

Choosing How Many Lines with -n

The -n flag takes a number and tells head exactly how many lines to print instead of the default 10. You can also skip the letter and glue the number straight onto the flag, like -3, as a shorthand.

Show only the first 3 lines

$ head -n 3 access.log
192.168.1.5 - - [16/Jul/2026:09:00:01] "GET /"
192.168.1.5 - - [16/Jul/2026:09:00:02] "GET /style.css"
192.168.1.5 - - [16/Jul/2026:09:00:03] "GET /app.js"

Checking Multiple Files at Once

Pass several filenames and head prints a ==> filename <== banner before each file's output, making it easy to compare how a batch of files begins in a single command.

Peek at two log files

$ head -n 2 jan.log feb.log
==> jan.log <==
Jan 1 00:00:01 boot sequence started
Jan 1 00:00:02 network interface up

==> feb.log <==
Feb 1 00:00:01 boot sequence started
Feb 1 00:00:02 network interface up
  • head file — print the first 10 lines
  • head -n 20 file — print the first 20 lines
  • head -c 200 file — print the first 200 bytes instead of lines
  • head -n -5 file — print everything except the last 5 lines
  • head -q file1 file2 — hide the filename banners
FlagMeaning
-n NPrint the first N lines
-c NPrint the first N bytes
-n -NPrint all lines except the last N (GNU coreutils)
-qSuppress the ==> filename <== headers
Note: head only reads as far as it needs to, so it stays fast and safe even on multi-gigabyte files — it never loads the whole file into memory.