- 課本: Introduction to Linux
- complexity v.s. simplicity (figure from "Starting Forth")
- 我以前作的 上課講義
- 課本 第二章 概述
- 課本 第三章指令簡表
- summary of shell programming
- demo sh script
- demo awk scripts
- 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)
- note of tar and gzip
- vi 的參考資料
- 作業一: finding files
從 /var/tmp/exercise-one 目錄底下找出自己的檔案,
並在 ~/unix-1021/exer1 下建立一檔案, 名為 "myfiles", 內容為找到的檔名.
一行一個, 共有四個.
如為 /var/tmp/exercise-one/Sam/likes/a-duck
則只需輸入 Sam/likes/a-duck 即可. 注意大小寫.
編輯器可用 joe or vi
deadline: 2013 Oct 1, 00:05 am
- 作業二: cloning files and directories
從 /var/tmp/exercise-two 目錄底下找出自己的目錄及檔案,
並複製到 ~/unix-1021/exer2 下. 如果有以下目錄及檔案
/var/tmp/exercise-two/Alice/likes/an-ox
/var/tmp/exercise-two/Emily/has-bought/a-horse
/var/tmp/exercise-two/Gary/has-bought/a-rhino
/var/tmp/exercise-two/Gary/has-bought/a-rhino/it
/var/tmp/exercise-two/Gary/has-bought/a-rhino/is
/var/tmp/exercise-two/Gary/has-bought/a-rhino/fun
/var/tmp/exercise-two/Mary/is/a-snake
則在你的 exer2 下建立如下對應的結構.
~/unix-1021/exer2
|---Alice
| `---likes
| `---an-ox
|---Emily
| `---has-bought
| `---a-horse
|---Gary
| `---has-bought
| `---a-rhino
| |---fun
| |---is
| `---it
`---Mary
`---is
`---a-snake
deadline: 2012 Oct 8, 00:05 am
- 作業三: cloning a directory
在 ~/unix-1021/exer3 建出一個目錄結構, 使其與
/var/tmp/exercise-three 一樣
也就是說除了最上層的目錄不同外, ~/unix-1021/exer3 與
/var/tmp/exercise-three 要一模一樣. (當然 owner 不可能一樣)
- 若檔名開頭為 ex-, 則新檔名為移除 ex- 後剩餘部分.
- 若為 file, 內容必須一樣.
- 若為 hard link, 則新建出的檔案間的關係也是 hard link.
- 若為 soft link, 則新建出的檔案間的關係也是 soft link, 而
且 link file 的 內容也必須一樣.
deadline: 2013 Oct 18, 00:05 am
- 作業四: at and crontab
- 用 at 在 11/08 01:00 至 03:00 間執行一個程式. 時間自選,
作一次即可.
輸出的第一行要包含當時執行的時間.
- 設定 crontab, 在一小時內執行三次程式, 時間任選, 每次 run
的程式不一定都要一樣.
第一次的輸出會新增或蓋掉既有的檔案, 第二次及第三次的輸出則
會接到前一次的後面.
每次輸出的第一行要包含當時執行的時間.
- at 及 crontab 所需的程式及輸出檔案皆放在 ~/unix-1021/exer4 下.
- 請參閱 README-exer4.
deadline: 2013 Nov 08, 00:05 am
- 作業五: practicing regular expression with sed
用 sed 寫一個程式, 從 stdin 讀進, 過濾後寫到 stdout. 過濾條件如下:
- 將 comment 刪除.
- 若 commnet 刪除後為一空行, 則刪掉這行.
- 若為一空行, 則刪掉這行.
- 若 $ 後接一串數字, 則把 $ 刪除.
- 把 $klim 換成 $milk
- 把 $milk 換成 $oak
範例如下:
=======this-is-my-prompt====== cat IN-5
# this is a comment line.
$klim owes $milk $1000 # comment here
$milk wins $oak 20000
Klim owes milk $$1000 # comment
# comment line also
milk wins $oak $20000
=======this-is-my-prompt====== ./ex5 < IN-5
$milk owes $oak 1000
$oak wins $oak 20000
Klim owes milk $1000
milk wins $oak 20000
=======this-is-my-prompt======
=======this-is-my-prompt======
程式請放至 ~/unix-1021/exer5 下.
deadline: 2013 Nov 22, 00:05 am
- 作業六: practicing 'awk'
用 awk 寫一個程式, 從 file 或 stdin 讀入, 輸出到 stdout.
- 移除 commnet. (從 # 開始, 到這行結束.)
- 若移除 comment 後為一空白行(只含 space 及 tab), 則刪除
- 每行取三段, 第一段為 column 1-10, 第二段為 column 11-20,
第三段為 column 21-30.
- 每段將前後的空白移除.
- 將這三段按原先順序印出在同一行, 每一段都佔十個 chars.
- 若處理完的段落處理完後只有數字, 則印出時靠左, 否則靠右.
- 程式請設定成可執行, 並放在 ~/unix-1021/exer6 下.
- 相關例子放在網頁及 teto 上 (var/tmp/demo-awk).
- deadline: 2013 Dec 06, 00:05 am
=======this-is-my-prompt====== cat IN-6
# OK, this is a comment.
I'm fine Hi! John 300000 # So poor!
It is funReally? just kidding
100000oxen cost 500000 Just kidding
=======this-is-my-prompt====== ./ex6.awk IN-6
I'm fine Hi! John300000
It is fun Really? just kidd
100000 oxen cost500000
=======this-is-my-prompt======
- 作業七: practicing 'awk' again
- 寫一 awk 的 script file, 將 ps -e -o user,pid 的輸出的
- 第一行砍掉
- 將同一 user 的 pid 順序印出
- 每一行最多六個 pid
- 輸出要對齊
- 可能用到的關鍵字: print, printf, split, asort, for,
associative array
- 程式請設定成可執行, 並放在 ~/unix-1021/exer7 下.
- deadline: 2013 Dec 13, 00:05 am
=======this-is-my-prompt====== ps -e -o user,pid | ./ex7.awk
s99321047: 15619 15981 18063
s101321048: 16875 18008
s101321039: 17395
s99321002: 17973
klim: 15032 18067 18068
s101321011: 13840 14143
s101321020: 13344
s101321012: 13909
s101321013: 17899
smmsp: 244 250
s101321032: 17304
s99321025: 14375 16806 17822 18012
s100321008: 17717
daemon: 180
root: 0 1 2 3 52 70
145 168 182 192 193 204
212 226 231 252 261 298
300 307 310 311 317 380
382 383 384 396 13342 13838
13907 14141 14373 15030 15617 15871
15979 16093 16804 16873 17302 17393
17715 17820 17897 17934 17971
s99321046: 15873 16095
=======this-is-my-prompt======
- 作業八: shell programming 1
- 與上一個作業作同樣的事, 但改用 sh 來作.
- 可能用到的關鍵字: printf, while, expr, test
- 程式請設定成可執行, 並放在 ~/unix-1021/exer8 下.
- deadline: 2013 Dec 27, 00:05 am
與作業七的比較如下
--prompt--- ps -e -o user,pid | ./ex7.awk
s101321039: 11564 11770
klim: 9949 11863 11864
smmsp: 244 250
daemon: 180
root: 0 1 2 3 52 70
145 168 182 192 193 204
212 226 231 252 261 298
300 307 310 311 317 380
382 383 384 396 9947 11562
17934
--prompt--- ps -e -o user,pid | sed -e '1d' | sort | ./ex8.sh
klim: 9949 11865 11866
root: 0 1 2 3 52 70
145 168 182 192 193 204
212 226 231 252 261 298
300 307 310 311 317 380
382 383 384 396 9947 11562
17934
smmsp: 244 250
daemon: 180
s101321039: 11564 11770
--prompt---
--prompt---
- 作業九: calculating the sum for someone (sh)
寫一 sh script, 計算某人(第一個參數) 的總和. 第二個參數後為多個檔名,
若無指定檔名則從 stdin 讀入. input 的格式見下列例子.
-=-prompt-=-> cat Week-1
# this is a comment
klim 120 100 900
milk 98 33 100 120
moo 10000 200 20 # this is a comment too.
cow 2000 10 100000
-=-prompt-=-> cat Week-2
moo 20 100 20 1
cow 299 44 22
cow 333 22 90
klim 49 22
moo 333
-=-prompt-=-> ./ex8.sh moo Week-1
moo has total 10220 dollars.
-=-prompt-=-> ./ex8.sh moo Week-1 Week-2
moo has total 10694 dollars.
-=-prompt-=-> ./ex8.sh moo
moo 1000
cow 200
moo 20 40 30
moo has total 1090 dollars.
-=-prompt-=->
deadline: 2014 Jan 03, 00:05 am
作業請放至 ~/unix-1012/exer9 下.