Linux コマンド集 (メモ用)
CPU information
cat /proc/cpuinfo
lscpu
sed
sed -n '1,3p' sss #display line 1:3
後方参照
sed -e 's/^a\([0-9].*\)/b\1/g' rand_string
後方参照を使うことで、
置換前の一部の文字列を、置換後にも利用できる。
以下のように、awkを使っても似たようなことができる。
awk '{if( $1 ~ "^a[1234567890].*"){v1 = substr($1,2); print "b"v1 }}' rand_string
nohup #let a job run even after your logout from a machine
nohup ls & #do not show signals of commands
nohup csh wait_exec.csh > nohup.out &
xargs
seq 1 4 | xargs -L 2 -P 4 ./a.out #parallel run -L: how many arguments, -P: how many runs
du -sh $dir
Summarize disk usage of each FILE, recursively for directories.
du -sh zzz_all/
40M zzz_all/
tr
tr '\n' ' ' < hoge.txt # replace newline with three spaces
tr -d '\n' < hoge.txt # delete newlines
expand # replace tab with some spaces
expand -t 3 hoge.txt # replace tab with three spaces
gthumb
gthumb image.png #show png or jpeg image on x11 window
yes
yes 0.000 | head -900 > file.dat #out 0.000, 900 times
sed # replace
sed "s/nodes=qm../nodes=qm"$qq"/g" ${dir}/md/md${next_mdn}/no${jj}/bbb > ${dir}/md/md${ne
xt_mdn}/no${jj}/qfile_md0.csh # can use 正規表現
sed -i.bak -e "s;pre;post;" file # leave backup
SEARCH FILE OR DIRECTORY
find ~ -name "termi"
ctrl + r # search command I used. press again to go back
STATE
env # 環境変数の表示
which mipf90 # show version of mpif90
uname -rao | cat /etc/*release # show what OS, also try "cat /etc/*version"
FILE TRANSPORT
tar -cvf outfilename.tar infilename1 infilename2 # file compression
tar -xvf filename.tar # file decompression
scp ~/test.txt hnishi@194.148.32.6:hnishi/test/ # ssh cp
ubuntu
dpkg -l | grep hamachi # show installed applications and grep
KILL PROCESS
pkill -f psygene # delete all process matching psygene
pgrep -f psygene -l # ps aux | grep psygene | grep -v ‘grep’ # -l option is used to show command name
awk
cat 4MA3Fv.pdb | grep ATOM | awk '{print $6}' | uniq | wc # combination
awk '{printf("%10.3f, %5d \n",$2,$1)}' file.dat #formatting
awk '{$1="";print $0}' file.dat #do not show column 1
screen
screen -rx (id) # enter Attached screen
at
at -f ../../do_grep_potential.csh 19:55 # 時間のスケジュール
sed
sed -e '1,2d' potential.dat # 指定行(1 - 2行の削除)
奇数行のみを出力
sed -n -e 1~2p
1行目、6行目、11行目、16行目、、、を出力
sed -n -e 1~5p
paste
paste file1 file2 # カラムを結合する
nl
nl -nln file1 # 行頭全てにナンバリングする
grep
grep "ATOM ¥| HETATM ¥| REMARK" filename # “ “ or “ “ or “ “
find hnishi/ -name "*.tar*" | xargs du -sh | grep "M\|G" | awk '{print "rm",$2}'> zzz.sh
grep -i error <file name>
-iオプションは大文字と小文字の区別をなくす
-E
オプションで、拡張正規表現を使うことができる。
したがって、-e
よりも-E
を使う癖をつけた方が良い。
last
last # ログイン履歴の確認
w # ログインしているユーザの表示
SEE WHAT IP-ADRESS THIS COMPUTER HAS
ifconfig
xargs
ls no*/md.out | xargs tail # lsの結果を全部、tailの引数に渡す
ls no*/md.out | xargs -L 1 tail # lsの結果を一つずつ、tailに渡して表示する
find ./path/to/file -type f | xargs sed -i "s/hoge/hage/g" # g option means all are replaced
find ./path/to/file -type f -print | xargs grep 'hoge' # grep
論理演算子
mkdir zzz || (rm -r zzz && echo "remove zzz")
sort
sort #sort by character
sort -n # sort by number
sort -k 1.4 # sort by the fourth character of column 1
cat c1_c2_str.dat | sort -k1,1n -k2,2n | less # sort by column 1 by number and by column 2 moreover
sort -k1.7,1.8n file.txt #sort by num of column 1 and 7th character to 8 th
ldd /work1/hnishi/programs/pymol/pymol.exe
実行ファイルの参照するライブラリのpathを表示する
/sbin/ldconfig -p | grep libGL.so.1
インストールされているライブラリの中からgrepで探す
メモ
for i in {93..113}; do echo " ${i} ";done > _grep.dat
grep "CA" out.pdb |grep "H "|grep -f _grep.dat |cut -c 32-55 > coord.dat
ファイルから読み込まなくても
for i in {93..113}; do grep " $i " out.pdb| grep "H "|grep CA;done|less
でonelineにできる。
この場合、forで回して1行ずつ取り出していく。