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

20:42:41Unde suntem, încotro mergem —» APort | "Pentru un român care știe citi, cel mai greu lucru e să nu scrie." I.L. Carag
17:14:03Peste 1 miliard de euro în noi parteneriate investiționale și finanțări anunțate pentru Republica Moldova 💥 —» Sandu GRECU
11:26:32Potîrniche, acid cu colegii: birocrație. Stop pe Stadion. Rușinea CNOS. Sfaturi de la Dobrik —» Sandu GRECU
10:31:49Terapie în grup sau să nu ne mai mințim… —» Biblioteca de Arte 'Tudor Arghezi'
07:04:13Epicrama a fost inaugurată oficial —» Fine Wine
07:02:26Drumul Republicii Moldova în UE —» Biblioteca Publică or.Rîşcani
05:24:25DIN ESEURI —» Leo Butnaru
16:09:58Produsele moldovenești pot ajunge în fața cumpărătorilor internaționali la SIAL Paris 2026 ❣️ —» Sandu GRECU
16:01:52Tinerii din Moldova transformă apicultura într-o oportunitate de dezvoltare și investiție în viitor 🐝 —» Sandu GRECU
14:00:30Deputatul Lilian Carp cere transparență la Strășeni: Stadionul construit din bani publici trebuie să aparțină cetățenilor, nu grupurilor de interese 🔥 —» Sandu GRECU
07:56:28CELEBRITĂȚI PRIN VREMURI... —» Leo Butnaru
14:53:05Republica Moldova, destinație strategică pentru afaceri - Agenția de Investiții lansează Ghidul Investitorului 2026 📜 —» Sandu GRECU
12:12:31POEZII PENTRU COPII —» Leo Butnaru
09:12:46DE ZIUA COPIILOR —» Leo Butnaru
15:11:33Teatrul Verde și-a redeschis pe 29 mai stagiunea de vară printr-un spectacol grandios la Chișinău —» Curaj.TV | Media alternativă
05:55:34INTERSECȚII —» Leo Butnaru
23:39:40Skream & Benga reunited —» turn up the silence
09:06:42Rusia atacă România cu milioane de droni! —» APort | "Pentru un român care știe citi, cel mai greu lucru e să nu scrie." I.L. Carag
05:15:22LAPTE CU LITERE —» Leo Butnaru
16:50:14La întâlnire cu opera lui Constantin Brâncuși —» Biblioteca de Arte 'Tudor Arghezi'
15:03:28„Fii AgriCOOLtor!”: Cum transformă tinerii tradiția vinului moldovenesc într-o carieră de succes 🍷🍷 —» Sandu GRECU
14:38:17Companiile moldovenești pot accesa noi parteneriate de business în BENELUX. Înregistrările pentru Forumul de afaceri BENELUX-Republica Moldova sunt deschise până pe 4 iunie 💲 —» Sandu GRECU
07:14:03JURNALUL LUI ORFEU —» Leo Butnaru
16:31:29Marşul tăcerii pentru victimele pe bicicletă —» Curaj.TV | Media alternativă
13:18:48Șota Maharadze, gruzinul care i-a făcut campioni pe hînceșteni. Legătura cu Kvaratskhelia. Tată unic 🔥🔥🔥 —» Sandu GRECU