Bash
讀取文件夾和子文件夾中的所有文件 - 進度和大小
我的命令是:
time find . -type f -print -exec cp {} /dev/null \;
此命令查找目前文件夾和子文件夾中的所有文件,列印每個文件的名稱並將每個文件複製到 /dev/null。最後它顯示了複製所有文件所花費的時間。
我需要的是在最後計算(顯示)所有複製的字節(這樣我就可以計算讀取速度//記憶體無關緊要//)和/或在文件名旁邊顯示每個文件的大小。
如果有可能顯示每個文件(pv)的進度 - 那會很棒!
為此,我使用 Cygwin 和它的 bash shell,但腳本也應該在真正的 Linux 系統上工作。
**編輯:**這個想法是讀取文件,而不是複制它們(rsync)。
不確定我是否完全理解您的問題,但是:
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
而不是使用
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