📜 ⬆️ ⬇️

pv is a small but very useful utility.

One friend of mine said about pv as follows: “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 to Harba, I typed in the search for pv. And found nothing.


And so pv is abbreviated from pipeviewer, that is, not a few more than a pipe viewer. I will not tell you about the effectiveness of the use of the payp, it is not a secret to anyone. The only "but" in working with them is that typing a command and pressing Enter often lacks a little - knowing how long it will take to complete. It is the speed of data processing and will show us pv.

With the lyrics over, proceed to the examples.
')
Installing pv in Debian is pretty trivial.
% sudo aptitude install pv

Further introductory, let's say you are the same as I am happy owner of some useful logs and at some point you got the hands to archive them, for example,
% cat rt94-171-06 | gzip > rt94-171-06.gz
Any thoughts on how long this operation will take?

The same with pv
%pv rt94-171-06 | gzip > rt94-171-06.gz
128MB 0:00:15 [ 9.1MB/s] [=====>.....................] 18% ETA 0:01:07

It is clearly seen that 128MB 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.
%tar -czf - . | pv > out.tgz
21.9MB 0:00:15 [1.47MB/s] [...<=>.....................]

Already not bad, but I want more to show the end time of work. To do this, all you need to do is use the -s switch to transfer the pv directory size in bytes
%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

My whole operation will take 13 and a half hours. Heh, accumulated =)

You can also make commands from multiple copies of pv.
%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] [....<=>................]

The -c switch is needed so that multiple pv copies do not output information on top of each other. The -N key gives the name of the scale.

Well, at the end of a funny example from a single English-language blog about Linux
%pv /dev/urandom > /dev/null
18MB 0:00:05 [ 3,6MB/s] [...<=>............................]

Source: https://habr.com/ru/post/65384/


All Articles