Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any incremental (interactive) shell utils? I.e. "online" sort, wc etc

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
like image 276
johv Avatar asked Oct 16 '25 13:10

johv


1 Answers

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 in sort 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.

like image 51
Caleb Avatar answered Oct 19 '25 05:10

Caleb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!