赢了’到现在为止,我们已经感到惊讶 外壳进度条.
当我们复制大文件时,最好有一个ETA,进度条和一些反馈,但是 cp 命令不’为此提供我们。
当然,我们可以使用 同步 以获得过程的一些反馈,但是如果我们想要进度条,可能最简单的方法是使用 光伏 .
光伏 , 要么 管道查看器 是一个非常简洁的外壳工具,可让您监视管道。它的调用方式类似于 猫 命令。您可以通过管道传输并监视通过管道的数据的吞吐量
猫 srcfile | 光伏 > dstfile
您也可以直接使用它打开文件,就像 猫 。实际上,这就是您的做法“copy” a file using pv
光伏 srcfile > dstfile
但是该语法使用起来不是很好,而且一次只能限制在一个文件中。我想递归地在整个目录中使用它,所以我想出了一个小包装,带有惊人的原始名称 中央电视台 .
用法
调用就像 cp 。没有选择。显然要求您拥有 光伏 已安装。
中央电视台 file_or_dir_src file_or_dir_dst
那’是的。这确实是一个非常简单的包装器,但是非常方便。
在从网络安装架复制或复制到网络安装架以测量传输速度时,它也很有用。
安装
添加 码 给你 .zshrc 要么 .bashrc 。您可以一行完成此操作,但是 首先检查 所以你不’不必盲目相信我。
wget //raw.githubusercontent.com/nachoparker/cpv/master/cpv.sh -O - >> ~/.zshrc # ~/.bashrc
光伏更酷的东西
您可以做更多的复制工作。您可以获得几乎所有使用文件或管道的数据。
例如,您可以监控 网猫 转让
光伏 srcfile | nc -w 1 somewhere.com 3000
还是那个压缩包的创建
tar -cf - dir | 光伏 > tarball.tar
或Docker导出
码头工人 export minidebian_container | 光伏 > minidebian_export.tar
或那个ssh管
tar -cfz - dir | 光伏 | ssh pi@raspi " 猫 > ~/dir.tar.gz"
还是那个数据库转储
mysqldump -u root --single-transaction nextcloud | 光伏 > db-backup.sql
您可以随着进度刷新SD卡(即使我们最终拥有 dd status =进度 )
光伏 下一个 CloudPi.img > /dev/sdc; sync
零驱动器
光伏 < /dev/zero > /dev/sda
它甚至可以跟踪打开的文件描述符,因此您可以在进程启动后监视操作
mysqldump -u root --single-transaction nextcloud > db-backup.sql pv -d $(pidof mysqldump)
码
#!/bin/bash # 光伏 wrapper that imitates cp usage # # Copyleft 2017 通过 Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com> # GPL licensed (see end of file) * Use at your own risk! # # 用法 : # 中央电视台 file_or_dir_src file_or_dir_dst # # More details at ownyourbits.com function 中央电视台 () { local DST=${@: -1} # last element local SRC=( ${@: 1 : $# - 1} ) # array with rest of elements # checks type 光伏 &>/dev/null || { echo "install 光伏 first"; return 1; } [ $# -lt 2 ] && { echo "too few args" ; return 1; } # special invocation function 中央电视台 _rename() { local SRC="$1" local DST="$2" local DSTDIR="$( dirname "$DST" )" # checks if [ $# -ne 2 ]; then echo "too few args" ; return 1; fi if ! [ -e "$SRC" ]; then echo "$SRC doesn't exist" ; return 1; fi if [ -d "$SRC" ]; then echo "$SRC is a dir" ; return 1; fi if ! [ -d "$DSTDIR" ]; then echo "$DSTDIR does not exist"; return 1; fi # actual 复制 echo -e "\n$SRC ? $DST" 光伏 "$SRC" >"$DST" } # special case for 中央电视台 _rename() if ! [ -d "$DST" ]; then 中央电视台 _rename "$@"; return $?; fi; # more checks for src in "${SRC[@]}"; do local dst="$DST/$( basename "$src" )" if ! [ -e "$src" ]; then echo "$src doesn't exist" ; return 1; elif [ -e "$dst" ]; then echo "$dst already exists"; return 1; fi done # actual 复制 for src in "${SRC[@]}"; do if ! [ -d "$src" ]; then local dst="$DST/$( basename "$src" )" echo -e "\n$src ? $dst" 光伏 "$src" > "$dst" else local dir="$DST/$( basename "$src" )" mkdir "$dir" || continue local srcs=( $src/* ) 中央电视台 "${srcs[@]}" "$dir"; fi done unset 中央电视台 _rename } # License # # This script is free 软件 ; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published 通过 # the Free Software Foundation; either version 2 of the License, 要么 # (at your option) any later version. # # This script is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY 要么 FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a 复制 of the GNU General Public License # along with this script; if not, write to the # Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA
查看其他 贝壳制品
或者只是使用rsync–info=progress2
提供进度条吗?不是上次我检查
你好nachoparker,
您正在使用哪个发行版linux?
我喜欢GUI桌面,您能帮我发个名字吗?
谢谢
嗨,我将Arch Linux与普通的openbox一起使用…真的很少的东西
您好,
how can I 复制 the whole directory recursively?
它默认递归复制
好的代码,谢谢分享。我使用pv复制(备份)VM’在KVM中。我喜欢进度条,因为有些较大的进度条,我质疑它是否挂断或仍在工作。