scp 和 cp 有什么区别?

BDD*_*BDD 10 command-line scp cp

我对命令行和 Ubuntu 真的很陌生,我最近了解到有scp命令和cp命令。我尝试使用scp命令将目录从 A 点移动到 B 点,但没有奏效。但是,当我使用 时cp,它工作得很好。

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

A.B*_*.B. 18

TL;DR阅读手册页:

man scp
man cp
Run Code Online (Sandbox Code Playgroud)

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.
Run Code Online (Sandbox Code Playgroud)

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.
Run Code Online (Sandbox Code Playgroud)

  • 好。我觉得很蠢。我完全忘记了手册页。谢谢! (5认同)

Oli*_*Oli 15

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

scp /path/to/local/file user@server:/path/to/target/dir/
Run Code Online (Sandbox Code Playgroud)


Arr*_*cal 8

scp 或 Secure Copy 主要用于在本地主机和远程主机或两个远程主机之间进行复制,通过 ssh

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

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