Linux command
stdbuf 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Line buffered stdout
stdbuf -oL [command]
Unbuffered stdout
stdbuf -o0 [command]
Unbuffered stderr
stdbuf -e0 [command]
Fully buffered stdin
stdbuf -i[1M] [command]
Line buffered all streams
stdbuf -oL -eL [command]
Combine with grep
stdbuf -oL [command] | grep [pattern]
说明
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.
参数
- -i _MODE_
- stdin buffering.
- -o _MODE_
- stdout buffering.
- -e _MODE_
- stderr buffering.
FAQ
What is the stdbuf command used for?
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.
How do I run a basic stdbuf example?
Run `stdbuf -oL [command]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -i _MODE_ do in stdbuf?
stdin buffering.