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

18:11:55FIECARE COPIL MERITĂ ȘANSA DE A-ȘI URMA VISUL! 💙💛 —» Sandu GRECU
05:11:19DIN REVISTA TINERILOR —» Leo Butnaru
12:37:25Under 15. Jucători din țară și de peste hotare, convocați de FMF la un nou trial ⚽️ —» Sandu GRECU
12:18:35„Ca primar, nu sunt aici pentru declarații, ci pentru fapte” – Viorel Jardan, primarul comunei Lozova 💫 —» Sandu GRECU
09:46:20Biblioteca – punct de întâlnire între diasporă și acasă —» BPR Ungheni's Blog
18:40:53„ALB DUPĂ ALB” – expoziție de Doina Mihăilescu, la Muzeul Național de Artă al Moldovei din Chișinău 🏦 —» Sandu GRECU
18:25:21Derzamăgit de organele de drept, vrea să plece afară —» Curaj.TV | Media alternativă
12:19:46DIN REVISTA TINERILOR —» Leo Butnaru
15:24:47🎾 ROMINA HÎNCU, AL TREILEA TROFEU DIN 2026! 🇲🇩🏆 —» Sandu GRECU
15:24:47🎾 ROMINA HÎNCU, AL TREILEA TROFEU DIN 2026! 🇲🇩🏆 —» Sandu GRECU
04:54:53CARTE NOUĂ PENTRU COPII —» Leo Butnaru
13:45:15Arta nu tace: Perjovschi cu David —» Curaj.TV | Media alternativă
16:59:59NU CÂT ȘTIE, CI CÂT ÎȘI PERMITE... —» Leo Butnaru
11:49:49Petru Racu: jucători pe pile la Națională și cei care veneau să se odihnească. Pariuri: prețul unui galben 💥💥💥 —» Sandu GRECU
11:46:26Vin cu aur la Mondial de Bruxelles – 55 mdl —» Fine Wine
11:45:31Cardinalul fotbalului, Nicolai Cebotari. Portar de top, cearta cu Ciobanu, arbitraje, dinastia 🔥🔥🔥 —» Sandu GRECU
11:41:00De la pasiunea pentru sere moderne la „Agricultura Inteligentă”: Povestea lui Piotr Caraman, masterandul care dă tonul inovației la UTM 💥 —» Sandu GRECU
11:40:41AGG Group investește în producția locală: un exemplu de reinvestire strategică în economia Republicii Moldova 💫 —» Sandu GRECU
11:31:45Agricultura modernă te așteaptă! În aceste zile se desfășoară admiterea la instituțiile de învățământ agricol ✍️ —» Sandu GRECU
10:25:22Sălcuța intră pe piața spumantelor —» Fine Wine
04:04:12DINTRE PRUT ȘI NISTRU —» Leo Butnaru
04:48:09RACURSIU —» Leo Butnaru
04:11:37ÎNTRE PROZĂ ȘI YES-EU —» Leo Butnaru
07:14:33Biodiversitatea din Purcari: studiu de caz în China —» Fine Wine
04:59:54INTERSECȚII —» Leo Butnaru