Skip to main content

Command referencehead

head command (Linux / bash / sh / zsh)

Linuxbashshzshtextbeginner

What it does

Print the beginning of files or standard input. When people search for the head command linux lines, they usually want head's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.

Print the beginning of files or standard input.

Syntax

head [OPTION]... [FILE]...

Common options

Flag / optionMeaning
-n NPrint the first N lines.
-c NPrint the first N bytes.
-qSuppress file-name headers.
-vAlways print file-name headers.

Practical examples

First ten lines

head app.log

Prints the default ten lines.

CSV header

head -n 1 data.csv

Prints only the first row.

Preview bytes

head -c 64 binary.dat | xxd

Feeds the first 64 bytes to a hex viewer.

Common mistakes

  • Assuming `-c` counts characters; it counts bytes.
  • Using head as a safe parser for multiline structured records.

FAQ

What does head do in Linux?

Print the beginning of files or standard input.

How do I use head from the terminal?

Start with `head [OPTION]... [FILE]...`, then choose only the options needed for the task.

What is a practical head example?

Try `head app.log` — Prints the default ten lines.

Can I use head in a shell script?

Yes. head works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.