What does `head -c` do?

QuestionsQuestions8 SkillsProDec, 17 2025
0108

head -c is a command used in Linux (and other Unix-like systems) to display a specific number of bytes from the beginning of a file.

Let's break it down:

  • head: This is the command itself. Its primary function is to output the first part of files. By default, head shows the first 10 lines of a file.
  • -c: This is an option (or flag) for the head command. It tells head to count by bytes rather than by lines.
  • NUMBER: After -c, you specify the number of bytes you want to display. So, -c1 means 1 byte, -c5 means 5 bytes, and so on.

Example:

If your file /tmp/hello contains:

Hi,
I am Labby!
  • head -c1 /tmp/hello would output H (the first byte).
  • head -c5 /tmp/hello would output Hi, and then a newline character, so it would look like:
    Hi,
    (including the space and the newline character as bytes).

This is useful when you want to examine just a small, precise portion of a file's content, especially for binary files or when you need byte-level precision.

Does that explanation clarify what head -c does, Labber?

0 Comments

no data
Be the first to share your comment!