Site icon New Generation Enterprise Linux

Harness `stdbuf` for Unbuffered Command Output

Quick Tip

Harness `stdbuf` for Unbuffered Command Output

Challenge: When running certain commands or scripts, especially those that produce output in chunks or interact with pipes, you might experience unexpected delays or buffering issues. This can make real-time monitoring or interactive script execution frustrating.

The Solution: Use the stdbuf command to control the buffering of command output.

stdbuf -o L your_command_here

Why it works: The -o L option tells stdbuf to set the output buffering mode to “line buffering”. This ensures that output is flushed line by line, preventing delays and making the output appear more immediately, which is crucial for interactive sessions and piped commands.

Pro-Tip: You can also use -e L for unbuffered stderr and -i L for unbuffered stdin, though line buffering for output is the most common use case.

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

0 0 votes
Article Rating
Exit mobile version