LinuxCommandLibrary

unbuffer

TLDR

Run command with unbuffered output

$ unbuffer [command]
copy
Unbuffer in a pipeline
$ [command1] | unbuffer -p [command2] | [command3]
copy
Unbuffer grep in a pipeline
$ tail -f [logfile] | unbuffer -p grep [pattern]
copy
Unbuffer output of a script
$ unbuffer ./[script.sh] | tee [output.log]
copy

SYNOPSIS

unbuffer [-p] program [args]

DESCRIPTION

unbuffer disables output buffering that occurs when program output is redirected. Many programs buffer their output when not connected to a terminal, which can cause delays or issues in pipelines.
The tool works by connecting the program to a pseudo-terminal (pty), making it behave as if running interactively. This forces line-buffered or unbuffered output even when redirected to files or pipes.
Common use cases include watching log files through grep, capturing colored output, and ensuring real-time output in scripts.
unbuffer is part of the Expect package and uses Expect's pty handling capabilities.

PARAMETERS

-p

Pipeline mode: read from stdin and pass to program.
program
The command to run with unbuffered output.
args
Arguments to pass to the program.

CAVEATS

Does not read from stdin by default; use -p for pipeline mode. In pipeline mode with -p, unbuffer exits immediately when it encounters EOF. May affect programs that detect terminal capabilities. Part of the expect package, not installed by default on all systems.

HISTORY

unbuffer was created as part of the Expect package by Don Libes at NIST. Expect is documented in "Exploring Expect: A Tcl-Based Toolkit for Automating Interactive Programs" (O'Reilly, 1995). The tool addresses a common Unix problem of output buffering in pipelines.

SEE ALSO

expect(1), stdbuf(1), script(1), tee(1)

Copied to clipboard