Linux 中的文件传输
###########1.實(shí)驗(yàn)環(huán)境###########
 需要2臺(tái)主機(jī)并且保證這兩臺(tái)主機(jī)是可以通信的
westos_linux : 172.25.254.1
 westos_node1 : 172.25.254.2
westos_linux&westos_node1:
systemctl disable firewalld
 systemctl stop firewalld
 ###########1 scp命令############
 scp?? 本地文件??? 遠(yuǎn)程主機(jī)用戶(hù)@遠(yuǎn)程主機(jī)ip:遠(yuǎn)程主機(jī)目錄的絕對(duì)路徑
 scp?? 遠(yuǎn)程主機(jī)用戶(hù)@遠(yuǎn)程主機(jī)ip:遠(yuǎn)程主機(jī)文件的絕對(duì)路徑? 本地文件
 實(shí)驗(yàn)步步驟:
 1.在rhel7建立實(shí)驗(yàn)素材
touch westos
 mkdir westosdir
2.測(cè)試
a)把本地文件復(fù)制到遠(yuǎn)程主機(jī)?? ?(上傳)
 scp ??? ?westos? ??? ?root@172.25.254.2:/root/Desktop
 scp -r?? ?westosdir?? ?root@172.25.254.2:/root/Desktop ## -r 表示復(fù)制目錄
 scp -q?? ?westos?? ??? ?root@172.25.254.2:/root/Desktop?? ??? ? ## -q 傳輸文件時(shí)不顯示進(jìn)度
b)把遠(yuǎn)程文件復(fù)制到本地(下載)
 scp root@172.25.254.2:/root/Desktop/westos_rhel8?? /root/Desktop
 ##############2.rsync##############
a) rsync和scp命令的對(duì)比
 實(shí)驗(yàn)素材:
 1)172.25.254.1
 dd if=/dev/zero of=/root/Desktop/westosfile1 bs=1M count=10?? ?##dd=截取,if=inputfile
 ?? ??? ??? ??? ??? ??? ??? ??? ?##of=outputfile
 ?? ??? ??? ??? ??? ??? ??? ??? ?#bs=blocksize
 ?? ??? ??? ??? ??? ??? ??? ??? ?#count=快的個(gè)數(shù)
 dd if=/dev/zero of=/root/Desktop/westosfile2 bs=1M count=20
 dd if=/dev/zero of=/root/Desktop/westosfile3 bs=1M count=30
2)在主機(jī)之間建立免密登陸使遠(yuǎn)程文件傳輸可以直接執(zhí)行
 rhel7中:
 ssh-keygen?? ??? ?## 生成密鑰
 ssh-copy-id -i /root/.ssh/id_rsa.pub. root@172.25.254.2
3)創(chuàng)建測(cè)試腳本
 vim check_scp.sh?? ??? ?##檢測(cè)scp傳輸時(shí)間
 time scp -qr /root/Desktop root@172.25.254.2:/root/Desktop
 time scp -qr /root/Desktop root@172.25.254.2:/root/Desktop
 time scp -qr /root/Desktop root@172.25.254.2:/root/Desktop
 vim check_rsync.sh?? ??? ?##檢測(cè)rsync的傳輸時(shí)間
 time rsync -raCq /root/Desktop root@172.25.254.2:/root/Desktop
 time rsync -raCq /root/Desktop root@172.25.254.2:/root/Desktop
 time rsync -raCq /root/Desktop root@172.25.254.2:/root/Desktop
 4)執(zhí)行
 #########scp ###################
 sh check_scp.sh
 real?? ?0m1.334s
 user?? ?0m0.210s
 sys?? ?0m0.490s?? ?第一次系統(tǒng)執(zhí)行時(shí)間
real?? ?0m1.642s
 user?? ?0m0.412s
 sys?? ?0m0.383s?? ?第二次系統(tǒng)執(zhí)行時(shí)間
real?? ?0m1.586s
 user?? ?0m0.309s
 sys?? ?0m0.497s?? ?第三次系統(tǒng)執(zhí)行時(shí)間
 以上執(zhí)行效果我們可以看出scp三次執(zhí)行時(shí)間幾乎一致
###########rsync執(zhí)行############
 sh check_rsync.sh
 real?? ?0m1.603s
 user?? ?0m0.399s
 sys?? ?0m0.557s?? ?第一次系統(tǒng)執(zhí)行時(shí)間
real?? ?0m0.329s
 user?? ?0m0.012s
 sys?? ?0m0.010s?? ?第二次系統(tǒng)執(zhí)行時(shí)間
real?? ?0m0.348s
 user?? ?0m0.014s
 sys?? ?0m0.022s?? ?第三次系統(tǒng)執(zhí)行時(shí)間
 以上執(zhí)行效果我們可以看出rsync三次執(zhí)行時(shí)間后兩次遠(yuǎn)遠(yuǎn)小與第一次
 b)rsync用法
 rsync ??? ?文件?? ??? ??? ?遠(yuǎn)程用戶(hù)@遠(yuǎn)程主機(jī)ip:遠(yuǎn)程主機(jī)目錄
 rsync?? ?遠(yuǎn)程用戶(hù)@遠(yuǎn)程主機(jī)ip:遠(yuǎn)程主機(jī)目錄?? ?文件路徑?? ?
 rsync
 ?? ?-r?? ?##復(fù)制目錄
 ?? ?-l?? ?##復(fù)制鏈接
 ?? ?-p?? ?##復(fù)制權(quán)限
 ?? ?-t?? ?##復(fù)制時(shí)間戳
 ?? ?-o?? ?##復(fù)制擁有者
 ?? ?-g?? ?##復(fù)制擁有組
 ?? ?-D?? ?##復(fù)制設(shè)備文件
實(shí)驗(yàn)環(huán)境
在westos_node1中
 watch -n 1 ls -lR /root/Desktop
 在rhel7中
 touch /root/Desktop/file{1..5}
 chmod 777 /root/Desktop/*
 useradd westos
 chown westos /root/Desktop/*
 ln -s /root/Desktop/file1 /root/Desktop/file
westos_linux執(zhí)行:
 執(zhí)行命令看效果:
 rsync? -r root@172.25.254.20:/root/Desktop?? ? /mnt?? ??? ?##同步目錄本身其目錄中的文件
 rsync? -r root@172.25.254.20:/root/Desktop/?? ? /mnt?? ??? ?##只同步目錄中的文件
 rsync? -rl root@172.25.254.20:/root/Desktop/?? ? /mnt?? ??? ?##同步鏈接
 rsync? -rlp root@172.25.254.20:/root/Desktop/?? ? /mnt?? ??? ?##同步權(quán)限
 rsync? -rlpog root@172.25.254.20:/root/Desktop/?? ? /mnt?? ??? ?##同步用戶(hù)組
 rsync? -rlpogt root@172.25.254.20:/root/Desktop/ /mnt?? ??? ?##同步時(shí)間
 rsync -rD root@172.25.254.20:/dev/pts?? ??? ? /mnt?? ??? ?##同步設(shè)備文件
?
#############文件的歸檔壓縮###############
 1.文件歸檔
 tar
 ?? ?c?? ??? ?##創(chuàng)建
 ?? ?f?? ??? ?##指定文件名稱(chēng)
 ?? ?x?? ??? ?##解檔
 ?? ?v?? ??? ?##現(xiàn)實(shí)過(guò)程
 ?? ?t?? ??? ?##查看
 ?? ?r?? ??? ?##向歸檔文件中添加文件
 ?? ?--get?? ??? ?##解檔指定文件
 ?? ?--delete?? ?##刪除指定文件
 ?? ?-C?? ??? ?##指定解檔路徑
實(shí)驗(yàn)步驟:
 tar cf etc.tar /etc/
 tar tf etc.tar
 tar rf etc.tar westos_rhel8
 tar xf etc.tar
 tar f etc.tar? --get westos_rhel8
 tar f etc.tar --delete westos_rhel8
 tar xf etc.tar -C /root/Desktop
 2.文件的壓縮
zip
 zip -r? mnt.tar.zip mnt.tar?? ?#zip格式壓縮
 unzip ?? ?mnt.tar.zip?? ??? ?#zip格式解壓縮
 gzip
 gzip?? ?mnt.tar?? ??? ??? ?#gzip格式壓縮
 gunzip ?? ?mnt.tar.gz?? ??? ?#gzip格式解壓縮
bzip2?? ?mnt.tar?? ??? ??? ?#bzip2格式壓縮
 bunzip2 etc.tar.bz2?? ??? ?#bzip2格式解壓縮
xz?? ?mnt.tar?? ??? ??? ?#xz格式壓縮
 unxz ?? ?mnt.tar.xz?? ??? ?#xz格式解壓縮
?
3.tar+壓縮
gzip
 tar zcf etc.tar.gz /etc
 tar zxf etc.tar.gz
 bzip2
 tar jcf etc.tar.bz2 /etc
 tar jxf etc.tar.bz2
xz
 tar Jcf etc.tar.xz /etc
 tar Jxf etc.tar.xz
?
?
總結(jié)
以上是生活随笔為你收集整理的Linux 中的文件传输的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
 
                            
                        - 上一篇: Linux 中的远程登陆
- 下一篇: Linux 系统之软件管理
