Link Search Menu Expand Document

Table of contents

  1. 檔案查詢
    1. ls查詢
    2. 尋找檔案
  2. 裁剪工具
    1. cut
    2. awkk
  3. 執行程式
    1. sub
    2. mpirun
    3. nohup/disown/tmux
    4. psg

此處介紹常用的unix指令、串連之內容別名、以簡化查詢過程。

檔案查詢

ls查詢

aliasusagefull commandarguments
lstlist and sort by time察看最新檔案ls $1 --time-style=long-iso --show-control-chars -hF --color=tty -lrt\|tail目錄、檔案群組(需double quotes)
lsSlist and sort by size察看最大檔案-自小到大ls $1 --show-control-chars -hF --color=tty -lrS\|tail目錄、檔案群組(需double quotes)
lSlist and sort by size察看最大檔案-自大至小ls -alhS --color|head無引數
lsdlist the directories察看目錄ls $1 --show-control-chars -hF --color=tty -l|grep "^d"目錄、檔案群組(需double quotes)
lsrrecursive list跨越目錄察看尋找結果ls --show-control-chars -hF --color=tty -ltd $(findc $1)檔案群組(需double quotes)
lsflist the finded results察看尋找結果/按時間排序ls -lrt $(find . -name "$1")檔案群組,不需double quotes
lsklist with certain library/usr/local/glibc-2.16/lib/ld-linux-x86-64.so.2 --library-path .:/lib64 /bin/ls無引數

尋找檔案

  • locate、find見程式前沿
  • findc(find current directory)=find . -name "$1"
  • lsr、lsf

裁剪工具

cut

  • 此處介紹cut的範例
loc=$(echo $PWD|cut -d'/' -f2)
bdate=`echo $(ls -rt COMBINE_ACONC*${GRID}_${CASE}.nc|head -n1)|cut -d'_' -f7`
/usr/bin/sensors |grep Core |awk '{print $3}'|cut -c 2-5
echo 'maps.google.com' | rev | cut -d'.' -f 1 | rev #result=com
  • cshell
mm5_to_grads.csh:set date = `READV3 $1 |head -n1|cut -c '3-4 6-7 9-10' `
  • 裁減特定長度,由程式自行計算長度>任何變數
myvar="some string";echo ${#myvar}  #->11
i=asdfa.nc
l=$(echo ${#i}); m=$(( $l - 3 ));j=$(echo $i|cut -c 1-$m);echo $j;#->asdfa
  • 計算字串的長度,再決定要裁剪那裡。>一行指令搞定:
kuang@node03 /nas1/ecmwf/reanalysis/gribs18
y=$(n=$(( ${#PWD} - 1 ));echo $PWD|cut -c${n}-)
#echo $y
#18

awkk

  • std output如有欄數,可以用awk來篩選切割,然其指令太過繁雜,awkk即為其簡化版本
  • awkk=awk '{print $'$1'}',引數為欄序,自1起算。

執行程式

sub

  • 在for迴圈內要將程式放在背景執行,須使用第三個腳本來吸收所有指令,在腳本內把所有指令放在背景執行,再跳回呼叫的腳本或console,否則for loop會突然中斷,回不到呼叫迴圈
  • 類似早期mainframe電腦的submit指令
  • sub=$1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} ${12} ${13} ${14} ${15} ${16} ${17} ${18} ${19} ${20} &

mpirun

  • 執行多工程式之管理程式
  • -np #指定核心個數,核心數不能多於模式維度之一半。
  • --use-hwthread-cpus使用硬體所能提供所有的核心數。視mpirun版本而定。
  • -machinefile指定主機與核心數。如網路速度不夠快,終會成為速度瓶頸。
  • eg
mpirun --mca pls_rsh_agent ssh -np 2 -machinefile machines.LINUX -x OMP_NUM_THREADS ./hello
$ cat /home/backup/sino4/kuang/MM5v3/MM5/Run/machines.LINUX
# Change this file to contain the machines that you want to use
# to run MPI jobs on.  The format is one host name per line, with either
#    hostname
# or
#    hostname:n
# where n is the number of processors in an SMP.  The hostname should
# be the same as the result from the command "hostname"
localhost:4
sino2:4
sino3:4

nohup/disown/tmux

psg

  • ps -ef|grep $1:引數可以是執行檔、使用者、pid號碼等等