pv is a small but very useful utility

    One friend of mine said about pv, "I’m an admin for seven years, I needed this tool dozens of times, and I didn’t even know that it exists." In thinking about how to get an invite on Harb, I typed in a search for pv. And did not find anything.


    And so pv is short for pipeviewer, that is, as much as a pipe viewer. I won’t talk about the effectiveness of using pipes, it’s no secret to anyone. The only “but” in working with them is that typing a command and pressing Enter is often not enough just a little - to know how long it will take to execute. It is the speed of data processing that pv will show us.

    The lyrics are over, let's move on to the examples.

    Installing pv on Debian is pretty trivial.
    % sudo aptitude install pv

    Next is the introductory one, let's say you are the same as I am the lucky owner of some useful logs and at some point you got your hands on archiving them, for example, so
    % cat rt94-171-06 | gzip > rt94-171-06.gz
    Any idea how long this operation will take?

    The same with pv. It is clearly seen that 128 MB passed through the pipe in 15 seconds - this is 18% of the total volume, the operation will take another minute and 7 seconds. It may seem that pv is such a replacement for cat, but in fact its capabilities are much wider. For example, we pack the entire catalog into a compressed archive. It’s already not bad, but I want more so that the end time is shown. To do this, just use the -s switch to transfer pv the size of the directory in bytes . My whole operation will take 13 and a half hours. Heh, accumulated =)
    %pv rt94-171-06 | gzip > rt94-171-06.gz
    128MB 0:00:15 [ 9.1MB/s] [=====>.....................] 18% ETA 0:01:07




    %tar -czf - . | pv > out.tgz
    21.9MB 0:00:15 [1.47MB/s] [...<=>.....................]


    %tar -czf - . | pv -s $(du -sb | grep -o '[0-9]*') > out.tgz
    44.3MB 0:00:27 [1.73MB/s] [>..........................] 0% ETA 13:36:22



    You can also make commands from several copies of pv. The -c switch is needed so that several copies of pv do not display information on top of each other. The -N switch gives the scale name. Well, in the end, a funny example from one English-language blog about Linux
    %tar -cf - . | pv -cN tar -s $(du -sb | grep -o '[0-9]*') | gzip | pv -cN gzip > out.tgz
    tar: 97.1MB 0:00:08 [12.3MB/s] [>......................] 0% ETA 1:50:26
    gzip: 13.1MB 0:00:08 [1.6MB/s] [....<=>................]




    %pv /dev/urandom > /dev/null
    18MB 0:00:05 [ 3,6MB/s] [...<=>............................]

    Also popular now: