pv: My New Favorite Command

Published: June 30, 2015


I don't know about you, but I'm not a fan of typing a command into the terminal and then nothing happening. Generally, any command that I know might take a while I'll run in verbose mode. That's great, I know that the process really is running. But what I don't know how far along it is...and how much more there is to go.

Today I found out about the pv command. Boy, is that a game changer...

What Does pv do?

I stumbled upon pv (short for Pipe Viewer) as I was wondering if there was anyway to know the status of MySQL import. Basically, you start out by running your input file through pv and then piping that out to whatever command you were originally intending to run.

pv my_backup.sql | mysql my_database

pv then keeps track of and reports on the status of wherever it's output is going.

Example of running pv command in terminal

By default pv shows the the amount of data transfered, the amount of time running, the transfer rate, a progress bar, the percentage complete, and an eta. I find the defaults to work perfectly, but if you'd like to tinker with things details on all the switches can be found here.

How Do I Get It

Head to the projects home page here for installation instructions. I was running pv on a CentOS system and used the yum package manager for installation.

A Word On Tmux

While we're on the subject, it should be said that tmux is also a great tool for these types of long running jobs. If you don't know about it there's a great primer here.

Other Uses

While a MySQL import seems like one of the most common use cases for pv, I anticipate I'll get additional mileage out of pv down the road. For example, I can see myself using it one day when running a long grep, awk, sort and uniq command on a massive Apache log file.

How are you using pv? I'd love to hear some more use cases in the comments.

Max Chadwick Hi, I'm Max!

I'm a software developer who mainly works in PHP, but loves dabbling in other languages like Go and Ruby. Technical topics that interest me are monitoring, security and performance. I'm also a stickler for good documentation and clear technical writing.

During the day I lead a team of developers and solve challenging technical problems at Something Digital where I mainly work with the Magento platform. I've also spoken at a number of events.

In my spare time I blog about tech, work on open source and participate in bug bounty programs.

If you'd like to get in contact, you can find me on Twitter and LinkedIn.