scp和cp有什么区别?


9

我真的是命令行和Ubuntu的新手,最近我了解到scp命令和cp命令都存在。我试图使用scp命令将目录从点A移到点B,但是它不起作用。但是,当我使用时cp,它工作得很好。

两者之间有什么区别?如何确定何时使用另一种?



当您说它不起作用时,您是什么意思?scp可用于将文件/目录从源复制到目标。源或目标或两者都可以是本地或远程的。
Mahesh

Answers:


18

TL; DR阅读手册页:

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.

5
好。我觉得很蠢 我完全忘记了手册页。谢谢!
BDD

15

scp确实用于通过SSH进行远程复制。例如:

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

7

scp 或“安全复制”主要用于通过以下方式在本地主机和远程主机或两个远程主机之间进行复制 ssh

cp命令用于在本地复制文件,即在主机系统内复制文件。

muru 在评论中链接的手册页应该可以帮助您了解用法,但是关于该互联网的内容也有很多教程。


3

您还应该了解有一个man命令。尝试一下!man cpman scpman man

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.

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).  Unlike rcp(1), scp will
     ask for passwords or passphrases if they are needed for authentication.

-2

如果文件名中有空格,则scp会比cp更好地处理它们,因此出于这个原因,我经常使用它甚至在本地计算机上进行复制。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.