歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> 每天一個Linux命令(63)scp命令

每天一個Linux命令(63)scp命令

日期:2017/3/3 11:39:07   编辑:Linux技術

[b] scp(secure copy)用於進行遠程文件拷貝。[/b][b] (1)用法:[/b]

[b] 用法: scp [參數] [源文件] [目標文件][/b][b] (2)功能:[/b]

[b] 功能: scp在主機間復制文件,他使用 ssh(1)作為數據傳輸,而且用同樣認證和安全性。兩個遠程登錄的服務器間的文件復制是允許的。[/b][b] (3)選項參數:[/b]

1) -r     遞歸的復制整個文件夾 2) -p    保留文件的最後修改時間,最後訪問時間和權限模式;

[b] (4)實例:[/b] 1)root@Unbuntu:/home/sunjimeng/桌面# rcp sunmeng@CentOS:/home/sunmeng/rcptext ./   將遠程文件復制到本地

root@Unbuntu:/home/sunjimeng/桌面# ll
總用量 8
drwxr-xr-x  2 sunjimeng sunjimeng 4096  6月 30 08:42 ./
drwxr-xr-x 20 sunjimeng sunjimeng 4096  6月 29 08:27 ../
root@Unbuntu:/home/sunjimeng/桌面# rcp sunmeng@CentOS:/home/sunmeng/rcptext ./
root@Unbuntu:/home/sunjimeng/桌面# ll
總用量 8
drwxr-xr-x  2 sunjimeng sunjimeng 4096  6月 30 08:56 ./
drwxr-xr-x 20 sunjimeng sunjimeng 4096  6月 29 08:27 ../
-rw-r--r--  1 root      root         0  6月 30 08:56 rcptext
2)root@Unbuntu:/home/sunjimeng/桌面# rcp -r sunmeng@CentOS:/home/sunmeng/Documents ./  復制遠程文件到本地

root@Unbuntu:/home/sunjimeng/桌面# rcp sunmeng@CentOS:/home/sunmeng/Documents ./
rcp: /home/sunmeng/Documents: not a plain file
root@Unbuntu:/home/sunjimeng/桌面# rcp -r sunmeng@CentOS:/home/sunmeng/Documents ./
root@Unbuntu:/home/sunjimeng/桌面# ll
總用量 12
drwxr-xr-x  3 sunjimeng sunjimeng 4096  6月 30 08:59 ./
drwxr-xr-x 20 sunjimeng sunjimeng 4096  6月 29 08:27 ../
drwxr-xr-x  2 root      root      4096  6月 30 08:59 Documents/
-rw-r--r--  1 root      root         0  6月 30 08:56 rcptext
3)將遠程文件復制到本地

CentOS:
[root@localhost Documents]# ll
總用量 8
-rw-r--r--. 1 root root 38 6月  27 07:19 text1.txt
-rw-r--r--. 1 root root 46 6月  27 07:19 text2.txt
Unbuntu:
root@Unbuntu:/home/sunjimeng/桌面# ll
總用量 8
drwxr-xr-x  2 sunjimeng sunjimeng 4096  6月 30 09:00 ./
drwxr-xr-x 20 sunjimeng sunjimeng 4096  6月 29 08:27 ../
root@Unbuntu:/home/sunjimeng/桌面# touch Unbuntu.txt
root@Unbuntu:/home/sunjimeng/桌面# rcp  ./Unbuntu.txt sunmeng@CentOS:/home/sunmeng/Documents/
CentOS:
[root@localhost Documents]# ll
總用量 8
-rw-r--r--. 1 root    root    38 6月  27 07:19 text1.txt
-rw-r--r--. 1 root    root    46 6月  27 07:19 text2.txt
-rw-r--r--  1 sunmeng sunmeng  0 6月  29 18:05 Unbuntu.txt
4)[root@localhost Documents]# rcp -p text2.txt root@Unbuntu:/home/sunjimeng/桌面    復制文件時保留原文件的屬性

CentOS:
[root@localhost Documents]# ll
總用量 8
-rw-r--r--. 1 root    root    38 6月  27 07:19 text1.txt
-rw-r--r--. 1 root    root    46 6月  27 07:19 text2.txt
[root@localhost Documents]# rcp  text1.txt root@Unbuntu:/home/sunjimeng/桌面
[root@localhost Documents]# rcp -p text2.txt root@Unbuntu:/home/sunjimeng/桌面
Unbuntu:
root@Unbuntu:/home/sunjimeng/桌面# ll
總用量 16
drwxr-xr-x  2 sunjimeng sunjimeng 4096  6月 30 09:20 ./
drwxr-xr-x 20 sunjimeng sunjimeng 4096  6月 30 09:18 ../
-rw-r--r--  1 root      root        38  6月 30 09:19 text1.txt
-rw-r--r--  1 root      root        46  6月 27 22:19 text2.txt
(5)其他:

rcp余scp的區別:

rcp通過rsh方式遠端復制文件或目錄;scp通過ssh方式遠端復制文件或目錄。 rcp是一種不安全的的傳輸文件的方式,scp則比較安全,但有可能scp命令執行時需要用戶輸入密碼和口令。

linux下不同服務器間數據傳輸命令和工具:rcp,scp,rsync,ftp,sftp,lftp,wget,curl。(http://blog.csdn.net/emili/article/details/6858818)

Copyright © Linux教程網 All Rights Reserved