Linux命令——8 cp 复制 & 9 scp 远程复制

cpscp 是 Linux 中用于复制文件的命令, 用于不同的场景。

1. cp 命令

cp 命令用于在本地系统中复制文件和目录。

序号命令 (英文)参数 (英文)说明示例
1cp-r (recursive)递归复制目录及其内容 (Recursive)cp -r /source/dir /destination/dir 复制整个目录。
2cp-i (interactive)复制时提示用户确认 (Interactive)cp -i file1.txt file2.txt 如果 file2.txt 存在,提示确认。
3cp-u (update)只在源文件较新时复制文件 (Update)cp -u file1.txt /destination/ 只在 file1.txt 新时复制。
4cp-v (verbose)显示详细的复制过程 (Verbose)cp -v file1.txt /destination/ 复制时显示详细信息。
5cp-a (archive)以归档模式复制文件(保留属性) (Archive)cp -a /source/dir /destination/ 保留文件属性进行复制。

示例:

# 复制单个文件
cp file1.txt /destination/

# 递归复制整个目录
cp -r /source/dir /destination/dir

# 提示确认覆盖文件
cp -i file1.txt /destination/

# 只在源文件更新时复制
cp -u file1.txt /destination/

# 显示复制过程
cp -v file1.txt /destination/

2. scp 命令

scp 命令用于在本地和远程主机之间安全地复制文件。

序号命令 (英文)参数 (英文)说明示例
1scp-r (recursive)递归复制目录及其内容 (Recursive)scp -r /source/dir user@remote:/destination/ 复制整个目录到远程。
2scp-P (port)指定 SSH 端口号 (Port)scp -P 2222 file1.txt user@remote:/destination/ 指定端口复制。
3scp-i (identity file)指定私钥文件进行身份验证 (Identity File)scp -i /path/to/private/key file1.txt user@remote:/destination/
4scp-v (verbose)显示详细的复制过程 (Verbose)scp -v file1.txt user@remote:/destination/ 复制时显示详细信息。
5scp-q (quiet)安静模式,不显示输出 (Quiet)scp -q file1.txt user@remote:/destination/ 复制时不显示输出。

示例:

# 从本地复制文件到远程主机
scp file1.txt user@remote:/destination/

# 递归复制整个目录到远程主机
scp -r /source/dir user@remote:/destination/

# 指定 SSH 端口号进行复制
scp -P 2222 file1.txt user@remote:/destination/

# 使用私钥文件进行身份验证
scp -i /path/to/private/key file1.txt user@remote:/destination/

# 显示详细复制过程
scp -v file1.txt user@remote:/destination/

cpscp 的区别

区别cpscp
用途在本地系统中复制文件和目录在本地和远程主机之间安全地复制文件
协议不使用任何协议使用 SSH 协议进行安全传输
安全性无法加密,传输不安全加密传输,保证数据安全
使用场景适用于本地文件管理适用于远程文件传输
速度复制速度受限于本地磁盘速度速度受限于网络带宽和延迟

cp 主要用于本地文件的管理,而 scp 适用于需要跨网络传输文件的情况,并提供更高的安全性。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值