- 課本: Introduction to Linux
- complexity v.s. simplicity (figure from "Starting Forth")
- 我以前作的 上課講義
- 課本 第二章 概述
- 課本 第三章指令簡表
- summary of shell programming
- demo sh script
- demo awk scripts
- note of tar and gzip
- unix commands vs python
- 作業一: find and create
從 /var/tmp/milk /var/tmp/zoo /var/tmp/sea 三個目錄底下找出自己的檔案,
並在 ~/unix-1001/exer1 下建立一檔案, 名為 myname, 內容為找到的檔名.
編輯器可用 joe or vi
deadline: 2011 Sep 21, 00:05 am
- 作業二: cloning a directory and changing the name
先在 /var/tmp 下找出你的目錄 (與作業一類似).
再在你的 home 目錄底下的 unix-1001/exer2 建出一個相同的目錄結構
也就是說除了最上層的目錄名不同外, ~/unix-1001/exer2 與
/var/tmp 下你的目錄結構要一模一樣.
在建目錄或檔案時, 若檔名或目錄名前有 'ex-', 則建時要將 'ex-' 去除.
也就是若檔名為 'ex-grape' 則要建的檔名為 'grape'.
可能用到的命令: mkdir, touch, ls, cd, .......
deadline: 2011 Sep 28, 00:05 am
- 作業三: invoking ps with cerain options
查閱 ps 的 man page, 找出適當的參數, 使其執行時只顯示
USER,PID,PPID,COMMAND
將你的東西寫成一個 file 放在 unix-1001/exer3 下, 並用 chmod 將其設成
可執行.
deadline: 2011 Oct 19, 00:05 am
- 作業四: writing sed script
將適當的 sed 的 commands 寫成一個 script file, 例如為 ex4.sed,
如底下方式執行, 將 ps -ef 的輸出的
- 第一行砍掉
- user 為 root 的砍掉
- 其餘的只顯示前二個欄位, 中間空一格.
$ ps -ef | sed -f ex4.sed
s9832100 18776
daemon 176
smmsp 236
s9832100 18749
klim 18818
klim 18817
smmsp 12322
klim 18641
$
將 sed 的 script 放在 unix-1001/exer4 下
deadline: 2011 Nov 2 00:05 am
- 作業五: writing awk script
寫一 awk 的 script file, 例如為 ex5.awk,
如底下方式執行, 將 ps -ef 的輸出的
- 第一行砍掉
- 將同一 user 的 pid 順序印出
$ ps -ef | ./ex5.awk
klim: 27048 27141 27142
smmsp: 236 12322
daemon: 176
root: 0 1 2 3 52 62 137 160 174 184 185 196 210 215 223 248 260 262 263 292 298 301 310 316 317 319 321 324 325 326 327 341 1755 12321 27046
$
將程式放在 unix-1001/exer5 下
deadline: 2011 Nov 23 00:05am
可能用到的關鍵字: printf, split, asort, for, associative array
- 作業六: writing sh script
寫一 sh 的 script file, 例如為 ex6.sh.
其執行結果與作業五類似. 如下例所示.
$ ./ex6.sh
klim: 29747 29957 29958
root: 0 1 2 3 52 62 137 160 174 184 185 196 210 215 223 248 260 262 263 292 298 301 310 316 317 319 321 324 325 326 327 341 1755 12321 29745
smmsp: 236 12322
daemon: 176
$ ps -e -o user,pid | ./ex5.awk
klim: 29747 29962 29963
smmsp: 236 12322
daemon: 176
root: 0 1 2 3 52 62 137 160 174 184 185 196 210 215 223 248 260 262 263 292 298 301 310 316 317 319 321 324 325 326 327 341 1755 12321 29745
$
將程式放在 unix-1001/exer6 下
deadline: 2011 Dec 14 00:05am
可能用到的命令: ps, printf, echo, sort, sed
不能用 awk. (不然就直接呼叫 ex5 就好了)
- 作業七: filtering numbers (shell script)
寫一 sh 的 script file, 例如為 ex7.sh
從參數讀進 lower bound 與 upper bound,
從 stdin 讀進 numbers.
把介於 lower bound 與 upper bound 的數以六個一列印出.
如下例所示.
$ cat N
3 4 5 6 7 8 9 10
9 88 23
121
98 78 34 288
345 909
3 2 1
$ ./ex7.sh 40 50 < N
$ ./ex7.sh 4 50 < N
4 5 6 7 8 9
10 9 23 34
$ ./ex7.sh 1 10 < N
3 4 5 6 7 8
9 10 9 3 2 1
$ ./ex7.sh 11 100 < N
88 23 98 78 34
$
將程式放在 unix-1001/exer7 下
deadline: 2011 Dec 21 00:05am
- 作業八: filtering numbers (python)
與作業七相同, 但改用 python 來作.
將程式放在 unix-1001/exer8 下
deadline: 2011 Dec 28 00:05am
- GNU document for
make
make.
- GNU document for
bash
- GNU document for
sed
- GNU document for
awk
- GNU document for
GNU core utils
coreutils.pdf
(created by dvipdf from coreutils.dvi)
- python
- vi 的參考資料