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

歡迎訪問 生活随笔!

生活随笔

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

linux

Linux 中的文件传输

發布時間:2024/9/3 linux 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux 中的文件传输 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

###########1.實驗環境###########
需要2臺主機并且保證這兩臺主機是可以通信的

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?? 本地文件??? 遠程主機用戶@遠程主機ip:遠程主機目錄的絕對路徑
scp?? 遠程主機用戶@遠程主機ip:遠程主機文件的絕對路徑? 本地文件


實驗步步驟:
1.在rhel7建立實驗素材

touch westos
mkdir westosdir

2.測試

a)把本地文件復制到遠程主機?? ?(上傳)
scp ??? ?westos? ??? ?root@172.25.254.2:/root/Desktop
scp -r?? ?westosdir?? ?root@172.25.254.2:/root/Desktop ## -r 表示復制目錄
scp -q?? ?westos?? ??? ?root@172.25.254.2:/root/Desktop?? ??? ? ## -q 傳輸文件時不顯示進度

b)把遠程文件復制到本地(下載)
scp root@172.25.254.2:/root/Desktop/westos_rhel8?? /root/Desktop


##############2.rsync##############

a) rsync和scp命令的對比
實驗素材:
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=快的個數
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)在主機之間建立免密登陸使遠程文件傳輸可以直接執行
rhel7中:
ssh-keygen?? ??? ?## 生成密鑰
ssh-copy-id -i /root/.ssh/id_rsa.pub. root@172.25.254.2

3)創建測試腳本
vim check_scp.sh?? ??? ?##檢測scp傳輸時間
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?? ??? ?##檢測rsync的傳輸時間
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)執行
#########scp ###################
sh check_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 check_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三次執行時間后兩次遠遠小與第一次


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


rsync
?? ?-r?? ?##復制目錄
?? ?-l?? ?##復制鏈接
?? ?-p?? ?##復制權限
?? ?-t?? ?##復制時間戳
?? ?-o?? ?##復制擁有者
?? ?-g?? ?##復制擁有組
?? ?-D?? ?##復制設備文件

實驗環境

在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執行:
執行命令看效果:
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 root@172.25.254.20:/dev/pts?? ??? ? /mnt?? ??? ?##同步設備文件

?

#############文件的歸檔壓縮###############
1.文件歸檔
tar
?? ?c?? ??? ?##創建
?? ?f?? ??? ?##指定文件名稱
?? ?x?? ??? ?##解檔
?? ?v?? ??? ?##現實過程
?? ?t?? ??? ?##查看
?? ?r?? ??? ?##向歸檔文件中添加文件
?? ?--get?? ??? ?##解檔指定文件
?? ?--delete?? ?##刪除指定文件
?? ?-C?? ??? ?##指定解檔路徑

實驗步驟:
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

?

?

總結

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

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