01寫在前面
Linux基礎(chǔ)教程已經(jīng)收官,教程回顧可點(diǎn)擊:Linux基礎(chǔ)教程。當(dāng)然,我們后續(xù)也會推出更多的Linux與生信相關(guān)教程,大家可以點(diǎn)擊收藏方便持續(xù)關(guān)注:生信Linux及服務(wù)器使用技巧。大家如果需要算力/服務(wù)器也可以點(diǎn)擊這個系列選到自己心儀的設(shè)備:有root權(quán)限的共享服務(wù)器
生信分析不求人
為實(shí)驗(yàn)室準(zhǔn)備一份生物信息學(xué)不動產(chǎn)
本文就帶大家一起學(xué)習(xí)Linux中常見的文件傳輸命令,幫助你快速傳輸大型文件。在學(xué)習(xí)之前,準(zhǔn)備好自己服務(wù)器的IP、用戶名、端口、密碼這些信息啦(你能連接服務(wù)器,當(dāng)然也就知道這些信息)。
02scp聯(lián)通的不同的主機(jī)傳輸文件
scp 與 cp 的區(qū)別是,cp 用于在 linux 本機(jī)下拷貝文件到其他路徑。scp 的原理其實(shí)是使用 ssh 協(xié)議登陸到 linux 服務(wù)器,然后傳輸文件。ssh 協(xié)議可以使用用戶名和密碼登陸Linux,也可以使用用戶名和密鑰來登陸。
以下的 user,host,port,xx.pem都需要代入具體的值
COPYssh user@host -p port (需要輸入密碼)
ssh user@host -p port -i xx.pem (使用密鑰進(jìn)行認(rèn)證)
# 使用 scp 拷貝文件時(shí)使用的命令與 ssh 是類似的。
scp -P port user@host:/tmp/xiyou.txt . (將遠(yuǎn)程主機(jī)的 /tmp/xiyou.txt 文件拷貝到本機(jī)的當(dāng)前工作目錄,這里"."表示當(dāng)前目錄,需要輸入密碼)
scp -r -P port user@host:/tmp/ . (復(fù)制遠(yuǎn)程主機(jī)上的目錄到本機(jī)的當(dāng)前工作目錄)
scp -i xx.pem -P port user@host:/tmp/xiyou.txt . (使用秘鑰 xx.pem 的方式認(rèn)證,不需要輸入密碼,秘鑰需要提前生成)
# 將本地的文件拷貝到遠(yuǎn)程主機(jī)上:
scp -P port user@host:/tmp xiyou.txt
03wget用于從網(wǎng)絡(luò)中下載文件
# 下載鏈接中的圖片 https://mirrors.tuna.tsinghua.edu.cn/static/img/logo-small-dark.png 并存儲為 tuna.png
wget -O tuna.png "https://mirrors.tuna.tsinghua.edu.cn/static/img/logo-small-dark.png"
ls -la | grep tuna.png
# 下載一個文件,不指定文件名
wget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg
ls -la | grep gpg
# 查看 wget 其他參數(shù)的使用方法
wget --help
# -c 參數(shù)支持?jǐn)帱c(diǎn)續(xù)傳,這在傳輸大文件時(shí)十分有用
wget -c -O tuna2.png https://mirrors.tuna.tsinghua.edu.cn/static/img/logo-small-dark.png
04mwget
mwget 是 wget 的升級版,支持多線程,下載速度更快。安裝方式如下:
COPY# 安裝編譯依賴
sudo apt update
sudo apt install build-essential -y
sudo apt upgrade intltool -y
sudo apt install libssl-dev -y
# 編譯
git clone https://github.com/rayylee/mwget.git
cd mwget
./configure
sudo make && sudo make install
# 查看使用方法
mwget --help
mwget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg
05curl通常用來在終端中模擬瀏覽器訪問網(wǎng)站
curl 也可以用來下載文件,不過使用體驗(yàn)不如 wget。
COPY# 使用 curl 下載鏈接中的文件,并保存為 tuna3.png
curl -o tuna3.png https://mirrors.tuna.tsinghua.edu.cn/static/img/logo-small-dark.png
# 查看 curl 的其他用法
curl --help
06
rsync
參考鏈接:https://www.ruanyifeng.com/blog/2020/08/rsync.html
COPY# 使用 2234 端口,將本地的 source 目錄拷貝到遠(yuǎn)程機(jī)的 /destination 目錄
rsync -av -e 'ssh -p 2234' source/ user@remote_host:/destination