LinuxCommandLibrary

stdbuf

Adjust stream buffering of commands

TLDR

Line buffered stdout

$ stdbuf -oL [command]
copy
Unbuffered stdout
$ stdbuf -o0 [command]
copy
Unbuffered stderr
$ stdbuf -e0 [command]
copy
Fully buffered stdin
$ stdbuf -i[1M] [command]
copy
Line buffered all streams
$ stdbuf -oL -eL [command]
copy
Combine with grep
$ stdbuf -oL [command] | grep [pattern]
copy

SYNOPSIS

stdbuf [-i mode] [-o mode] [-e mode] command [args]

DESCRIPTION

stdbuf runs a command with modified standard stream buffering. When programs detect their output is going to a pipe rather than a terminal, they typically switch from line-buffered to fully-buffered output, which delays output. stdbuf overrides this behavior using LD_PRELOAD to intercept buffering calls.
The three modes are: line-buffered (L) which flushes after each newline, unbuffered (0) which flushes immediately, and a specific buffer size. This is particularly useful when piping output through filters like grep or awk where real-time output is needed rather than waiting for the buffer to fill.

PARAMETERS

-i MODE

stdin buffering.
-o MODE
stdout buffering.
-e MODE
stderr buffering.

MODES

L - Line buffered
0 - Unbuffered
SIZE - Buffer size (e.g., 1K, 1M)

CAVEATS

Doesn't work with all programs. Statically linked programs unaffected. Some use internal buffering.

HISTORY

stdbuf is part of GNU coreutils. It uses LD_PRELOAD to intercept buffering calls.

SEE ALSO

unbuffer(1), script(1), tee(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community