1. sh script.sh chmod a+x script.sh ./script.sh 2. #!/bin/sh 3. 定義變量 var = value echo $var 4. 獲得變量值的長度 length = ${#var} 5.算數操作 let, (()),[] let result = no1 + no2 let no1++ let no1-- result = $[ $no1 + 5] result =$((no1+5)) 6. /dev/null 7. 2 > &1 8. cmd < file 9.array_var = (1,2) 10. alias 11. date start = $(date + %s) end = $(date+ %s) 12.函數參數 function fnname() { } $1,$2:第一個,第二個參數 [email protected]:以清單的方式一次性列印所有參數 $*,把所有的參數連起來 $?,上一次指令的退出狀态。 $#,參數個數 13.for((i=0;i<10;i++)){ } 14. while condition do commands done 15. util [$x -eq 9]; do let x++; done 16. if condition then commands elif condition then commands else commands fi 17.比較 $var -eq 0 #判斷相等 $var -ne 0 #不等 -gt 大于 -lt 小于 -ge 大于等于 -le 小于等于 檔案系統相關 [ -e $file_var] 檔案存在 字元串北京相等 [[ $str1 = $str2]] [[ -z $str1 ]]:str1包含的是空字元串 [[ -n $str1 ]]:str1包含的是非空字元串 17. &&,|| 18.-print,-print0 19.find path -name "*.txt" -print -iname忽略大小寫 -type f普通檔案 -atime通路時間 -mtime修改時間 -amin -size 20. xargs 21. tr 替換 22. md5sum 23. mkdir mkdir -p 24.sort,uniq 25.chown chmod 26. touch 27.符号連結 ln -s target symbolic_link_name 28. mount 29.diff 30.head,tail 31.wc-檔案行數 32.tree-檔案目錄樹 33.grep 34.cut -f1 a.txt
獲得第一列 cut -f2,4 a.txt 2,4列 35.sed stream deitor 檔案替換 36.awk awk 'BEGIN{} pattern {commands} END{}' $0目前行的内容 $1第一個字段 $2第二個字段 $NF這行中最後一個字段,${NF-1}倒數第一個字段 37.wget wget ftp://... -O -O指定檔案名 -t指定重試次數 -c斷點續傳 --limit指定限速 --user --password 38.curl curl發送post請求 curl url -d "var1=x&var2=y" 39.tar tar czvf dir.tar.gz dir tar xzvf dir.tar.gz 40.ifconfig nslookup a.b.com ping fping DNS查詢 fping 一組IP位址 41 scp scp -r遞歸拷貝檔案 rz -be sz 42 ssh 43. lsof -i 列出系統中開放端口一級運作在端口上的服務的詳細資訊 netstat -an 44. du -h FILENAME df 45. who history n 46. ps 47. top 48. kill -9 pid 49. which command 50. hostname 51. crontab -l crontab -e crontab -r:删除
轉載于:https://www.cnblogs.com/akingseu/p/3463466.html