How to make output of any shell command unbuffered?

bodacydo picture bodacydo · Aug 12, 2010 · Viewed 61.6k times · Source

Is there a way to run shell commands without output buffering?

For example, hexdump file | ./my_script will only pass input from hexdump to my_script in buffered chunks, not line by line.

Actually I want to know a general solution how to make any command unbuffered?

Answer

lambshaanxy picture lambshaanxy · Aug 28, 2014

Try stdbuf, included in GNU coreutils and thus virtually any Linux distro. This sets the buffer length for input, output and error to zero:

stdbuf -i0 -o0 -e0 command