Text

head

Print the beginning of files.

textfilepreviewbeginninglines

Additional Notes

head prints the first part of a file or input stream. By default, it shows the first 10 lines.

It is useful when you want to preview a file without opening the whole thing.

Syntax

head [options] [file...]

Parameters

  • options: Flags that change how head behaves.
  • file: Text file to read or process.

Common Options

  • -n N, --lines=N: Print the first N lines.
  • -c N, --bytes=N: Print the first N bytes.
  • -q, --quiet: Do not print file headers when reading multiple files.
  • -v, --verbose: Always print file headers.

Examples

head file.txt

Show the first 10 lines.

head -n 20 app.log

Show the first 20 lines.

head -c 100 data.bin

Show the first 100 bytes.

head *.log

Preview multiple log files.

command | head

Show only the beginning of command output.

Practical Notes

  • Use tail to view the end of a file.
  • Use less for scrolling and searching.
  • head is safe for large files because it stops early.
  • For CSV files, head -n 1 file.csv often shows the header.