写在前面Linux基础教程已经收官教程回顾可点击:Linux基础教程。当然我们后续也会推出更多的Linux与生信相关教程大家可以点击收藏方便持续关注生信Linux及服务器使用技巧。大家如果需要算力/服务器也可以点击这个系列选到自己心仪的设备有root权限的共享服务器生信分析不求人为实验室准备一份生物信息学不动产本文就带大家一起学习Linux中常见的文件传输命令帮助你快速传输大型文件。在学习之前准备好自己服务器的IP、用户名、端口、密码这些信息啦(你能连接服务器当然也就知道这些信息)。scp联通的不同的主机传输文件scp 与 cp 的区别是cp 用于在 linux 本机下拷贝文件到其他路径。scp 的原理其实是使用 ssh 协议登陆到 linux 服务器然后传输文件。ssh 协议可以使用用户名和密码登陆Linux也可以使用用户名和密钥来登陆。以下的 userhostportxx.pem都需要代入具体的值sshuserhost-pport(需要输入密码)sshuserhost-pport-ixx.pem 使用密钥进行认证# 使用 scp 拷贝文件时使用的命令与 ssh 是类似的。scp-Pport userhost:/tmp/xiyou.txt.(将远程主机的 /tmp/xiyou.txt 文件拷贝到本机的当前工作目录这里.表示当前目录需要输入密码)scp-r-Pport userhost:/tmp/.(复制远程主机上的目录到本机的当前工作目录)scp-ixx.pem-Pport userhost:/tmp/xiyou.txt.(使用秘钥 xx.pem 的方式认证不需要输入密码秘钥需要提前生成)# 将本地的文件拷贝到远程主机上scp-Pport userhost:/tmp xiyou.txtwget用于从网络中下载文件# 下载链接中的图片 https://mirrors.tuna.tsinghua.edu.cn/static/img/logo-small-dark.png 并存储为 tuna.pngwget-Otuna.pnghttps://mirrors.tuna.tsinghua.edu.cn/static/img/logo-small-dark.pngls-la|greptuna.png# 下载一个文件不指定文件名wgethttps://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpgls-la|grepgpg# 查看 wget 其他参数的使用方法wget--help# -c 参数支持断点续传这在传输大文件时十分有用wget-c-Otuna2.png https://mirrors.tuna.tsinghua.edu.cn/static/img/logo-small-dark.pngmwgetmwget 是 wget 的升级版支持多线程下载速度更快。安装方式如下# 安装编译依赖sudoaptupdatesudoaptinstallbuild-essential-ysudoaptupgrade intltool-ysudoaptinstalllibssl-dev-y# 编译gitclone https://github.com/rayylee/mwget.gitcdmwget ./configuresudomakesudomakeinstall# 查看使用方法mwget--helpmwget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpgcurl通常用来在终端中模拟浏览器访问网站curl 也可以用来下载文件不过使用体验不如 wget。# 使用 curl 下载链接中的文件并保存为 tuna3.pngcurl-otuna3.png https://mirrors.tuna.tsinghua.edu.cn/static/img/logo-small-dark.png# 查看 curl 的其他用法curl--helprsync参考链接https://www.ruanyifeng.com/blog/2020/08/rsync.html# 使用 2234 端口将本地的 source 目录拷贝到远程机的 /destination 目录rsync-av-essh -p 2234source/ userremote_host:/destination