scp 和 cp 有什麼差別?

scp 和 cp 有什麼差別?

我對命令列和Ubuntu確實很陌生,最近才知道有指令scp還有指令cp。我嘗試使用scp命令將目錄從 A 點移動到 B 點,但沒有成功。然而,當我使用時cp,效果很好。

兩者之間有什麼區別?

答案1

長話短說閱讀手冊頁:

man scp
man cp

man scp

NAME
     scp — secure copy (remote file copy program)

SYNOPSIS
     scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 ...
         [[user@]host2:]file2

DESCRIPTION
     scp copies files between hosts on a network.  It uses ssh(1) for data transfer, and uses the same authentication and provides the same security
     as ssh(1).  scp will ask for passwords or passphrases if they are needed for authentication.

     File names may contain a user and host specification to indicate that the file is to be copied to/from that host.  Local file names can be made
     explicit using absolute or relative pathnames to avoid scp treating file names containing ‘:’ as host specifiers.  Copies between two remote
     hosts are also permitted.

man cp

NAME
       cp - copy files and directories

SYNOPSIS
       cp [OPTION]... [-T] SOURCE DEST
       cp [OPTION]... SOURCE... DIRECTORY
       cp [OPTION]... -t DIRECTORY SOURCE...

DESCRIPTION
       Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

       Mandatory arguments to long options are mandatory for short options too.

答案2

scp實際上是透過 SSH 進行遠端複製。例如:

scp /path/to/local/file user@server:/path/to/target/dir/

答案3

scp或安全複製主要用於在本機和遠端主機或兩個遠端主機之間進行複製,透過ssh

cp命令用於在本機複製文件,即在主機系統內複製文件。

muru 的手冊頁已在評論中鏈接應該可以幫助您理解用法,但是互聯網上也有很多教程。

答案4

如果檔案名稱中有空格,scp 比 cp 更好地處理它們,因此我經常使用它甚至在本機上進行複製。

相關內容