pv
is a really handy tool to monitor the progress of certain operations. I almost use it on a daily basis. Here are some more advanced use cases:
import database dump
pv dump.sql.gz | gunzip | psql -U postgres my_database
grep requests from a set of logs
pv $(find . -name "*.log.gz") | gunzip | grep " action=users#create"
compress (and uncompress) files
pv Fedora-Workstation-Live-x86_64-25-1.3.iso | gzip > Fedora-Workstation-Live-x86_64-25-1.3.iso.gz
When called with a list of arguments pv
treats these as files and first calculates the total size. The progress indication is then measured towards that total size. In this case pv
behaves similar to cat
but with the progress of the cat
operation printed to stderr
.
pv
can also be called with data provided via stdin
. Without knowing the total size only the current rate (either in bytes, or via -l
in lines) is displayed. If known, the expected size (or number of lines) can be provided with the -s
flag.
More options and examples can be found at man pv.