是否有任何增量(交互式)shell 实用程序?即“在线”。排序、厕所等
是否有标准 shell 实用程序的版本(直接替换)可以显示即时更新的(部分)结果(可能更新到 stderr)?
假设我想这样做:
du ~/* -s | sort -rn | head
在 du
完成之前,首先绝对没有任何反应。然而,我希望看到部分结果,即我希望 sort
显示它已经看到的数据。这样我可以快速查看输出是否有问题并进行纠正。就像运行 grep 时一样。
同样的事情:
du ~/* -s | wc
我希望它能够即时更新。
这是一个丑陋的解决方法,显示了我想要的东西。 (但最好它不应该不必要地占用整个屏幕,就像下面的 du
一样。)
du ~/* -s > /tmp/duout | watch -n .1 sort -rn /tmp/duout
du ~/* -s > /tmp/duout | watch -n .1 wc /tmp/duout
但是,如果我可以这样做,我会更喜欢它:
du ~/* -s | isort -rn
Are there there versions (drop-in replacements) of the standard shell utils that displays (partial) results updated on-the-fly (perhaps to stderr)?
Say I want to do this:
du ~/* -s | sort -rn | head
At first absolutely nothing happens, before du
is done. I would however like to see partial results, i.e. I want sort
to show the data it has already seen. This way I can quickly see if something is wrong with the output and correct it. Like when running grep.
Same thing with this:
du ~/* -s | wc
I would like it to update on the fly.
Here is an ugly work-around showing kinda what I want. (But preferably it shouldn't unnecessarily consume the whole screen, like with du
below.)
du ~/* -s > /tmp/duout | watch -n .1 sort -rn /tmp/duout
du ~/* -s > /tmp/duout | watch -n .1 wc /tmp/duout
However, I'd much prefer it if I could just do like:
du ~/* -s | isort -rn
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有许多 shell 实用程序可以显示活动结果。
top
程序就是一个很好的例子。问题是,这些工具不适合通常的 Linux 输入和输出方法。
Sort
旨在获取输入流,对其进行排序并输出。然后您可以获取该输出并用它做其他事情。如果它输出增量版本,则对于进一步处理来说是无用的。如果您有特定需要查看部分数据,则必须自己将它们组合在一起。它与正常的工作流程截然相反,并且大量浪费计算资源。如此过多的内容由读者自行决定:)
如果您有其他特定的实用程序并且想知道是否有替代的显示系统,请随时询问。至于你提到的那些,特别是
sort
,它们不存在。在sort
中实时显示输出会使结果速度降低几个数量级,没有人愿意以等待最终结果十倍、一百倍或一千倍的时间为代价来观看输出。There are lots of shell utilities that display active results. A good example would be the
top
program.The trouble is, these kind of tools do NOT lend themselves to the usual linux methodology of input and output.
Sort
is meant to take an input stream, sort it, and output it. You can then take that output and do something else with it. If it output incremental versions, it would be useless for further processing.If you have specific needs to see partial data, you will have to hack them together yourself. It's diametrically opposed to the normal work flow and a massive waste of computing resources. Such excessive are left up to the reader :)
If you have another specific utility and wonder if there would be an alternative display system, feel free to ask. As for the ones you mention, particularly
sort
, they don't exist. A live display of output insort
would slow results down by several orders of magnitude and nobody wants to watch output at the cost of waiting ten or a hundred or a thousand times longer for the final result.您可以将
tee /dev/tty
插入管道序列中以打印中间结果。tee
复制标准输入,将输出发送到标准输出和命令行上指定的任何文件。您可以使用此技巧查看 du 的输出,同时将其传递给 sort:中间输出将与 sort 的输出发生冲突。您可以使用各种 shell 技巧来解决这个问题;例如,通过将排序的输出发送到寻呼机:
You can insert
tee /dev/tty
into a pipe sequence to print intermediate results.tee
duplicates stdin, sending output both to stdout and to any files specified on the command-line. You could use this trick to view du's output while simultaneously passing it to sort:The intermediate output will collide with sort's output. You could work around this with various shell tricks; for example, by sending sort's output to a pager:
问题不在于 utils,而在于 shell 本身。您需要一个不同的外壳来同时启动管道链中的每个进程。这些实用程序所有流输入都很好。运行递归 grep 向自己证明这一点。
The problem is not the utils, but the shell itself. You need a different shell that will start each process in a pipe chain at the same time. The utilities all stream input just fine. Run a recursive grep to prove that to yourself.
在正常的数据排序情况下,您必须读取所有数据才能开始打印数据第 1 行的值,对吧?正如您提到的,与 du -s 相同(意思是摘要,它也在对数据进行排序和整理)。取出
-s
,您将立即获得未汇总的输出。所以你总是不得不等待这类事情。您可以对第一个示例执行的一件事是将
tee
添加到数据流中,甚至
在 tty8 和 tty12 是单独的终端窗口的情况下添加,并且您已通过使用
找到了要替换的正确 ttyN shell 窗口中的 >tty
。我希望这有帮助。
PS,由于您似乎是新用户,如果您得到的答案对您有帮助,请记住将其标记为已接受,和/或给它 +(或 -)作为有用的答案。
In a normal case of sorting data, you have to read all the data before you can start to print the value for line 1 of data, right? And as you mention, same with du -s (which means summary, it is sorting and collating data too). Take out the
-s
and you get unsummarized output right away.So you're always going to have to wait for those sorts of things. The one thing you can do with your first example is to add a
tee
into the data streamor even
where tty8 and tty12 are separate terminal windows, and you have found the correct ttyN to substitute by using
tty
in the shell window.I hope this helps.
P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.