Skip to main content
head, tail, wc -l and tail -f can ask your VFS for lines or a count, instead of reading the file. Return exactly what a read would hold, or None (TypeScript: null) and Mirage reads the file. For example, PostgreSQL answers head -n 20 rows.jsonl with LIMIT 20 and wc -l rows.jsonl with COUNT(*).

first_lines

The first lines of one file.
These commands call first_lines:
  • head: the first 10 lines
  • head -n N, head -N: the first N lines
These read the file instead:
  • head -c N: the first N bytes
  • head -n -N: all but the last N lines
  • head -z: lines end with NUL
  • standard input

last_lines

The last lines of one file.
These commands call last_lines:
  • tail: the last 10 lines
  • tail -n N, tail -N: the last N lines
These read the file instead:
  • tail -c N: the last N bytes
  • tail -n +N: from line N on
  • standard input

line_count

The number of lines in one file.
This command calls line_count:
  • wc -l
These read the file instead:
  • wc with another count: -c, -w, -m or -L
  • standard input

Example: head, tail and wc -l

This example extends NotesVFS from Custom VFS:
head -n 1, tail -n 1 and wc -l on a page then read nothing. head -c 3 still reads it.

follow

The last lines of one file, then each new line as it arrives.
These commands call follow:
  • tail -f, tail -f -n N on one file
These read the file every interval seconds instead:
  • tail -F, tail --follow=name: follow the name, not the file
  • tail -f -c N
  • tail -f -n +N
  • tail -f on more than one file
This example extends the same NotesVFS. A real service would push new lines over a stream; this one checks the dictionary every interval seconds. It yields on every check, an empty chunk when nothing is new, so a stopped tail -f closes it within one interval, and it starts over when the page shrinks: