๐Ÿ“š General & Other

tac, tail, and Reading Large Files Backwards

reverses line order โ€” backwards, and named accordingly. How it does that decides whether it works on very large files.

tac reverses line order โ€” cat backwards, and named accordingly. How it does that decides whether it works on very large files.

Seekable input is read backwards efficiently

Given a regular file, tac seeks to the end and reads blocks backwards, so memory stays flat regardless of size. Given a pipe, it cannot seek, so it buffers the entire stream โ€” which on a multi-gigabyte input means holding all of it in memory. Pass a filename rather than piping into it when the input is large.

tail is the better tool for the recent end

If the question is only about the last N lines, tail -n 1000 seeks directly to that region and reads nothing else. Reversing an entire file to look at its end is wasteful when the file is large.

Reverse order is not descending sort

tac inverts existing order. sort -r imposes descending order. On unsorted data these produce completely different results, and confusing them is a common source of output that looks plausible and is wrong.

Try it: Reverse Line Order on SeoWolf's Notepad.