将 pv 输出 (stderr) 打印到文件

Print pv output (stderr) to file

如何将 output of 打印到文件中?例如:

timeout 5s dd if=/dev/random | pv -r > /dev/null
[ 505kiB/s]

在我的五秒超时过程中,速率线输出为 "updated"。我试过了,但它不起作用(日志为空):

timeout 5s dd if=/dev/random | pv -r > /dev/null 2> rates.log

我相信它与 carriage returns output, but after an hour I am stuck. Ideally my log file would have multiple lines each time 打印出一个新值有关:

[ 505kiB/s]
[ 498kiB/s]
[ 542kiB/s]
[ 513kiB/s]
[ 509kiB/s]

更新:

要按照我上面的描述将内容放入文件中,我必须使用 though I'm not sure why it is required ( alone didn't work, the file will be empty without ):

timeout 5s dd if=/dev/random | pv -fr > /dev/null 2> >(stdbuf -oL tr '\r' '\n' > rates.log)

来自man pv

-f, --force
Force output. Normally, pv will not output any visual display if standard error is not a terminal. This option forces it to do so.

由于 rates.log 不是终端,您需要执行 pv -fr 而不是 pv -r