使用:
neofetch --stdout |grep 'OS:'
OS: Kubuntu 22.04.3 LTS x86_64
Shell: bash 5.1.16
rsync --version
rsync version 3.2.7 protocol version 31
变量,SourceDisK1src1
和目标des1
:
src1=` cat /tmp/01/sdk1_usb_disk `
des1='/media/u3/A1000G/Data/backupUSB2'
命令1:
time rsync -ah --delete-before --no-perms --info=progress2 "$src1/" "$des1" --out-format='%t %i %C %b %n %l'
command1_output 更新了 2 个文件b.sh
& c.txt
:
165.07K 0% 126.17MB/s 0:00:00 (xfr#1, to-chk=593/602)
2023/09/27 21:44:10 >f.st...... 22f876f17e77fb91281260a65f457f3b 165133 b.sh 165070
2023/09/27 21:44:10 .d..t...... 0 Misc/ 8192
165.85K 0% 25.38MB/s 0:00:00 (xfr#2, to-chk=215/602)
2023/09/27 21:44:10 >f.st...... 82dd3c8f657dee803b755955c146816c 827 Misc/c.txt 784
165.85K 0% 10.58MB/s 0:00:00 (xfr#2, to-chk=0/602)
real 0m0.108s
user 0m0.020s
sys 0m0.018s
。
命令2:
numfiles=$(rsync -auvh --stats --delete --log-file=/tmp/1.log --progress "$src1/" "$des1" |awk '/Number of regular files transferred:/{print $NF}') ;
echo $numfiles "regular files transferred"
命令2_输出:
2 regular files transferred
问题:
在 bash 中,如何发出一 (1) 个 rsync 命令并
获得上述输出1
和2
?
示例:
165.07K 0% 126.17MB/s 0:00:00 (xfr#1, to-chk=593/602)
2023/09/27 21:44:10 >f.st...... 22f876f17e77fb91281260a65f457f3b 165133 b.sh 165070
2023/09/27 21:44:10 .d..t...... 0 Misc/ 8192
165.85K 0% 25.38MB/s 0:00:00 (xfr#2, to-chk=215/602)
2023/09/27 21:44:10 >f.st...... 82dd3c8f657dee803b755955c146816c 827 Misc/c.txt 784
165.85K 0% 10.58MB/s 0:00:00 (xfr#2, to-chk=0/602)
real 0m0.108s
user 0m0.020s
sys 0m0.018s
2 regular files transferred
--