| 用途 | 修改被启动进程的 stdio 缓冲模式 |
|---|---|
| 语法 | stdbuf -oL -eL 命令 |
| 模式 | -o0 无缓冲、-oL 行缓冲(stdout);数字可指定字节大小 |
常用示例
常用示例
tail -f app.log | stdbuf -oL grep ERROR # grep 实时吐行
stdbuf -o0 tail -f app.log | tee live.log # tee 实时写文件+屏幕
stdbuf -oL long_running_cmd | ts '[%T]' # 配合时间戳工具
stdbuf -oL python tool.py 2>&1 | grep --line-buffered -v noise原理是 LD_PRELOAD 注入:只对动态链接且走 libc stdio 的程序有效(setuid 程序会被系统忽略注入)。