噸您可以使用 pv 命令查看通過管道的數據進度。提供以下信息:
- 時光飛逝
- 完成百分比(帶進度條)
- 當前吞吐量
- 傳輸的數據總量
- 什麼時候
從項目主頁:
它可以插入到兩個進程之間的常規管道中,以直觀地指示數據通過的速度、需要多長時間、完成需要多長時間以及完成需要多長時間。
如何安裝 pv 命令
默認情況下不安裝 pv 命令。 在 Debian/Ubuntu Linux 上輸入以下 apt-get 命令:# apt-get install pv
示例輸出:
Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: doc-base The following NEW packages will be installed: pv 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 28.9 kB of archives. After this operation, 143 kB of additional disk space will be used. Get:1 https://mirror.anl.gov/debian/ squeeze/main pv amd64 1.1.4-1 [28.9 kB] Fetched 28.9 kB in 1s (16.1 kB/s) Selecting previously deselected package pv. (Reading database ... 32240 files and directories currently installed.) Unpacking pv (from .../archives/pv_1.1.4-1_amd64.deb) ... Processing triggers for man-db ... Setting up pv (1.1.4-1) .
對於 RHEL/CentOS/SL/Fedora Linux 用戶,打開 EPEL 倉庫並輸入以下 yum 命令安裝 pv。# yum install pv
示例輸出:
Loaded plugins: product-id, protectbase, rhnplugin, subscription-manager Updating certificate-based repositories. Unable to read consumer identity 0 packages excluded due to repository protections Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package pv.x86_64 0:1.1.4-3.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================== Package Arch Version Repository Size ==================================================================================================== Installing: pv x86_64 1.1.4-3.el6 epel 34 k Transaction Summary ==================================================================================================== Install 1 Package(s) Total download size: 34 k Installed size: 67 k Is this ok [y/N]: y Downloading Packages: pv-1.1.4-3.el6.x86_64.rpm | 34 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : pv-1.1.4-3.el6.x86_64 1/1 Installed products updated. Verifying : pv-1.1.4-3.el6.x86_64 1/1 Installed: pv.x86_64 0:1.1.4-3.el6 Complete!
FreeBSD 用戶可以通過鍵入以下命令使用端口安裝 pv:# cd /usr/ports/sysutils/pv/
# make install clean
或者,要添加二進制包,請運行:# pkg_add -r pv
pv 命令語法
語法是:
pv filename pv filename > /path/to/output pv options filename | command1 pv options filename | command1 > output.file pv filename | command1 command1 | pv | command2 pv -options input.file | command1 | pv -options > output.file
pv 命令示例
此示例將名為 origin-cdn.cyberciti.org_access.log 的文件複製到 /tmp/origin-cdn-access.log 並顯示進度。# pv origin-cdn.cyberciti.org_access.log > /tmp/origin-cdn-access.log
或將其發送到 /dev/null。# pv origin-cdn.cyberciti.org_access.log > /dev/null
1.41GB 0:00:21 [66.3MB/s] [=====================================================>] 100%
使用 nc 創建網絡端口#2000。輸入以下命令:$ nc -l -v -w 30 -p 2000 > /tmp/data.bin
打開另一個終端並輸入:$ pv firmware33921.bin | nc -w 1 127.0.0.1 2000
示例輸出:
在此示例中,您可以看到兩個管道的進度。
pv -cN rawlogfile origin-cdn.cyberciti.org_access.log | gzip | pv -cN gziplogfile > access.log.gz
示例輸出:
在哪裡,
- -c :使用光標位置轉義序列,而不僅僅是回車。如果您在單個長管道中使用多個 pv 調用,這與 -N (name) 結合使用很有用。
- N rawlogfile : 以 NAME 為輸出信息的前綴。如果您有一個複雜的管道並希望能夠區分它的不同部分,這與 -c 結合使用很有用。
pv 和對話框命令
你能行的 在復制/移動/解壓縮文件或使用儀錶框備份時創建進度條(進度指示器):
echo percentage | dialog --gauge "text" height width percent echo "10" | dialog --gauge "Please wait" 10 70 0 echo "50" | dialog --gauge "Please wait" 10 70 0 echo "100" | dialog --gauge "Please wait" 10 70 0
此示例提取 tarball 並使用對話框命令顯示進度。
(pv -n backup.tar.gz | tar xzf - -C path/to/data ) 2>&1 | dialog --gauge "Running tar, please wait..." 10 70 0
示例輸出:
最後,您始終可以使用 rsync 命令查看本地和遠程文件的進度條。
- 人太陽能
- 太陽能 項目主頁。