[TUHS] head/sed/tail (was The Unix shell: a 50-year view)

Douglas McIlroy douglas.mcilroy at dartmouth.edu
Thu Jul 15 12:38:06 AEST 2021


This somewhat stale note was sent some time ago, but was ignored
because it was sent from an unregistered email address.

> And if the Unix patriarchs were perhaps mistaken about how useful
> "head" might be and whether or not it should have been considered
> verboten.

Point well taken.

I don't know which of head(1) and sed(1) came first. They appeared in
different places at more or less the same time. We in Research
declined to adopt head because we already knew the idiom "sed 10q".
However one shouldn't have to do related operations in unrelated ways.
We finally admitted head in v10.

Head was independently invented by Mike Lesk. It was Lesk's
program that was deemed superfluous.

Head might not have been written if tail didn't exist. But, unlike head,
tail strayed from the tao of "do one thing well". Tail -r and tail -f are
as cringeworthy as cat -v.

-f is a strange feature that effectively turns a regular file into a pipe
with memory by polling for new data, A clean general alternative
might be to provide an open(2) mode that makes reads at the current
file end block if some process has the file open for writing.

-r is weird because it enables backwards reading, but only as
limited by count. Better would be a program, say revfile, that simply
reads backwards by lines. Then tail p  has an elegant implementation:
       revfile p | head | revfile

Doug


More information about the TUHS mailing list