![scp 和 cp 有什么区别?](https://linux22.com/image/1127804/scp%20%E5%92%8C%20cp%20%E6%9C%89%E4%BB%80%E4%B9%88%E5%8C%BA%E5%88%AB%EF%BC%9F.png)
我对命令行和 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 更好地处理它们,因此出于这个原因,我甚至经常在本地机器上使用它来复制。