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

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
08:10:00Lilian Carp: Raportul Primăriei Chișinău confirmă distribuirea apartamentelor de la Apă-Canal către oameni de partid și conducerea întreprinderii 😡 —» Sandu GRECU
07:40:49DIN REVISTA TINERILOR —» Leo Butnaru
15:01:45Vino și joacă fotbal alături de copilul tău ⚽️🏆💥 —» Sandu GRECU
11:19:57Tradițiile au cucerit centrul Chișinăului. Corespondentele Curaj TV Ploiești , CristinaVîrtosu și Laurenția Costin au fost prezente cu camera de filmat la „Festivalul Tradițiilor” —» Curaj.TV | Media alternativă
11:19:57Tradițiile au cucerit centrul Chișinăului —» Curaj.TV | Media alternativă
00:54:00Prevenirea tentativelor de fraudă telefonică și importanța protejării datelor cu caracter personal ☎️ —» Sandu GRECU
18:30:06Studiul 5.0 privind impactul Investițiilor Străine Directe: Reziliență, consolidare și parcurs accelerat de integrare europeană a economiei Republicii Moldova 🚀 —» Sandu GRECU
08:34:01Festivalul Internațional Shakespeare de la Craiova —» Biblioteca de Arte 'Tudor Arghezi'
20:45:01Compania de consultanță și comunicare strategică, Parsec angajează - Specialist de comunicare și PR 💥 —» Sandu GRECU
20:14:32Agricultura 5.0 explorată de tineri la Târgul regional „Viitorul e AgriCOOL” de la Căușeni ☀️ —» Sandu GRECU
08:23:59Chateau Cristi lansează două vinuri noi —» Fine Wine
04:40:04DIN JURNAL 2023 —» Leo Butnaru
07:01:55DIN POEZIA LUMII —» Leo Butnaru
17:24:24🎊 15 ani de activitate ai S.A. „Loteria Națională a Moldovei" —» Sandu GRECU
12:58:44Am desemnat câștigătorul premiului de 6600 de lei oferit de Clubul Premier Football 💥🏆🔝 —» Sandu GRECU
09:07:43TÜV Austria își extinde prezența în Republica Moldova: Standarde internaționale pentru creșterea competitivității economice 💫 —» Sandu GRECU
13:45:50Efros la Londra, acasă la Borsetca. Agenție de impresariat împreună cu Plahotniuc. Banii din transferuri 🔥🔥🔥 —» Sandu GRECU
12:13:34Moldova, prezentă la CMB în Erevan —» Fine Wine
05:30:37INTERVIU CU UN CORESPONDENT... NEVĂZUT —» Leo Butnaru
15:12:02🔔 Chișinăul va găzdui evenimentul la nivel înalt EU-Moldova Investment Conference pe 4 iunie 2026 —» Sandu GRECU
07:27:39INVIDIA, URA —» Leo Butnaru
06:59:25Agricultura 5.0 în nordul țării: Tinerii au testat tehnologiile viitorului la Târgul „Viitorul e AgriCOOL” din Corlăteni 🦾 —» Sandu GRECU