1.踢掉便用者 skill -KILL -u user_1
2. 那麼要如何同時把結果存到檔案中,又可以顯示在螢幕上哩,這個時候就要用到tee這一個指令
$ whoami | tee whoami.file
那如果要把要顯示在螢幕上的再分析一次哩,那請用
$ whoami | tee whoami.file | 分析指令
3.重新導向
https://dotblogs.com.tw/ghoseliang/2013/05/29/105049
1. 0:Standard Input (STDIN),預設為鍵盤輸入值
2. 1:Standard Output (STDOUT),預設為終端機螢幕顯示輸出
3. 2:Standard Error (STDERR),預設為終端機螢幕顯示輸出
http://ibookmen.blogspot.tw/2010/11/unix-2.html
2>&1
要有&是因為沒有的話會被當作檔案
>&1 全部std 0,1,2轉到screen
2>&1 std 2轉到screen
1>%1 std 1轉到screen
3.印出長度
x="okok"
echo "${#x}"//4
4.看執行命令是否成功 echo $# 或$?,成功回傳0不成功為其他數字
-bash: 12abc=123: command not found #發生錯誤
$echo $?
127
5.&&和||
test -f a && echo 'exist' || echo 'no exist' 沒檔案回傳no exist
6. unary operator expected
不要寫成[ $xxx == xxx]
因為$xxx如果為空會出錯
要寫成[[ $xxx == xxxx]]
7.case 寫法
case $xx in
0( echo 'ya' ;; 要注意要有兩個;;
*( echo 'other';;
esac
8.
$ sudo netstat -tuap
# -t 和 -u 選項表示要顯示 tcp 和 udp 通訊協定
# -a 選項表示要顯示所有內容
# -p 選項表示要顯示 PID
Read more: http://www.arthurtoday.com/2015/06/ubuntu-netstat-lists-all-ports-used-by-processes.html#ixzz5Ammh1BY4