170 likes | 325 Views
UNIX 進階使用. 台灣大學計算機及資訊網路中心 教學研究組 張傑生 jsc@ccms.ntu.edu.tw. 線上查詢相關指令說明. man <command(s)> 線上查詢各個指令的說明 man -k <keyword> 線上查詢所有與 < keyword> 相關之指令 RTFM 發問前,請先做好功課!. 線上查詢相關指令位址. which <command(s)> 由 shell 設定的 path 中,找尋 < command(s)> 所存放的目錄 whereis <commands(s)>
E N D
UNIX 進階使用 台灣大學計算機及資訊網路中心 教學研究組 張傑生 jsc@ccms.ntu.edu.tw
線上查詢相關指令說明 • man <command(s)> • 線上查詢各個指令的說明 • man -k <keyword> • 線上查詢所有與 <keyword> 相關之指令 • RTFM • 發問前,請先做好功課!
線上查詢相關指令位址 • which <command(s)> • 由shell 設定的path 中,找尋 <command(s)>所存放的目錄 • whereis <commands(s)> • 由shell 設定的path 中,找尋包含 <command(s)>關鍵字之所有指令所存放的目錄
更改個人資訊 • passwd • 更改密碼 • chfn • 更改個人資訊 • chsh • 更改shell • ~/.plan • 個人計畫檔 • finger username • 觀察username 的資料
指令介紹 more/head/tail • more /etc/password • head /etc/password • tail -100 /var/log/message • tail -f /var/log/message
指令介紹 file/find • file filename • 顯示該檔案格式 • check /etc/magic • find /etc -name passwd • find /usr/bin -perm -4000 • find /usr/bin/ -perm -4000 -exec /bin/ls -al {} \; • find /tmp -mtime +3 -exec /bin/rm -f {} \;
指令介紹sort • 參數: • -n 以數字做為比對基準 • -r 反向列印 • -t 分隔符號 • +? 對某一欄位做排序 • sort /etc/passwd • sort -r /etc/passwd • sort -t: +2 -n /etc/passwd
指令介紹 grep • grep login /var/log/message • grep -i ntu.edu.tw /var/log/message • grep -v tcsh /etc/passwd • grep -e stu12 -e stu13 /etc/passwd • grep -n root /etc/passwd
輸出轉向 • command > file1 : 將command 的輸出送往 file1,file1原先的內容消失 • command >> file1 : 將command 的輸出附加在 file1 的尾端 • ls -al > /tmp/ls000 • cat /tmp/ls000
輸入轉向 • command < file1 : 將file1 的內容作為 command 的輸入 • more < /etc/passwd • sort < /etc/passwd
PIPE • cmd1 | cmd2 [|command]* • 將cmd1的輸出作為cmd2的輸入 • ls -al |more • cat /etc/passwd | sort • ps aux|grep root
前景與背景 Job • 前景 job:依前述命令迴圈執行之 job • 背景 job : 不等命令執行完畢即顯示提示符號 • 要執行很久又不會用到終端機輸出入的命令最適合在背景執行 • command & 命令解譯迴圈 顯示提示符號 shell 讀取命令 執行命令 處理命令
Jobs 觀察與控制 • 在 job 執行時按下Ctrl-Z 便會使該 job 的執行暫停 • jobs : 觀看目前所有背景 job • fg %jid : 將編號為 %jid 之job前景執行 • bg %jid : 將編號為 %jid 之job背景執行
Process 觀察 • Process:一個執行中的程式 • ps:列出 process 狀態 • BSD: • ps -a : 列出系統中所有 process • ps -u : 列出 Process 的執行者及其他資訊 • SYSTEM V: • ps -e : 列出系統中所有 process • ps -f : 列出完整資料
Process 控制 • kill PID : 不再執行編號為 PID 的 process • kill -9 PID = kill -KILL PID • 強制中斷 process(暴力法) • kill -1 PID = kill -HUP PID • 通知process 重新執行 • man -k kill • man -k signal • more /usr/include/sys/signal.h
轉變使用者身份 • su • su - root • su - username • 必須在 /etc/group 的wheel 中才可轉變身份為root
進階 permission 觀念 • Concept of setuid and setgid • chmod u+s filename • check /usr/bin/passwd • chmod g+s filename • check /usr/bin/top • Concept of sticky bit • chmod a+t directory • check /tmp