如何以给定的线/秒速率制作cat/tac流?

com*_*mte 4 linux shell

想象你有一个名为"filename"的大日志文件

如果您使用tail -f filename,那么只有在filename更新时才会有一个流

如果您使用cat filename,那么您有一个流,但如果您的CPU比intel 8088新,则无法读取它

如果你cat filename | 更多的是你有一个页面,一页一页,可能会打破你的空格键

如何以给定的速率列出文件(例如:每0.05秒一行)所以我有时间阅读,但我不需要按空格键数百次?

(我不使用| grep,因为在我的特殊情况下,我不知道究竟要搜索什么)

Joh*_*nck 8

yes | pv --quiet --rate-limit 10
Run Code Online (Sandbox Code Playgroud)

yes在这里用来获得快速的文字来源; pv由于许多原因,它是一个非常有用的工具,但它的一个功能是速率限制器.您需要告诉它安静,因此它不会打印其进度指示器.限制以每秒字节数为单位.

另见:https://superuser.com/questions/526242/cat-file-to-terminal-at-particular-speed-of-lines-per-second


jm6*_*666 6

使用

perl -MTime::HiRes=usleep -pe '$|=1;usleep(300000)'
#or
perl -pe 'select(undef,undef,undef,0.3)'
Run Code Online (Sandbox Code Playgroud)

你可以将上面的shell函数添加到你的~/.profile例子中

slowcat

slowcat() {
    perl -MTime::HiRes=usleep -pe '$|=1;usleep(300000)' "$@"
}
Run Code Online (Sandbox Code Playgroud)

将接受文件名和管道输入,

slowcat filenames....
command | slowcat
Run Code Online (Sandbox Code Playgroud)

以下将产生输出作为典型的电影 - 电脑屏幕或通过300Baud调制解调器的连接......

perl -MTime::HiRes=usleep -ne '$|=1;while($c=getc(*stdin)){usleep(33000);print $c}'
Run Code Online (Sandbox Code Playgroud)

  • +1'慢慢地' - 我爱它!你能做一个`totallyexhausetedcat`吗?:-) (2认同)