日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux系统中的文件传输(scp命令,rsync命令)

發布時間:2023/12/20 linux 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux系统中的文件传输(scp命令,rsync命令) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

實驗環境

需要2臺主機并且保證這兩臺主機是可以通信的

linux_westos? : 172.25.254.10

westos_lue?: ?172.25.254.20

systemctl disable? firewalld

systemctl stop firewalld

1.scp命令

  • scp ? 本地文件 ? ?遠程主機用戶@遠程主機ip:遠程主機目錄的絕對路徑
  • scp ? 遠程主機用戶@遠程主機ip:遠程主機文件的絕對路徑 ?本地文件

?實驗:

1.在172.25.254.10主機中建立實驗素材

?touch westosfile?

mkdir westosdir

touch westosdir/test{1..5}

echo "hello" > westosfile

?2.測試

?a)把本地文件復制到遠程主機 (上傳)(172.25.254.10)

scp ?westosfile? ?root@172.25.254.20:/root/Desktop

scp -r westosdir root@172.25.254.20:/root/Desktop ?-r 表示復制 目錄

scp -q westosfile root@172.25.254.20:/root/ Desktop ?-q 傳輸文件時不顯示進度

scp ?westosfile? ?root@172.25.254.20:/root/Desktop

scp -r westosdir root@172.25.254.20:/root/Desktop ?-r 表示復制 目錄

scp -q westos root@172.25.254.20:/root/ Desktop ?-q 傳輸文件時不顯示進度

b)把遠程文件復制到本地(下載)

scp root@172.25.254.20:/root/Desktop/testdir? ?/root/Desktop

2.rsync

  • ??rsync和scp命令的對比

實驗素材:

1)172.25.254.10:(du -sh *)

dd if=/dev/zero of=/root/Desktop/westosfile1 bs=1M count=10

dd=截取

if=inputfile

of=outputfile

bs=blocksize

count=個數

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)在主機之間建立免密登陸使遠程文件傳輸可以直接執行

rhel8中:

ssh-keygen ?生成密鑰

ssh-copy-id -i /root/.ssh/id_rsa.pub?root@172.25.254.20

3)創建測試腳本

vim /mnt/test_scp.sh? ? 檢測scp傳輸時間

time scp -qr /root/Desktop root@172.25.254.20:/root/Desktop

time scp -qr /root/Desktop root@172.25.254.20:/root/Desktop

time scp -qr /root/Desktop root@172.25.254.20:/root/Desktop

?vim /mnt/test_rsync.sh? 檢測rsync的傳輸時間

time rsync -racq /root/Desktop root@172.25.254.20:/root/Desktop

time rsync -racq /root/Desktop root@172.25.254.20:/root/Desktop

time rsync -racq /root/Desktop root@172.25.254.20:/root/Desktop

4)執行?

scp

sh /mnt/test_scp.sh

real 0m1.334s

user 0m0.210s

sys 0m0.490s 第一次系統執行時間

?real 0m1.642s

user 0m0.412s

sys 0m0.383s 第二次系統執行時間

?real 0m1.586s

user 0m0.309s

sys 0m0.497s 第三次系統執行時間

以上執行效果我們可以看出scp三次執行時間幾乎一致

rsync執行

sh /mnt/test_rsync.sh

real 0m1.603s

user 0m0.399s

sys 0m0.557s 第一次系統執行時間

real 0m0.329s

user 0m0.012s

sys 0m0.010s 第二次系統執行時間

?real 0m0.348s

user 0m0.014s

sys 0m0.022s 第三次系統執行時間

以上執行效果我們可以看出rsync三次執行時間后兩次遠遠小與第一次

  • rsync用法

rsync ?文件 遠程用戶@遠程主機ip:遠程主機目錄

rsync 遠程用戶@遠程主機ip:遠程主機目錄 文件路徑

rsync
? ? ? ? -r 復制目錄

? ? ? ? -l 復制鏈接

? ? ? ? -p 復制權限

? ? ? ? -t 復制時間戳

? ? ? ? -o 復制擁有者

? ? ? ? -g 復制擁有組

? ? ? ? -D 復制設備文件?

實驗環境

?在linux_westos中

watch -n 1 ls -lR /mnt/

在westos_lue中

touch westosfile{1..5}

ln -s /root/Desktop/westosfile1 /root/Desktop/westoslink

chown westos.westos *(chown westos /root/Desktop *)

chmod 777 *

?

執行命令看效果:(linux_westos)

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? ?同步權限

rsync ?-rlpog ?root@172.25.254.20:/root/Desktop /mnt? ?同步用戶組

rsync ?-rlpogt? ?root@172.25.254.20:/root/Desktop /mnt? ?同步時間

rsync -rD /dev/pts root@172.25.254.20: /dev/pts? /mnt?同步設備文件

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? ?同步權限

rsync ?-rlpog ?root@172.25.254.20:/root/Desktop /mnt? ?同步用戶組

rsync ?-rlpogt? ?root@172.25.254.20:/root/Desktop /mnt? ?同步時間

rsync -rD /dev/pts root@172.25.254.20: /dev/pts? /mnt?同步設備文件

文件的歸檔壓縮

1.文件歸檔

tar

c 創建

f 指定文件名稱

x 解檔

t 查看

-v 顯示過程

r 向歸檔文件中添加文件

--get 解檔指定文件

--delete 刪除指定文件

-C 指定解檔路徑

實驗步驟:

tar cf mnt.tar /mnt/

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

實驗素材

tar cf mnt.tar /mnt/

tar tvf mnt.tar

tar rf mnt.tar westosfile

tar xf mnt.tar

tar f mnt.tar ?--get westosfile

tar f mnt.tar --delete westosfile

tar xf mnt.tar -C /root/Desktop

2.文件的壓縮

zip

zip -r? mnt.tar.zip mnt.tar? ? ?zip格式壓縮

unzip tar mnt.zip? ? ? ? ? ? ? ? ?zip格式解壓縮

zip -r? mnt.tar.zip mnt.tar zip格式壓縮

unzip tar mnt.zip? ? ? ? ? ? ? ? ?zip格式解壓縮

gzip

gzip mnt.tar? ? ? ? ? ? ? ?gzip格式壓縮

gunzip mnt.tar.gz? ? ? ?gzip格式解壓縮

?bzip2 mnt.tar? ? ? ? ? ? ?bzip2格式壓縮

bunzip2 mnt.tar.bz2? ? bzip2格式解壓縮

xz mnt.tar? ? ? ? ? ? ? ? ? ? xz格式壓縮

unxz mnt.tar.xz? ? ? ? ? ? xz格式解壓縮

gzip mnt.tar gzip格式壓縮

gunzip mnt.tar.gz? ? ? ?gzip格式解壓縮

?bzip2 mnt.tar? ? ? ? ? ? ?bzip2格式壓縮

bunzip2 mnt.tar.bz2? ? bzip2格式解壓縮

xz mnt.tar? ? ? ? ? ? ? ? ? ? xz格式壓縮

unxz mnt.tar.xz? ? ? ? ? ? xz格式解壓縮

?

3.tar+壓縮

?gzip

tar zcf mnt.tar.gz /mnt?

tar zxf mnt.tar.gz? 解檔

bzip2

tar jcf mnt.tar.bz2 /mnt

tar jxf mnt.tar.bz2?

?xz

tar Jcf mnt.tar.xz /mnt

tar Jxf mnt.tar.xz


?
?
?
?
?
?
?
?
?
?
?

總結

以上是生活随笔為你收集整理的Linux系统中的文件传输(scp命令,rsync命令)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。