Pipe Viewer

Today I found a really nice program for long-running console commands: pv, aka “Pipe Viewer”. If you’ve ever strung together a long command with pipes, run it, questioned why it’s taking so long, maybe open another terminal to run toppv is the answer to that question.

The examples that come with it are a little weird, but the best way I’ve found to use it is in-between the pipes of an existing command.

# transform this command to dump and compress a database:
mysql -u [username] --password=[password] [database] | bzip2 > /tmp/db_dump
# into:
mysql -u [username] --password=[password] [database] | pv -cN dump | bzip2 | pv -cN bzip2 > /tmp/db_dump
# or this command to count popular pages in a big apache log:
awk '{ print  }' access.log | sort | uniq -c | sort -rn
# into:
awk '{ print  }' access.log | pv -cN awk | sort | pv -cN sort | uniq -c | pv -cN uniq | sort -rn

Yeah, the repetition calls out for a really pithy alias for pv -cN. But you get the idea — you can easily see how long the different steps of your long job are taking.

Want more? I'm not as good at forgetting to update @pushcx on Twitter.