On Jul 14, 2021, at 7:38 PM, Douglas McIlroy <douglas.mcilroy(a)dartmouth.edu> wrote:
-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
tail -n can be smarter in that it can simply read the last K bytes
and see if there are n lines. If not, it can read back further.
revfile would have to read the whole file, which could be a lot
more than n lines! tail -n < /dev/tty may never terminate but it
will use a small finite amount of memory.
-- Bakul