pv: Progress Bar for md5sum et al.


Tools that know they will take a long time often come with a built-in progress indicator, but there are other utilities on Linux that often leave the user frustratedly tapping their fingers, wondering how much longer they will have to wait.

Luckily, there is a nifty little tool called pv that will donate a progress bar to any program that can read from standard input or a pipe. pv probably stands for pipe viewer.

1. Simple example: figure out how long an md5sum will take:

pv eternal.avi |md5sum

will display something like

96.5MB 0:00:05 [25.3MB/s] [=======>                                    ]  9% ETA 0:00:48

Notes:

  • pv reads from file and prints to stdout.
  • md5sum reads from stdin.
  • pv outputs the progress bar to stderr so as not to interfere with the piped data. See the man page for ways to customize pv’s output.
  • since the bottleneck of such an operation is the media you’re reading from, not the CPU, there will be no noticeable overhead.

2. Complex example: add a progress bar to tar/bzip2 compression/decompression:

tar cf - mydir | pv -n -s $(du -sb mydir | awk ‘{print $1}’) | bzip2 >mydir.tar.bz2

Notes:

  • this example is adapted from the pv man page.
  • the -n switch makes pv output only percentage values.
  • no file is passed to pv, so it reads from stdin (piped to the output of tar).
  • on a system with good cache and enough memory, doing the extra du -s mydir shouldn’t hurt much, since tar will go through the entire directory anyway.

Now let’s decompress it:

pv mydir.tar.bz2 |tar xjf -

By now you realize how awesome this is.

3. Fun example: measure /dev/null throughput:

pv /dev/zero >/dev/null

is close to 3.3GB/s on my 3-year-old system.

Notes:

  • this is not a benchmark ™.
  • pv can’t know the size of its input in this case (infinity), so it obviously can’t display an ETA.

pv is a brilliant example of the UNIX philosophy: simple puzzle pieces combining to create useful results. A couple of last-word remarks:

  • There is apparently a very similar tool called cpipe.
  • There are, unfortunately, programs for which you will not be able to use pv. One example is dpkg, which apparently tries seeking in its input, thus failing to work with pipes.
  • Thanks to my boss for pointing me to this awesome tool.
Posted in Linux, Shell, Technology   Tagged: bzip, bzip2, compression, decompression, md5, md5 sum, md5sum, pipe, progress, progress bar, pv, tar, throughput, tool, trick, unzip, zip   

Sursa
2009-02-05 00:00:00



Comenteaza





Ultimele 25 posturi adăugate

19:18:28Vasile Tarlev: Nu eu am distrus Stadionul Republican. Atacant la echipa Bucuria. Despre Voronin și circ —» Sandu GRECU
19:13:06Tehnologie, energie verde și investiții în tineri: Istoria de succesului a Agro-Firmei „Plaiul Bîrlădean” 🌞 —» Sandu GRECU
19:07:23„Rolul meu ca primar nu este să fac promisiuni, ci să livrez rezultate” – Leonid Boaghi, primarul satului Sireți 💫 —» Sandu GRECU
17:04:57Fosta ambasadoare în India se judecă cu Ministerul de Externe —» Curaj.TV | Media alternativă
15:25:42Despre scandalul de la Dumbrava, BH (Live) —» Curaj.TV | Media alternativă
09:29:40DIN REVISTA DE TRADUCERI LITERARE —» Leo Butnaru
20:44:08De la pasiunea pentru arta culinară, la o carieră de succes în managementul ospitalității: Povestea Ninei Stratu 💫 —» Sandu GRECU
07:13:21Copyright: Deciziile vicedirectorului AGEPI, au costat autorii peste 7 milioane de lei 🤬🤬🤬 —» Sandu GRECU
04:40:33LACONICE —» Leo Butnaru
18:31:28Muzica unește generații. Gheorghe Mustea, sărbătorit la 75 de ani printr-un concert aniversar la Chișinău —» Curaj.TV | Media alternativă
18:31:28Muzica unește generații. Gheorghe Mustea, sărbătorit la 75 de ani printr-un concert aniversar la Chișinău —» Curaj.TV | Media alternativă
13:22:13Cu hijab-ul la defilare —» APort | "Pentru un român care știe citi, cel mai greu lucru e să nu scrie." I.L. Carag
18:56:52Păcălit de avocați și de magistrați (ru) —» Curaj.TV | Media alternativă
04:42:42METAMORFOZE ȘI (NE)LINIȘTI —» Leo Butnaru
19:07:21Primarul de Burlacu e din nou agresiv —» Curaj.TV | Media alternativă
17:01:45„Fii AgriCOOLtor!”: De la pasiunea pentru gătit la o carieră de viitor în gastronomie 💫 —» Sandu GRECU
05:36:29BACOVIA LICEAN... —» Leo Butnaru
14:27:38Moldoveanul care l-a bătut pe Figo. Secu-unicul: 29 de meciuri căpitan al URSS la fotbal. L-a vrut Bayern Munchen 💥🔥🚀 —» Sandu GRECU
12:47:29SCRIITORI - VICTIME ALE GULAGULUI —» Leo Butnaru
04:44:42DESPRE ȘAH ȘI NU NUMAI —» Leo Butnaru
18:49:09Handbalul a unit Moldova, România și Ucraina la Sîngerei: gazdele au câștigat Memorialul „Simion Prașcă” 🤾‍♂️ —» Sandu GRECU
08:54:32O întâlnire cu Teodor Buzu —» Biblioteca de Arte 'Tudor Arghezi'
20:01:51Un simplu Mulțumim, GEOTERMAL 🙏 —» Sandu GRECU
14:35:22„Cornova ungheneană” – la Biblioteca „Dimitrie Cantemir” —» BPR Ungheni's Blog
05:37:05RELAȚIA TA CU ALTER EGO —» Leo Butnaru