Display the progress information of the command currently executed on the command line, pipeline viewer
pv command Short for Pipe Viewer, developed by Andrew Wood. It means displaying information on the progress of data processing through the pipeline. This information includes elapsed time, percentage complete (displayed via a progress bar), current speed, total data transferred, and estimated time remaining.
# Debian-based operating system, such as Ubuntu
sudo apt-get install pv
# RedHat system is like this:
yum install pv
pv(option)(parameter)
pv [OPTION] [FILE]...
-p, --progress show progress bar
-t, --timer display elapsed time
-e, --eta display estimated time of arrival (completion)
-I, --fineta Display absolute estimated arrival time
(Finish)
-r, --rate Display data transfer rate counter
-a, --average-rate Display data transfer average rate counter
-b, --bytes Display the number of bytes transferred
-T, --buffer-percent displays the percentage of the transmit buffer in use
-A, --last-written NUM displays the number of bytes last written
-F, --format FORMAT Set output format to FORMAT
-n, --numeric output percentage
-q, --quiet do not output any information
-W, --wait do not display anything until the first byte is transferred
-D, --delay-start SEC Do not display anything until SEC seconds have elapsed
-s, --size SIZE Set estimated data size to SIZE bytes
-l, --line-mode count lines instead of bytes
-0, --null lines are terminated with zero
-i, --interval SEC Update every SEC seconds
-w, --width WIDTH Assume the terminal is WIDTH characters wide
-H, --height HEIGHT Assume the terminal height is HEIGHT lines
-N, --name NAME prepend visual information with name
-f, --force output standard error to terminal
-c, --cursor Use cursor to locate escape sequences
-L, --rate-limit RATE Limit transfers to RATE bytes per second
-B, --buffer-size BYTES Use buffer size of BYTES
-C, --no-splice never use splice(), always use read/write
-E, --skip-errors Skip read errors in input
-S, --stop-at-size Stop after transmitting --size bytes
-R, --remote PID update process PID settings
-P, --pidfile FILE Save process ID in FILE
-d, --watchfd PID[:FD] Monitor process PID, open file FD
-h, --help show help
-V, --version display version information
The command that most of us (command line users on Linux) use is copying movie files from a USB drive to your computer. If you use cp to complete the above task, you will not know what is going on until the entire copy process is completed or an error occurs.
# There will be progress in copying files
linux [master●] % pv ~/Downloads/CentOS-7-x86_64-Minimal-1511.iso > ~/Desktop/CentOS-7-x86_64-Minimal-1511.iso
#Enter information below
552MiB 0:00:02 [ 212MiB/s] [==================> ] 91% ETA 0:00:00
# -L allows you to modify the transmission rate of the pv command.
# Use the -L option to limit the transfer rate to 2MB/s.
pv -L 2m /media/himanshu/1AC2-A8E3/fNf.mkv > ./Desktop/fnf.mkv
Display a progress bar while copying files (defaults to -p, -t, -e, -r and -b options if no option is specified)
$ pv getiot.db > getiot.db.bak
Pack the /var/log/syslog
file into a zip compressed package and display the progress
$ pv /var/log/syslog | zip > syslog.zip
Show progress bar when decompressing using tar command
$ pv rootfs.tar.bz2 | tar -jxf - -C rootfs/
12.3MiB 0:00:02 [6.15MiB/s] [==========> ] 21% ETA 0:00:07
Decompression completed
$ pv rootfs.tar.bz2 | tar -jxf - -C rootfs/
57.8MiB 0:00:10 [5.53MiB/s] [====================================== ==========>] 100%
Characters are displayed in the command line one by one at a constant speed.
echo "Tecmint[dot]com is a community of Linux Nerds and Geeks" | pv -qL 10
Compressed files display progress information
pv /media/himanshu/1AC2-A8E3/fnf.mkv | gzip > ./Desktop/fnf.log.gz
Use the dd command to write the iso to disk and pv to display the progress bar.
sudo pv -cN source < /Users/kacperwang/Downloads/CentOS-7-x86_64-Everything-1511.iso | sudo dd of=/dev/disk2 bs=4m
## Show the progress below
source: 5.2GiB 5:11:41 [ 503KiB/s] [======================> ] 71% ETA 2:01:56
On Linux, if the execution of some commands or scripts takes a long time, but you cannot devote more energy to repeatedly watching whether the execution is completed, you can use pv to monitor the PID and notify you through the network when the task is completed. WeChat or DingTalk, so you can free up your energy to do other things, isn’t it great?
$ pv -d $(ps -ef | grep -v grep | grep "<keyword of script or command>" | awk '{print $2}') && <The notification script or command needs to be executed in advance. Debugged>