我的命令是:
time find . -type f -print -exec cp {} /dev/null \;
此命令查找当前文件夹和子文件夹中的所有文件,打印每个文件的名称并将它们复制到 /dev/null。最后它显示复制所有文件花费了多少时间。
我需要的是在末尾计算(显示)所有复制的字节(这样我就能够计算读取速度//缓存无关紧要//)和/或在文件名称旁边显示每个文件的大小。
如果能够显示每个文件 (pv) 的进度 -那就太好了!
为此,我使用 Cygwin 及其 bash shell,但脚本也应该在真正的 Linux 系统上运行。
编辑:这个想法是读取文件,而不是复制它们(rsync)。
答案1
不确定我完全理解你的问题,但是:
find . -type f -exec pv -N {} {} \; > /dev/null
给出如下输出:
./file1: 575kB 0:00:00 [1.71GB/s] [=======================>] 100%
./file2: 15.2GB 0:00:07 [2.22GB/s] [==> ] 15% ETA 0:00:38
答案2
而不是使用cp
andfind
对于此任务,您可能需要考虑使用rsync
。
例子
$ time rsync -avvz -O --stats --checksum --human-readable \
--acls --itemize-changes --progress \
--out-format='[%t] [%i] (Last Modified: %M) (bytes: %-10l) %-100n' \
"<fromDir>" "<toDir>" | tee /path/to/log.txt
例子
这将生成一个如下所示的报告。
命令
$ time rsync -avvz -O --stats --checksum --human-readable --acls --itemize-changes --progress --out-format='[%t] [%i] (Last Modified: %M) (bytes: %-10l) %-100n' "How_to_Write_Shared_Libraries" "/home/saml/newdir/." | tee ~/rsync.txt
每个传输文件的详细信息
sending incremental file list
delta-transmission disabled for local transfer or --whole-file
[2014/05/31 15:12:34] [cd+++++++++] (Last Modified: 2014/02/21-15:42:44) (bytes: 4096 ) How_to_Write_Shared_Libraries/
[2014/05/31 15:12:34] [>f+++++++++] (Last Modified: 2013/12/06-19:59:22) (bytes: 766590 ) How_to_Write_Shared_Libraries/dsohowto.pdf
766.59K 100% 20.00MB/s 0:00:00 (xfer#1, to-check=1/3)
[2014/05/31 15:12:34] [>f+++++++++] (Last Modified: 2014/02/21-15:42:44) (bytes: 44 ) How_to_Write_Shared_Libraries/url.txt
44 100% 1.23kB/s 0:00:00 (xfer#2, to-check=0/3)
total: matches=0 hash_hits=0 false_alarms=0 data=766634
有关整个转会的统计数据
rsync[5923] (sender) heap statistics:
arena: 1073152 (bytes from sbrk)
ordblks: 5 (chunks not in use)
smblks: 1
hblks: 2 (chunks from mmap)
hblkhd: 401408 (bytes from mmap)
allmem: 1474560 (bytes from sbrk + mmap)
usmblks: 0
fsmblks: 96
uordblks: 410512 (bytes used)
fordblks: 662640 (bytes free)
keepcost: 396928 (bytes in releasable chunk)
rsync[5926] (server receiver) heap statistics:
arena: 286720 (bytes from sbrk)
ordblks: 2 (chunks not in use)
smblks: 5
hblks: 3 (chunks from mmap)
hblkhd: 667648 (bytes from mmap)
allmem: 954368 (bytes from sbrk + mmap)
usmblks: 0
fsmblks: 384
uordblks: 180208 (bytes used)
fordblks: 106512 (bytes free)
keepcost: 102336 (bytes in releasable chunk)
rsync[5925] (server generator) heap statistics:
arena: 135168 (bytes from sbrk)
ordblks: 2 (chunks not in use)
smblks: 6
hblks: 2 (chunks from mmap)
hblkhd: 401408 (bytes from mmap)
allmem: 536576 (bytes from sbrk + mmap)
usmblks: 0
fsmblks: 464
uordblks: 88688 (bytes used)
fordblks: 46480 (bytes free)
keepcost: 32800 (bytes in releasable chunk)
转会统计摘要
Number of files: 3
Number of files transferred: 2
Total file size: 766.63K bytes
Total transferred file size: 766.63K bytes
Literal data: 766.63K bytes
Matched data: 0 bytes
File list size: 143
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 667.27K
Total bytes received: 54
sent 667.27K bytes received 54 bytes 1.33M bytes/sec
total size is 766.63K speedup is 1.15
花费的时间
real 0m0.092s
user 0m0.053s
sys 0m0.008s