How `tail -c` counts bytes?

QuestionsQuestions8 SkillsProDec, 21 2025
0104

Actually, tail -c counts from the end of the file backwards.

Here is exactly how it works:

1. Simple Counting (Last X Bytes)

When you use a command like tail -c 5, the computer:

  1. Goes to the very last byte of the file.
  2. Moves backward 5 bytes.
  3. Prints everything from that point until the end.

2. Why -c1 vs -c2 matters in your case

As you saw in the lab, tail -c1 showed "nothing" while tail -c2 showed !. Here is the byte-by-byte visual of the end of /tmp/hello:

Byte Position Character Visible?
Last-1 ! Yes
Last (End) \n (Newline) No (it's just a "return" instruction)
  • tail -c1: Grabs only the \n. Your terminal moves to a new line, but you see no text.
  • tail -c2: Grabs ! AND \n. You see the !.

3. The "Hidden" Offset Mode (+)

Interestingly, tail -c has a "secret" mode. If you put a plus sign before the number, it counts starting from the beginning instead of the end:

  • tail -c +5: This tells Linux, "Skip the first 4 bytes and show me everything from the 5th byte to the end of the file."

Summary

  • Without +: Count backward from the end (show the last X bytes).
  • With +: Count forward from the start (skip the first X-1 bytes).

In most daily tasks, people use it without the + to quickly check the "footer" or trailing metadata of a data file

0 Comments

no data
Be the first to share your comment!