Site icon New Generation Enterprise Linux

Harnessing `stdbuf` for Unbuffered Command Output

Quick Tip

Harnessing `stdbuf` for Unbuffered Command Output

Challenge: When running commands or scripts in Linux, especially those that produce output incrementally or are part of a pipeline, you might notice a delay in seeing the output. This is often due to buffering, where the system waits to accumulate a certain amount of data before displaying it. This can be frustrating for real-time monitoring or when debugging.

The Solution: Utilize the stdbuf command to control or disable buffering for command output.

stdbuf -oL your_command_here

Why it works: The -o L options tell stdbuf to set the output buffering mode to “line” for the specified command. This ensures that output is flushed line by line, making it appear in real-time rather than waiting for a full buffer. You can also use -o 0 to disable output buffering entirely (no buffering).

Pro-Tip: Use stdbuf -oL your_script.sh > output.log to ensure your script’s output is written to the log file as it’s generated.

Linux Tips & Tricks | © ngelinux.com | 5/28/2026

0 0 votes
Article Rating
Exit mobile version