Linux中的scp指令

在Linux和Unix系统中,scp(Secure Copy Protocol)是一个用于通过SSH协议进行安全文件传输的命令行实用程序。与传统的cp(copy)命令不同,scp允许用户在不同的机器之间、或同一台机器的不同位置之间传输文件或文件夹。

语法

基本语法如下:

bash 复制代码
scp [options] [source] [destination]
  • options:可选参数,用于修改scp的行为
  • source:源文件或目录
  • destination:目标文件或目录

常用选项

  • -r:递归复制,用于复制目录及其内容。
  • -p:保留文件属性(如修改时间、访问时间等)。
  • -q:安静模式,不显示复制进度。
  • -v:详细模式,显示详细的调试信息。

示例

  1. 将本地文件复制到远程服务器

    bash 复制代码
    scp local_file.txt username@remote_host:/path/to/destination/
  2. 从远程服务器复制文件到本地

    bash 复制代码
    scp username@remote_host:/path/to/source/file.txt /local/destination/
  3. 复制目录到远程服务器

    bash 复制代码
    scp -r local_directory/ username@remote_host:/path/to/destination/
  4. 从一个远程服务器复制文件到另一个远程服务器

    bash 复制代码
    scp username1@remote_host1:/path/to/source/file.txt username2@remote_host2:/path/to/destination/
  5. 使用特定SSH端口

    bash 复制代码
    scp -P 2222 local_file.txt username@remote_host:/path/to/destination/

安全性

由于scp使用SSH进行数据传输,因此它是加密的,这提供了额外的安全层。

注意事项

  • 如果你首次连接到远程主机,系统可能会提示你确认远程主机的身份。
  • 你必须具有对源文件和目标位置的适当访问权限。

这只是scp命令的一个简单介绍。更多高级用法和选项可以通过查看其man页面(通过运行man scp)来了解。

相关推荐
xuhe220 分钟前
Claude Code配合Astro + GitHub Pages:为 sharelatex-ce 打造现代化的开源项目宣传页
linux·git·docker·github·浏览器·overleaf
charlie11451419125 分钟前
RK3568跑Arch Linux全路程指南(以正点原子的RK3568开发板为例子)
linux·嵌入式·rootfs·教程·环境配置·嵌入式linux·工程实践
爆米花byh1 小时前
在RockyLinux9环境的Doris单机版安装
linux·数据库·database
筱白爱学习3 小时前
RestHighLevelClient详细使用手册
linux·服务器·php
若谷老师3 小时前
21.WSL中部署gnina分子对接程序ds
linux·人工智能·ubuntu·卷积神经网络·gnina·smina
啊辉的科研5 小时前
植物单细胞RNA-seq分析教程3-2025年版
linux·r语言
Norach6 小时前
ubuntu22.04安装ssh-server与realvnc-server
linux·服务器·经验分享·ubuntu·ssh·vnc
UP_Continue6 小时前
Linux--进程间通信
linux·运维·服务器
kaoa0006 小时前
Linux入门攻坚——67、MySQL数据库-4
linux·运维·数据库·mysql
蓝天居士6 小时前
VMware Workstation挂载共享文件夹(2)
linux·ubuntu