Notebook

linux command

最近更新:2022/9/21 10:04


# vim

· 在10-30行首加4個(gè)空格:"10,30 s/^/? ? /



# awk

· 指定條件匹配某數(shù)組的第1列:awk -F'\t' '{if($1==123) print $0}' data.txt

· 用某文件中的內(nèi)容匹配某數(shù)組的第1列,輸出第8列:awk -F '\t' 'BEGIN{while(getline<"userid.txt") a[$1]=1;} {if(a[$1]==1) print $8;}' data.txt

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?(臨時(shí)建立了一個(gè)字典,key是userid.txt中的第1列,values賦值為1;然后用data.txt的第1列做key去看其value是否為1)



# ssh

·?ssh配置文件:vim ~/.ssh/config

·?免密ssh:

? ? ? ? 生成本地公匙文件 ssh-keygen -t rsa

? ? ? ? 添加新服務(wù)器密碼?ssh-copy-id name? ? (name是你之前在config里給這個(gè)服務(wù)器域名取的短名)

Reference: 使用Linux,從正確配置ssh開始 - 知乎

·?sshfs將本地Linux文件夾與服務(wù)器文件夾掛載,可以實(shí)現(xiàn)不scp查看服務(wù)器圖片等文件:

? ? ? ? ?sudo chmod 777 localpath

? ? ? ? ?sshfs username@ip:path localpath

? ? ? ? ?如要取消掛載:umount localpath -o nonempty

Reference: SSHFS使用指南_eatlemon的博客-CSDN博客_sshfs

· ssh斷點(diǎn)續(xù)傳:

rsync + ssh 替代scp 傳送數(shù)據(jù)和斷點(diǎn)續(xù)傳_胡二妞的博客-CSDN博客_ssh斷點(diǎn)續(xù)傳



# conda / pip

· 如果安裝包時(shí)說(shuō)沒有權(quán)限,就將anaconda路徑chmod -R 777,注意-R必需,為更新所有子文件的權(quán)限

· pip時(shí)出現(xiàn)SOCK相關(guān)問(wèn)題-代理問(wèn)題,就unset ALL_PROXY && unset all_proxy

Pip install 報(bào)錯(cuò) Failed to establish a new connection: [Errno 111] Connection refused_HUGOkungggg的博客-CSDN博客



# CPU

·?哪些計(jì)算節(jié)點(diǎn)空閑:pbsnodes -l free

· 切換節(jié)點(diǎn):ssh cu01/cu02/...

· 修改密碼:passwd



# GPU

·?查看CUDA版本:nvcc -V

· 用pip安裝某python包的時(shí)候出現(xiàn)*Defaulting to user installation because normal site-packages is not writeable*,可以把pip install xxx改成python -m pip install xxx ;另外如果在Collecting時(shí)出現(xiàn)WARNING:Retrying,可以嘗試換個(gè)源。臨時(shí)換源:python3 -m pip install xxx -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

· 用GPU跑ML的時(shí)候出warning說(shuō)

NVIDIA A100-PCIE-40GB with CUDA capability sm_80 is not compatible with the current PyTorch installation. The current PyTorch install supports CUDA capabilities sm_37 sm_50 sm_60 sm_70. If you want to use the NVIDIA A100-PCIE-40GB GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/

那就說(shuō)明pytorch的版本和CUDA的版本不對(duì)應(yīng),一般可能pytorch要往回一兩個(gè)版本才能正常跑。

pip3 install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0-f https://download.pytorch.org/whl/torch_stable.html



# compress and reverse

·?tar -czvf test.tar.gz test

·?tar -xzvf test.tar.gz



# Linux terminal command

·?查看當(dāng)前路徑總文件(夾)個(gè)數(shù):ls | wc -l

·?文件個(gè)數(shù):ls -l |grep "^-" | wc -l

·?文件夾個(gè)數(shù):ls -l | grep "^d" | wc -l

·?當(dāng)前路徑下的空文件夾:find $path -type d -empty

·?刪除空文件夾:find $path -type d -empty | xargs rm -r

· 出現(xiàn) “Argument list too long”:將原來(lái)的命令改為找到一個(gè)操作一個(gè)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 如 rm -rf * 改為 find . -name 'temp*' | xargs rm -rf 'temp*'

·?查看后臺(tái)進(jìn)程:ps -aux | grep husir

·?磁盤空間及占用空間:df -h? ? ? ? ? ?某個(gè)目錄下統(tǒng)計(jì)占用空間:du -sh .

·?給長(zhǎng)路徑取別名:A. ~/.bashrc中添加alias myFold="cd /storage/lab/husir/"

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?即可在終端中直接用myFold進(jìn)入該目錄

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?B. ~/.bashrc中添加shopt -s cdable_vars

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? export myFold=/storage/lab/husir/

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 即可在終端中用cd myFold進(jìn)入該目錄

? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ?(重啟terminal/source .bashrc后生效)

·?用.yml安裝conda環(huán)境:conda env create -f XXX.yml

·?從絕對(duì)路徑中提取出最后一項(xiàng)文件名:long_path=/home/husir/Desktop/xxxx.dat

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? file=`echo $long_path | awk -F "/" '{print $NF}'`

Reference: Linux shell中提取文件名和路徑 - 魯娜的博客 | Luna's Blog

· 將某路徑下批量文件改名:

刪除文件名中的某字符串如filtered:for i in $(ls ./*.filtered*); do(mv ${i} `echo ${i%.filtered*}.jpg`); done

· 只scp某ls中的文件/文件夾到服務(wù)器中:

awk '{printf "scp -r PATH/%s cpu:PATH\n",$1}' ls | sh

· 雙屏之后之前deepin-wine的wechat不知怎么用不了了,圖標(biāo)點(diǎn)擊后打不開,試了一下docker安裝wechat?docker安裝微信

筆記本登微信擠掉這邊的微信之后,要么就一直留著登陸界面在桌面上,要么就sudo docker stop wechat; sudo docker start wechat就可以重開這個(gè)container


python

·?正則表達(dá)式:找到[]圈住的那一段字符串 re.findall("\[.*?\]")

· 數(shù)組 (array) 按第一列排正序:data = data[np.argsort(data[:,0])]

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?逆序:data = data[np.argsort(data[:,0], reverse=True)]

? 列表 (list) 按第i列排正序:ls = sorted(ls, key=lambda x: x[i])

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?逆序:ls=sorted(ls, key=lambda x: x[i], reverse=True)

· ax.set_xscale('log')

· 對(duì)數(shù)據(jù)點(diǎn)進(jìn)行平滑:data_smooth = savgol_filter(data, 11, 3)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 其中第二個(gè)數(shù)是平滑窗口(須為正奇數(shù)),第三個(gè)數(shù)是多項(xiàng)式擬合階數(shù)

具體可參考:python 數(shù)據(jù)、曲線平滑處理——方法總結(jié)(Savitzky-Golay 濾波器、make_interp_spline插值法和convolve滑動(dòng)平均濾波)_Yale曼陀羅的博客-CSDN博客_make_interp_spline

· pandas dataframe讀入數(shù)據(jù)文件:pd.read_csv(filename, skiprows=?, sep='\s+', usecols=[0,1,???], names=['?','?','?'])

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?sep='\s+'是一個(gè)或多個(gè)空格

· 進(jìn)度條:from tqdm import tqdm

? ? ? ? ? ? ? ? ? ?for i in tqdm(range(100)):

? ? ? ? ? ? ? ? ? ? ? ? ? ?xxx

· 列表排序:def take(ls): return ls[1]

? ? ? ? ? ? ? ? ? ? ? ls.sort(key=take, reverse=False) (升序)

· 設(shè)置橫坐標(biāo)/縱坐標(biāo)間隔:from matplotlib.pyplot import MultipleLocator

? ??????????????????????????????????????????????x_major_locator=MultipleLocator(1)

? ??????????????????????????????????????????????ax.xaxis.set_major_locator(x_major_locator)

· excel篩選某列的值在某列表內(nèi):info = info[info['cluster'].isin([1,2,3])]

· multiprocessing的starmap_async, apply_map啥的是默認(rèn)不返回運(yùn)行錯(cuò)誤的,經(jīng)常出現(xiàn)實(shí)際卡在那里但表面風(fēng)平浪靜的假象,為該并行加上錯(cuò)誤返回:

具體可參考:python multiprocessing 高級(jí)用法(打印報(bào)錯(cuò)解決Pool線程不運(yùn)行)_Ricky_Yan的博客-CSDN博客_multiprocessing 打印線程號(hào)

后來(lái)發(fā)現(xiàn)好像沒屁用

· pandas用來(lái)創(chuàng)建等差時(shí)間序列:

pd.date_range(start=datetime.datetime(2019,12,6,0,0),end=datetime.datetime(2020,1,2,23,0), freq='H')

datetime計(jì)算時(shí)間加減;

+datetime.timedelta(days=1)



Obspy

· 讀入多個(gè)sac,但又不是*:st = read('[NEZ].sac')則可以讀入N.sac,E.sac以及Z.sac

· plot beachball:

from obspy.imaging.mopad_wrapper import beachball

mt = [-0.5, 1, 0.5, 0, 0, 0]? # CLVD moment tensor (Mrr, Mtt, Mpp, Mrt, Mrp, Mtp)

beachball(mt, size=200)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容