Skip to content

Your first count

By the end of this chapter you can run tokei on a folder, read its table column by column, ask for the per-file detail — and explain the first surprise the table contains.

All of this chapter happens in the lab's basics tree, three small files written for the purpose, each counted by hand before tokei saw it:

  • greet.py — ten lines of Python
  • block.c — ten lines of C
  • notes.md — eight lines of Markdown, one of them a line of Python in a fenced block

The table

$ tokei tokei-lab/fixtures/basics
 Language              Files        Lines         Code     Comments       Blanks
 C                         1           10            6            3            1
 Markdown                  1            7            0            5            2
 |- Python                 1            1            1            0            0
 (Total)                                8            1            5            2
 Python                    1           10            5            2            3
 Total                     3           28           12           10            6

The full table is in transcript tokei-lab/transcripts/t01-first-count.txt; its totals row reads 3 files, 28 lines, 12 code, 10 comments, 6 blanks. Read the columns as:

  • Files — how many files the detector claimed for this language.
  • Lines — every line in those files, of all three kinds.
  • Code, Comments, Blanks — the split, which always sums back to Lines: 12 + 10 + 6 = 28.

The C and Python rows match the hand counts exactly — six code lines in the C file, for instance, including the line where a string contains what looks like the start of a comment (chapter 6 takes that line apart).

The Markdown surprise

The Markdown row is the first place a rule speaks. The file's prose lines — a heading, two sentences — are counted as comments, all five of them, and its Code column is zero. Under tokei's definition, Markdown is a prose language: its lines are commentary unless they are something else.

One of them is something else. The fenced block near the end —

```python
print("shelf three")
```

— is counted as an embedded language: a Python child under the Markdown row, contributing the single Code line to that file's (Total). The two fence lines themselves stay with Markdown. So notes.md is eight physical lines, reported as seven Markdown and one Python — partitioned, not double-counted. Chapter 7 meets files where the partition works differently.

Per-file detail

--files asks for the receipts:

$ tokei --files tokei-lab/fixtures/basics
...
 |b/fixtures/basics/greet.py           10            5            2            3

Each language gains a line per file, in the same five numbers. Two things to know about this view: long paths are trimmed from the left to fit the column (the | marks a path that was cut), and this is the view every later chapter uses, because a rule can only be checked against a single file.

Check: run tokei on a folder of your own, pick the language you know best, and verify one file's split against --files. If the three numbers sum to its Lines, you have this chapter.