linux命令學習之SCP命令

2021-09-20 03:10:37 字數 2234 閱讀 3531

一、scp命令介紹

scp是secure copy的簡寫,用於在linux下進行遠端拷貝檔案的命令,和它類似的命令有cp,不過cp只是在本機進行拷貝不能跨伺服器,而且scp傳輸是加密的。scp命令可以在linux伺服器之間複製檔案和目錄。

命令格式:scp [引數] [原路徑] [目標路徑]

二、scp用法

這裡假定:

local:192.168.0.1 使用者名稱:root 密碼:123

remote:192.168.0.2 使用者名稱:root 密碼:456

1、遠端主機拷貝到本地

1.1 將遠端主機remote_ip xx路徑下的**檔案** yyy.zz拷貝到本機的/aa/bb路徑下(檔名保持一致)

格式: scp remote_username@remote_ip:/xx/yyy.zz /aa/bb

示例:scp [email protected]:/usr/local/test.txt /usr/local 回車輸入密碼456

將遠端主機192.168.0.2的/usr/local路徑下的test.txt檔案拷貝到本機的/usr/local路徑下,檔名仍為test.txt

1.2 將遠端主機remote_ip xx路徑下的**檔案** yyy.zz拷貝到本機的/aa/bb路徑下(檔名保持一致)

格式: scp remote_username@remote_ip:/xx/yyy.zz /aa/bb

示例:scp [email protected]:/usr/local/test.txt /usr/local/test2.txt (回車輸入密碼456)

將遠端主機 192.168.0.2的/usr/local路徑下的test.txt檔案拷貝到本機的/usr/local路徑下,檔名改為test2.txt

1.3 將遠端主機remote_ip xx路徑下的**資料夾** yy拷貝到本機的/aa/bb路徑下,即bb路徑下會出現yy資料夾。

scp -r remote_username@remote_ip:/xx/yy /aa/bb

格式: scp remote_username@remote_ip:/xx/yyy.zz /aa/bb

示例:scp -r [email protected]:/usr/local/test /usr/local (回車輸入密碼456)

將遠端主機 192.168.0.2的/usr/local路徑下的test資料夾拷貝到本機的/usr/local路徑下。

2、本地拷貝到遠端主機

1.1 將本地主機local_ip xx路徑下的**檔案** yyy.zz拷貝到本機的/aa/bb路徑下(檔名保持一致)

格式:scp /aa/bb/cc.zz remote_username@remote_ip:/xx/

示例:scp /usr/local/test.txt [email protected]:/usr/local/ (回車輸入密碼456)

將本地主機192.168.0.1的/usr/local路徑下的test.txt檔案拷貝到遠端主機的/usr/local路徑下,檔名仍保持為test.txt

1.2 將本地主機local_ip xx路徑下的**檔案** yyy.zz拷貝到本機的/aa/bb路徑下(檔名保持一致)

格式:scp /aa/bb/cc.zz remote_username@remote_ip:/xx/yyy.zz

示例:scp /usr/local/test.txt [email protected]:/usr/local/test2.txt (回車輸入密碼456)

將本地主機192.168.0.1的/usr/local路徑下的test.txt檔案拷貝到遠端主機192.168.0.2的/usr/local路徑下,檔名儲存為test2.txt

1.3 將本地主機local_ip xx路徑下的**資料夾** bb拷貝到遠端主機的/xx路徑下(檔名保持一致)

格式:scp -r /aa/bb remote_username@remote_ip:/xx

示例:scp -r /usr/local/test [email protected]:/usr/local (回車輸入密碼456)

將本地主機192.168.0.1的/usr/local路徑下的test資料夾拷貝到遠端主機192.168.0.2的/usr/local路徑下。

Linux命令之 SCP 命令

名稱 cp 使用許可權 所有使用者 使用方式 cp options source dest cp options source.directory 說明 將乙個檔案拷貝至另一檔案,或將數個檔案拷貝至另一目錄。把計 a 盡可能將檔案狀態 許可權等資料都照原狀予以複製。r 若 source 中含有目錄名...

linux命令之scp命令

linux scp命令用於linux之間複製檔案和目錄。scp是 secure copy的縮寫,scp是linux系統下基於ssh登陸進行安全的遠端檔案拷貝命令。一 語法 可以使用scp help檢視命令用法 root localhost scp help unknown option usage ...

Linux命令學習 scp命令

scp命令用於兩台linux伺服器之間複製檔案。你當前登入的那台遠端伺服器就是本地伺服器,另一台就是遠端伺服器。scp 可選引數 file source file target 可選引數 1 強制scp命令使用協議ssh1 2 強制scp命令使用協議ssh2 4 強制scp命令只使用ipv4定址 6...