写在前面
Linux基础教程已经收官,教程回顾可点击:Linux基础教程。当然,我们后续也会推出更多的Linux与生信相关教程,大家可以点击收藏方便持续关注:生信Linux及服务器使用技巧。
大家如果需要算力/服务器也可以点击这个系列选到自己心仪的设备:
有root权限的共享服务器
生信分析不求人
为实验室准备一份生物信息学不动产
本文就带大家一起学习Linux中常见的文件传输命令,帮助你快速传输大型文件。在学习之前,准备好自己服务器的IP、用户名、端口、密码这些信息啦(你能连接服务器,当然也就知道这些信息)。
scp联通的不同的主机传输文件
scp 与 cp 的区别是,cp 用于在 linux 本机下拷贝文件到其他路径。scp 的原理其实是使用 ssh 协议登陆到 linux 服务器,然后传输文件。ssh 协议可以使用用户名和密码登陆Linux,也可以使用用户名和密钥来登陆。
以下的 user,host,port,xx.pem都需要代入具体的值
sshuser@host-pport(需要输入密码)sshuser@host-pport-ixx.pem (使用密钥进行认证)# 使用 scp 拷贝文件时使用的命令与 ssh 是类似的。scp-Pport user@host:/tmp/xiyou.txt.(将远程主机的 /tmp/xiyou.txt 文件拷贝到本机的当前工作目录,这里"."表示当前目录,需要输入密码)scp-r-Pport user@host:/tmp/.(复制远程主机上的目录到本机的当前工作目录)scp-ixx.pem-Pport user@host:/tmp/xiyou.txt.(使用秘钥 xx.pem 的方式认证,不需要输入密码,秘钥需要提前生成)# 将本地的文件拷贝到远程主机上:scp-Pport user@host:/tmp xiyou.txtwget用于从网络中下载文件
# 下载链接中的图片 https://mirrors.tuna.tsinghua.edu.cn/static/img/logo-small-dark.png 并存储为 tuna.pngwget-Otuna.png"https://mirrors.tuna.tsinghua.edu.cn/static/img/logo-small-dark.png"ls-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.pngmwget
mwget 是 wget 的升级版,支持多线程,下载速度更快。安装方式如下:
# 安装编译依赖sudoaptupdatesudoaptinstallbuild-essential-ysudoaptupgrade intltool-ysudoaptinstalllibssl-dev-y# 编译gitclone https://github.com/rayylee/mwget.gitcdmwget ./configuresudomake&&sudomakeinstall# 查看使用方法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-e'ssh -p 2234'source/ user@remote_host:/destination