Pipe Viewer «
»


Code: , ,
2 comments

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 $7 }' access.log | sort | uniq -c | sort -rn
# into:
awk '{ print $7 }' 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.


Comments

  1. It’s very similar to tee, except instead of sending a copy of the data to a file, it displays one or more progress meters on the screen so you can see the flow of data through your piped commands

Leave a Reply

Your email address will not be published.