pv执行命令的管道查看器

  • 什么是pv

pv (Pipe Viewer )的简称,由Andrew Wood 开发。是通过管道显示数据处理进度的信息。这些信息包括已经耗费的时间,完成的百分比(通过进度条显示),当前的速度,全部传输的数据,以及估计剩余的时间。PV显示当前在命令行执行的命令的进度信息,管道查看器.

  • 下载安装
#Ubuntu安装
sudo apt-get install pv

# CentOS安装
yum install pv
  • 选项参数
-p, --progress           show progress bar
-t, --timer              show elapsed time
-e, --eta                show estimated time of arrival (completion)
-I, --fineta             show absolute estimated time of arrival
                         (completion)
-r, --rate               show data transfer rate counter
-a, --average-rate       show data transfer average rate counter
-b, --bytes              show number of bytes transferred
-T, --buffer-percent     show percentage of transfer buffer in use
-A, --last-written NUM   show NUM bytes last written
-F, --format FORMAT      set output format to FORMAT
-n, --numeric            输出百分比
-q, --quiet              do not output any transfer information at all

-W, --wait               display nothing until first byte transferred
-D, --delay-start SEC    display nothing until SEC seconds have passed
-s, --size SIZE          set estimated data size to SIZE bytes
-l, --line-mode          count lines instead of bytes
-0, --null               lines are null-terminated
-i, --interval SEC       update every SEC seconds
-w, --width WIDTH        assume terminal is WIDTH characters wide
-H, --height HEIGHT      assume terminal is HEIGHT rows high
-N, --name NAME          prefix visual information with NAME
-f, --force              output even if standard error is not a terminal
-c, --cursor             use cursor positioning escape sequences

-L, --rate-limit RATE    limit transfer to RATE bytes per second
-B, --buffer-size BYTES  use a 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 --size bytes have been transferred
-R, --remote PID         update settings of process PID

-P, --pidfile FILE       save process ID in FILE

-d, --watchfd PID[:FD]   watch file FD opened by process PID

-h, --help               显示帮助
-V, --version            显示版本信息

示例

  • 复制文件显示进度
[root@vm10-0-1-212 ~]# pv wj.zip > weijing1.zip 
17.8MiB 0:00:00 [ 381MiB/s] [===============================>] 100%
  • 使用 -L 选项来限制传输速率为1MB/s。
[root@vm10-0-1-212 ~]# pv -L 1m  wj.zip > weijing2.zip 

17.8MiB 0:00:17 [   1MiB/s] [===============================>] 100%
  • 使字符一个个匀速在命令行中显示出来
[root@vm10-0-1-212 ~]# echo "This url is weijing.co" | pv -qL 10
  • 压缩文件展示进度信息
[root@vm10-0-1-212 ~]# pv wj.zip | gzip > weijingbiji.gz

17.8MiB 0:00:00 [25.8MiB/s] [===============================>] 100%
  • 用 dd 命令将 iso 写入磁盘,pv来实现进度条的显示
[root@vm10-0-1-212 ~]# pv -cN source < /CentOS-7-x86_64-Everything-1511.iso | sudo dd of=/dev/disk2 bs=4m

source:  5.2GiB 5:11:41 [ 503KiB/s] [=====================>       ] 71% ETA 2:01:56

发表评论