find -exec
Watch / findexec
Filmed on the Apple IIe 80-column display. The same session on the Videx UltraTerm: same keys, same text.
The Videx UltraTerm was an 80-column video card for the Apple IIe, with its own video memory and character generator, real hardware scrolling and more screen modes than the IIe's own 80 columns. This demo runs on either display; the UltraTerm film shows the original Videx UltraTerm, emulated.
About as canonically Unix as a command line gets. find walks the manual, a glob picks the pages whose names begin with S, and -exec runs grep -l on each of them, one process per page, to say which mention a word.
What it types
Everything it types, in order. A line starting with $ is a command at the shell, RET included; keys lines are single keystrokes to a program (RET, ESC and the control keys are named).
$ cd /usr/man
$ find . -name 'S*'
$ find . -name 'S*' -exec grep -l expression {} \;
Between steps it presses ^L to clear the screen.
What the captions say
- find: walk a tree, match names, run a program on each hit.
- Now -exec: grep -l runs once for every page that matched.
- A tree walk, a glob, a spawn per hit: on a 1 MHz 65C02.
- Ken Thompson, by repute: when in doubt, use brute force.
The gate that proves it
This film is made by site/demos/findexec.py. Run as assertions, the
same file is make check-demo-findexec, and it runs with the rest of the tests. It requires that find lists exactly the pages whose names begin with S, and that the -exec run names exactly the pages that mention the word. Both lists are computed on the host from the image. The checks themselves were tested: with grep replaced by a copy of true the demo fails at "only the pages that mention the word are named"; with find replaced by true it fails at "find lists every page".
Transcript
The screen at every checkpoint the test checks, as the recorder saved it:
== find lists every page whose name starts with S (t=11.5 s)
$ cd /usr/man
$ find . -name 'S*'
./SACT
./SCCS
./SED
./SH
./SHUTDOWN
./SLEEP
./SORT
./SPLIT
./STRINGS
./STRIP
./STTY
./SUM
$
== only the pages that mention "expression" are named (t=44.4 s)
$ find . -name 'S*' -exec grep -l expression {} \;
./SED
./SH
$
== host: the filter is selective (t=44.4 s)
$ find . -name 'S*' -exec grep -l expression {} \;
./SED
./SH
$