thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

Unbuffer

• 114 words • 1 min • updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

The unbuffer binary comes from the expect package. I didn’t realize until now that it is hosted in NIST.gov!

There are two scenarios in which I find unbuffer quite helpful:

  1. flush stdout line output immediately, in programs such as tail or python. Julia Evans noted this in a blog post:
shell
% tail -f /some/log/file | unbuffer grep thing1 | grep thing2

Without unbuffer there’s no guarantee tail would print its stdout output in real time.

  1. force stdout to write to a TTY (or to pretend that it will write to a TTY):
shell
% unbuffer ls --color=auto | less -R

In this example, less will properly recognize and display color output from ls.