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

14:54:38Pentru copiii de la Tabăra de Vară a Alianței Franceze vara a început cu lecții —» BiblioCity
14:54:13La Tabără, la Bibliotecă vin copii talentați —» BiblioCity
14:53:49În vacanța mare? De unul singur? Oare cum ar fi? —» BiblioCity
14:53:27Orice întâlnire a copiilor cu scriitorii devine un eveniment memorabil —» BiblioCity
14:52:43Cartea cea de toate zilele. Adevărată lecție de educație patriotică și spirituală —» BiblioCity
14:52:19Copii și Cuvinte. O Vacanță Mare cu o Scriitoare Mare este o Poezie scrisă împreună —» BiblioCity
14:51:57CARTEA cu ochi de copii – cartea cu poezii. Drago Mir – DRAG LUMII NOASTRE, LUMII COPILAȘILOR —» BiblioCity
14:49:23GHICITORI PE PORTATIV. Scriitoarea Marcela Mardare și-a amintit de elevii săi de cândva —» BiblioCity
17:35:45IHTIANDRU —» Andrei LANGA. Blogul personal
11:16:32105 ani de la nașterea artistului plastic Gleb Sainciuc —» Biblioteca de Arte 'Tudor Arghezi'
14:45:27EDITORIAL | Cazul „expertului” pedofil și noua mare provocare a lumii „moderne” —» Nicolae Federiuc
11:04:24DACĂ CITIȚI ÎN BULGARĂ, UN INTERVIU DIN REVISTA „FLACĂRA”, EDITATĂ DE UNIUNEA SCRIITORILOR DIN BULGARIA Leo Butnaru - Ognian Stamboliev —» Leo Butnaru
03:42:46PLOAIE —» Andrei LANGA. Blogul personal
07:02:18EXTRAS DIN INTERVIU —» Leo Butnaru
03:01:20JURNALUL CA MEMORIE, 1992 —» Leo Butnaru
10:18:42Primul concediu în patru cu Ilinca și Matei (probabil ultimul în Creta) —» Andrei Albu - omul alb cu gînduri negre
16:32:16Marea strategie scurtcircuitată —» APort | "Pentru un român care știe citi, cel mai greu lucru e să nu scrie." I.L. Carag
09:32:49CARTEA cu ochi de copii – cartea cu poezii. Drago Mir – DRAG LUMII NOASTRE, LUMII COPILAȘILOR —» BiblioCity
04:10:45PĂMÂNTUL FĂGĂDUINȚEI / POEME —» Leo Butnaru
19:04:43PLOAIE —» Andrei LANGA. Blogul personal
08:11:39Mărturii din GULAG filmate la Burlacu, Cahul —» Curaj.TV | Media alternativă
06:46:22Cercetașii ingenioși vara la Bibliotecă —» BiblioCity
06:25:46Amintiri despre foame și canibalism —» Curaj.TV | Media alternativă
03:30:24JURNALUL CA MEMORIE —» Leo Butnaru
15:07:39Trei reguli de știut când servim spumant! —» Fine Wine