成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

如何在Linux上復制文件/文件夾到遠程系統?

系統 Linux
從一個服務器復制文件到另一個服務器,或者從本地到遠程復制是 Linux 管理員的日常任務之一。

[[258145]]

 從一個服務器復制文件到另一個服務器,或者從本地到遠程復制是 Linux 管理員的日常任務之一。

我覺得不會有人不同意,因為無論在哪里這都是你的日常操作之一。有很多辦法都能處理這個任務,我們試著加以概括。你可以挑一個喜歡的方法。當然,看看其他命令也能在別的地方幫到你。

我已經在自己的環境下測試過所有的命令和腳本了,因此你可以直接用到日常工作當中。

通常大家都傾向 scp,因為它是文件復制的原生命令native command之一。但本文所列出的其它命令也很好用,建議你嘗試一下。

文件復制可以輕易地用以下四種方法。

  • scp:在網絡上的兩個主機之間復制文件,它使用 ssh 做文件傳輸,并使用相同的認證方式,具有相同的安全性。
  • rsync:是一個既快速又出眾的多功能文件復制工具。它能本地復制、通過遠程 shell 在其它主機之間復制,或者與遠程的 rsync 守護進程daemon 之間復制。
  • pscp:是一個并行復制文件到多個主機上的程序。它提供了諸多特性,例如為 scp 配置免密傳輸,保存輸出到文件,以及超時控制。
  • prsync:也是一個并行復制文件到多個主機上的程序。它也提供了諸多特性,例如為 ssh 配置免密傳輸,保存輸出到 文件,以及超時控制。

方式 1:如何在 Linux 上使用 scp 命令從本地系統向遠程系統復制文件/文件夾?

scp 命令可以讓我們從本地系統復制文件/文件夾到遠程系統上。

我會把 output.txt 文件從本地系統復制到 2g.CentOS.com 遠程系統的 /opt/backup 文件夾下。

  1. # scp output.txt root@2g.CentOS.com:/opt/backup
  2.  
  3. output.txt 100% 2468 2.4KB/s 00:00

從本地系統復制兩個文件 output.txtpasswd-up.sh 到遠程系統 2g.CentOs.com/opt/backup 文件夾下。

  1. # scp output.txt passwd-up.sh root@2g.CentOS.com:/opt/backup
  2.  
  3. output.txt 100% 2468 2.4KB/s 00:00
  4. passwd-up.sh 100% 877 0.9KB/s 00:00

從本地系統復制 shell-script 文件夾到遠程系統 2g.CentOs.com/opt/back 文件夾下。

這會連同shell-script 文件夾下所有的文件一同復制到/opt/back 下。

  1. # scp -r /home/daygeek/2g/shell-script/ root@:/opt/backup/
  2.  
  3. output.txt 100% 2468 2.4KB/s 00:00
  4. ovh.sh 100% 76 0.1KB/s 00:00
  5. passwd-up.sh 100% 877 0.9KB/s 00:00
  6. passwd-up1.sh 100% 7 0.0KB/s 00:00
  7. server-list.txt 100% 23 0.0KB/s 00:00

方式 2:如何在 Linux 上使用 scp 命令和 Shell 腳本復制文件/文件夾到多個遠程系統上?

如果你想復制同一個文件到多個遠程服務器上,那就需要創建一個如下面那樣的小 shell 腳本。

并且,需要將服務器添加進 server-list.txt 文件。確保添加成功后,每個服務器應當單獨一行。

最終,你想要的腳本就像下面這樣:

  1. # file-copy.sh
  2.  
  3. #!/bin/sh
  4. for server in `more server-list.txt`
  5. do
  6. scp /home/daygeek/2g/shell-script/output.txt root@$server:/opt/backup
  7. done

完成之后,給 file-copy.sh 的文件設置可執行權限。

  1. # chmod +x file-copy.sh

然后運行腳本完成復制。

  1. # ./file-copy.sh
  2.  
  3. output.txt 100% 2468 2.4KB/s 00:00
  4. output.txt 100% 2468 2.4KB/s 00:00

使用下面的腳本可以復制多個文件到多個遠程服務器上。

  1. # file-copy.sh
  2.  
  3. #!/bin/sh
  4. for server in `more server-list.txt`
  5. do
  6. scp /home/daygeek/2g/shell-script/output.txt passwd-up.sh root@$server:/opt/backup
  7. done

下面結果顯示所有的兩個文件都復制到兩個服務器上。

  1. # ./file-cp.sh
  2.  
  3. output.txt 100% 2468 2.4KB/s 00:00
  4. passwd-up.sh 100% 877 0.9KB/s 00:00
  5. output.txt 100% 2468 2.4KB/s 00:00
  6. passwd-up.sh 100% 877 0.9KB/s 00:00

使用下面的腳本遞歸地復制文件夾到多個遠程服務器上。

  1. # file-copy.sh
  2.  
  3. #!/bin/sh
  4. for server in `more server-list.txt`
  5. do
  6. scp -r /home/daygeek/2g/shell-script/ root@$server:/opt/backup
  7. done

上述腳本的輸出。

  1. # ./file-cp.sh
  2.  
  3. output.txt 100% 2468 2.4KB/s 00:00
  4. ovh.sh 100% 76 0.1KB/s 00:00
  5. passwd-up.sh 100% 877 0.9KB/s 00:00
  6. passwd-up1.sh 100% 7 0.0KB/s 00:00
  7. server-list.txt 100% 23 0.0KB/s 00:00
  8.  
  9. output.txt 100% 2468 2.4KB/s 00:00
  10. ovh.sh 100% 76 0.1KB/s 00:00
  11. passwd-up.sh 100% 877 0.9KB/s 00:00
  12. passwd-up1.sh 100% 7 0.0KB/s 00:00
  13. server-list.txt 100% 23 0.0KB/s 00:00

方式 3:如何在 Linux 上使用 pscp 命令復制文件/文件夾到多個遠程系統上?

pscp 命令可以直接讓我們復制文件到多個遠程服務器上。

使用下面的 pscp 命令復制單個文件到遠程服務器。

  1. # pscp.pssh -H 2g.CentOS.com /home/daygeek/2g/shell-script/output.txt /opt/backup
  2.  
  3. [1] 18:46:11 [SUCCESS] 2g.CentOS.com

使用下面的 pscp 命令復制多個文件到遠程服務器。

  1. # pscp.pssh -H 2g.CentOS.com /home/daygeek/2g/shell-script/output.txt ovh.sh /opt/backup
  2.  
  3. [1] 18:47:48 [SUCCESS] 2g.CentOS.com

使用下面的 pscp 命令遞歸地復制整個文件夾到遠程服務器。

  1. # pscp.pssh -H 2g.CentOS.com -r /home/daygeek/2g/shell-script/ /opt/backup
  2.  
  3. [1] 18:48:46 [SUCCESS] 2g.CentOS.com

使用下面的 pscp 命令使用下面的命令復制單個文件到多個遠程服務器。

  1. # pscp.pssh -h server-list.txt /home/daygeek/2g/shell-script/output.txt /opt/backup
  2.  
  3. [1] 18:49:48 [SUCCESS] 2g.CentOS.com
  4. [2] 18:49:48 [SUCCESS] 2g.Debian.com

使用下面的 pscp 命令復制多個文件到多個遠程服務器。

  1. # pscp.pssh -h server-list.txt /home/daygeek/2g/shell-script/output.txt passwd-up.sh /opt/backup
  2.  
  3. [1] 18:50:30 [SUCCESS] 2g.Debian.com
  4. [2] 18:50:30 [SUCCESS] 2g.CentOS.com

使用下面的命令遞歸地復制文件夾到多個遠程服務器。

  1. # pscp.pssh -h server-list.txt -r /home/daygeek/2g/shell-script/ /opt/backup
  2.  
  3. [1] 18:51:31 [SUCCESS] 2g.Debian.com
  4. [2] 18:51:31 [SUCCESS] 2g.CentOS.com

方式 4:如何在 Linux 上使用 rsync 命令復制文件/文件夾到多個遠程系統上?

rsync 是一個即快速又出眾的多功能文件復制工具。它能本地復制、通過遠程 shell 在其它主機之間復制,或者在遠程 rsync 守護進程daemon 之間復制。

使用下面的 rsync 命令復制單個文件到遠程服務器。

  1. # rsync -avz /home/daygeek/2g/shell-script/output.txt root@:/opt/backup
  2.  
  3. sending incremental file list
  4. output.txt
  5.  
  6. sent 598 bytes received 31 bytes 1258.00 bytes/sec
  7. total size is 2468 speedup is 3.92

使用下面的 rsync 命令復制多個文件到遠程服務器。

  1. # rsync -avz /home/daygeek/2g/shell-script/output.txt passwd-up.sh root@2g.CentOS.com:/opt/backup
  2.  
  3. sending incremental file list
  4. output.txt
  5. passwd-up.sh
  6.  
  7. sent 737 bytes received 50 bytes 1574.00 bytes/sec
  8. total size is 2537 speedup is 3.22

使用下面的 rsync 命令通過 ssh 復制單個文件到遠程服務器。

  1. # rsync -avzhe ssh /home/daygeek/2g/shell-script/output.txt root@2g.CentOS.com:/opt/backup
  2.  
  3. sending incremental file list
  4. output.txt
  5.  
  6. sent 598 bytes received 31 bytes 419.33 bytes/sec
  7. total size is 2.47K speedup is 3.92

使用下面的 rsync 命令通過 ssh 遞歸地復制文件夾到遠程服務器。這種方式只復制文件不包括文件夾。

  1. # rsync -avzhe ssh /home/daygeek/2g/shell-script/ root@2g.CentOS.com:/opt/backup
  2.  
  3. sending incremental file list
  4. ./
  5. output.txt
  6. ovh.sh
  7. passwd-up.sh
  8. passwd-up1.sh
  9. server-list.txt
  10.  
  11. sent 3.85K bytes received 281 bytes 8.26K bytes/sec
  12. total size is 9.12K speedup is 2.21

方式 5:如何在 Linux 上使用 rsync 命令和 Shell 腳本復制文件/文件夾到多個遠程系統上?

如果你想復制同一個文件到多個遠程服務器上,那也需要創建一個如下面那樣的小 shell 腳本。

  1. # file-copy.sh
  2.  
  3. #!/bin/sh
  4. for server in `more server-list.txt`
  5. do
  6. rsync -avzhe ssh /home/daygeek/2g/shell-script/ root@2g.CentOS.com$server:/opt/backup
  7. done

上面腳本的輸出。

  1. # ./file-copy.sh
  2.  
  3. sending incremental file list
  4. ./
  5. output.txt
  6. ovh.sh
  7. passwd-up.sh
  8. passwd-up1.sh
  9. server-list.txt
  10.  
  11. sent 3.86K bytes received 281 bytes 8.28K bytes/sec
  12. total size is 9.13K speedup is 2.21
  13.  
  14. sending incremental file list
  15. ./
  16. output.txt
  17. ovh.sh
  18. passwd-up.sh
  19. passwd-up1.sh
  20. server-list.txt
  21.  
  22. sent 3.86K bytes received 281 bytes 2.76K bytes/sec
  23. total size is 9.13K speedup is 2.21

方式 6:如何在 Linux 上使用 scp 命令和 Shell 腳本從本地系統向多個遠程系統復制文件/文件夾?

在上面兩個 shell 腳本中,我們需要事先指定好文件和文件夾的路徑,這兒我做了些小修改,讓腳本可以接收文件或文件夾作為輸入參數。當你每天需要多次執行復制時,這將會非常有用。

  1. # file-copy.sh
  2.  
  3. #!/bin/sh
  4. for server in `more server-list.txt`
  5. do
  6. scp -r $1 root@2g.CentOS.com$server:/opt/backup
  7. done

輸入文件名并運行腳本。

  1. # ./file-copy.sh output1.txt
  2.  
  3. output1.txt 100% 3558 3.5KB/s 00:00
  4. output1.txt 100% 3558 3.5KB/s 00:00

方式 7:如何在 Linux 系統上用非標準端口復制文件/文件夾到遠程系統?

如果你想使用非標準端口,使用下面的 shell 腳本復制文件或文件夾。

如果你使用了非標準Non-Standard端口,確保像下面 scp 命令那樣指定好了端口號。

  1. # file-copy-scp.sh
  2.  
  3. #!/bin/sh
  4. for server in `more server-list.txt`
  5. do
  6. scp -P 2222 -r $1 root@2g.CentOS.com$server:/opt/backup
  7. done

運行腳本,輸入文件名。

  1. # ./file-copy.sh ovh.sh
  2.  
  3. ovh.sh 100% 3558 3.5KB/s 00:00
  4. ovh.sh 100% 3558 3.5KB/s 00:00

如果你使用了非標準Non-Standard端口,確保像下面 rsync 命令那樣指定好了端口號。

  1. # file-copy-rsync.sh
  2.  
  3. #!/bin/sh
  4. for server in `more server-list.txt`
  5. do
  6. rsync -avzhe 'ssh -p 2222' $1 root@2g.CentOS.com$server:/opt/backup
  7. done

運行腳本,輸入文件名。

  1. # ./file-copy-rsync.sh passwd-up.sh
  2. sending incremental file list
  3. passwd-up.sh
  4.  
  5. sent 238 bytes received 35 bytes 26.00 bytes/sec
  6. total size is 159 speedup is 0.58
  7.  
  8. sending incremental file list
  9. passwd-up.sh
  10.  
  11. sent 238 bytes received 35 bytes 26.00 bytes/sec
  12. total size is 159 speedup is 0.58

 

責任編輯:龐桂玉 來源: Linux中國
相關推薦

2017-05-03 15:30:38

LinuxMeld比較文件夾

2020-12-28 06:44:45

FedoraLinux RPM文件

2018-01-24 15:35:22

Linux隱藏文件管理器

2014-02-12 10:58:05

Linux文件夾文件權限

2015-08-05 09:40:26

2019-06-10 08:15:52

Linux命令

2016-12-20 09:47:17

Linux命令復制文件到多個目錄

2018-02-25 09:48:36

LinuxUbuntu文件系統

2021-07-10 11:20:44

FreeDOS歸檔文件

2019-04-26 09:50:21

Linux壓縮文件文件夾

2018-01-09 09:00:01

Linux命令文件壓縮

2015-06-01 12:19:03

FedoraCentOSSamba

2019-09-16 11:40:49

Linux交換文件

2023-12-20 22:04:17

Linux二進制文件

2014-12-03 08:53:59

eCryptFS加密文件

2019-09-03 08:57:52

Linux命令軟件

2022-07-21 11:31:28

UbuntuWindowsLinux

2022-08-09 15:30:41

Linux

2013-11-14 10:32:40

Linux系統監測系統溫度

2015-08-04 14:04:28

UbuntuPDF文件
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 久干网 | 成人在线精品视频 | 欧美在线观看免费观看视频 | 亚洲日本一区二区三区四区 | 国产视频久久 | 精品久久久久久国产 | 亚洲欧美在线观看 | 神马久久av| 成人av电影天堂 | 亚洲高清成人 | 国产精品久久久久久久久久久久久 | 欧美午夜一区 | a级在线免费 | 午夜在线精品 | 欧美在线视频不卡 | 欧美激情第一区 | 久久国产婷婷国产香蕉 | 91影视 | 亚洲一区二区三区福利 | 亚洲区一区二区 | 最新91在线| 亚洲国产精品一区二区第一页 | 另类 综合 日韩 欧美 亚洲 | 国产四区| 99热精品在线| 久草成人| 欧美日韩免费在线 | 日韩成人免费av | 91麻豆精品国产91久久久更新资源速度超快 | 国产精品69毛片高清亚洲 | 中文字幕在线观看第一页 | eeuss国产一区二区三区四区 | 丁香色婷婷 | 亚洲免费一区二区 | 91久久夜色精品国产网站 | 亚洲 欧美 日韩 在线 | 亚洲一区欧美 | 综合五月 | 日韩 国产 在线 | 精品久久久久一区二区国产 | 成人免费在线观看 |