第零章、為何要學作業系統

Similar documents
投影片 1

了 立 連 立 量 領 來 例 蘭 便 不 數 不 論 更 更 更 力 更 參 例 來 例 見 量 度 量 量 參 論 量 行 量 量 瑩 理 來 錄 量 量 不 力 省 力 立 力 量 量 量 了 量 便 錄 錄 錄 料 說 省 6

untitled

個人教室 / 網路硬碟

untitled

untitled

I/O Files讀寫檔案:

untitled

臺灣地區的警察教育現況與展望

untitled

untitled

專 題 論 述

untitled

untitled

untitled

untitled

untitled

第五章 實例個案

untitled

中華人民共和國殘疾人保障法(2008年修訂)

untitled

untitled

untitled

untitled

電腦組裝訓練

1

地方公共服務績效比較評量之探討—標竿學習策略的觀點

untitled

龍華科技大學

九十三年第三期檔案管理工作研習營學員建議事項答覆情形彙整表

公立學校教職員成績考核辦法修正草案總說明

大陸黨報集團化發展之研究

性別主流化簡介

第五章 鄉鎮圖書館閱讀推廣活動之分析

依據教育部八十九年 月 日臺(八九)技(二)字第 號函

自由軟體社群發展經驗與 Linux認證介紹

untitled

untitled

untitled

untitled

untitled

人身保險業務員資格測驗方案

untitled

國立政治大學新研所碩士在職專班

untitled

untitled

正確的姿勢 — 疾病疼痛不上身

untitled

untitled

untitled

untitled

untitled

見 例 年 例 利 不 料 林 不 立 理 不 念 類 理 利 了 路 來 行 來 行 立 見不 立 亂 不 理 立 來 2

個人提供土地與建設公司合建分屋並出售合建分得之房屋,核屬營業稅法規定應課徵營業稅之範圍,自本函發布日起,經建築主管機關核發建造執照之合建分屋案件,附符合說明二之規定者外,均應辦理營業登記,課徵營業稅及營利事業所得稅

untitled

untitled

untitled

untitled

廉 樂 不 廉 倫 理 廉 倫 理 領 不 參 領 不 若 不 不 不 不 利 聯 行 李 聯 例 律

十四、特殊需求的嬰兒

說 列 流 不 不 理 料 理 路 數 錄 路 料 料 錄 路 列 來 料 便 利 行 狀 路 II

untitled

國立中山大學學位論文典藏.PDF

1-2岁宝宝的游戏和活动指南

untitled

untitled

untitled

untitled

4-04 論文封面(樣式)

untitled

untitled

廢證相關作業

Catalan Numbers簡介

台南縣全民學區數位學習課程進階班—PhotoImpact 10

untitled

untitled

untitled

untitled

移民資料

untitled

untitled

untitled

untitled

untitled

untitled

「UPENN牙醫學院見習及費城文藝之旅」成果報告書

微處理機實習期末專題

untitled

untitled

untitled

untitled

第一場

untitled

倫 廊 倫 廊 裡 不 路 樓 落 葉 不 來 說 裡 不 了 省 裡 都 理 裡 不 了 裡 樓 來 亮 羅 更 讀 落 葉 不 樓 來 亂 不 滑 易 733 5

untitled

國立故宮博物院九十三年提升服務品質績效報告

國立台灣大學法律學院院史(1928~2000):台大法學教育的回顧〔初稿〕

untitled

untitled


Transcription:

Bash Shell script VBird 2008/03/11 1

什 Shell Shell 2008/03/11 2

什 Shell Shell Linux shell /etc/shells chsh l 行 shell program 不 shell shell Linux Solaris bash csh 2008/03/11 3

Bash bash *? [0-9] 0~ [^abc] 不 man grep \[: [:upper:], [:lower:] 略 2008/03/11 4

Bash [tab] 令 歷 令 (history)!!( )!vi( vi 令 )!5( 行 5 令 )!?abc( 行 令 abc 令 )!-5( 5 令 令 ) 2008/03/11 5

Bash 行 令 ll /lib/modules/`uname r`/kernel echo This system s name is $(hostname) 2008/03/11 6

Bash { } touch file{1,3,5} ll 2008/03/11 7

Bash 數 數 類 數 set 數 export, env 數 力 bash HOME LANG PS1 work= /home/user/mywork/myproject cd $work 2008/03/11 8

Bash 令 令 alias alias newcmd= oldcmd option newcmd 2008/03/11 9

Bash /etc/profile ~/.bashrc 立 source ~/.bashrc. ~/.bashrc 不 2008/03/11 10

Bash 令 行 令 行 / 路 行 令 alias 立 bash 令 PATH 令 2008/03/11 11

Shell script 什 shell script 令 行 shell (if, then ) r r+x 行 2008/03/11 12

Shell script shell script 令 行 理 行 (troubleshooting) 立 ( logfile.sh ) 2008/03/11 13

Shell script 立 行 shell 例 #!/bin/bash 行 說 數來 理 料 # 來說 2008/03/11 14

Shell script 行 /root/script1.sh r x cd /root;./script1.sh r x sh /root/script1.sh r script1.sh $PATH r x 2008/03/11 15

Shell script shell script #!/bin/bash # This script displays some information about your system # write by VBird 2007/11/17 echo Hello world! echo The day is $(date) echo Your working directory is: $(pwd) exit 0 2008/03/11 16

練 錄 ( 立 ) 了 bash 更 來 類 錄 錄 (subdirectories) /tmp/archive 錄 2008/03/11 17

練 (terminal, 不論 ) 錄 什 令 立 chapter3 錄 錄 立 量 { } 行 (, ) 令 什 touch {report,memo,graph}_{sep,oct,nov,dev}_{a,b,c}_{1,2,3} 2008/03/11 18

練 錄 料 來 ll 令來 立 ( 108 ) [shift]+[page up] ll more 來 ll less 2008/03/11 19

練 立 類 錄 立 錄 a_reports september october november december a_reports 立 錄 one two three 錄 ll a_reports 2008/03/11 20

練 類 chapter3 錄 來 dec (12 ) b dec_b_ december 錄 december 錄 nov_b_, oct_b_, sep_b_ 錄 2008/03/11 21

練 類 錄 來 _a_ 行 類 類 *_a_1 a_reports/one 料不 了 a_reports/one sep 2008/03/11 22

練 錄 _a_2 _a_3 reports/two reports/three 兩 錄 chapter3 錄 錄 _c_ 立 /tmp/archive 錄 錄 report 數 1 2 /tmp/arvhive 行 令 2008/03/11 23

練 chapter3 錄 c 兩 令 不 ls *c* ls -Fd *c* c 1 2 3 ( ) 錄 2008/03/11 24

練 料 script 更 料 shell script 立 shell script 來 行 2008/03/11 25

練 料 script root 行 易 令 cp -av /etc/sysconfig ~/backups/sysconfig-20080321 立 script 若 20080321 不 立 date 令 串 Linux PATH 錄 ~/bin 行 令 錄 立 錄 行 錄 (a) PATH 數 (b) 立 ~/bin 錄 2008/03/11 26

練 料 script 立 backup-sysconfig.sh ~/bin #!/bin/bash # This script creates a backup of /etc/sysconfig # into a datestamped subdirectory of ~/backups/ cp -av /etc/sysconfig ~/backups/sysconfig-$(date +%Y%m%d ) echo Backup of /etc/sysconfig completed at: $(date) 2008/03/11 27

練 料 script script 行 錄 ~/backups/sysconfig-$(date +%Y%m%d ) script 行 力 行 script bash -x /root/bin/backup-sysconfig.sh 2008/03/11 28

料流 料流 令 行 料 令 行 料 Linux 0 料 不 bash 數 echo $? 來 2008/03/11 29

料流 料流 易 2008/03/11 30

料流 / (standard input, STDIN, 0) (standard output, STDOUT, 1) 料 (standard error output, STDERR, 2) 2008/03/11 31

料流 什 料 STDOUT >( ) >>( 累 ) STDERR 2>( ) 2>>( 累 ) &> command > something 2>&1 2008/03/11 32

料流 /dev/null /dev/lp0 /dev/usb/lp0 2008/03/11 33

料流 行 列 令 / 狀 find /etc -name passwd find /etc -name passwd > find.out find /etc -name passwd 2> /dev/null find /etc -name passwd > find.out 2> /dev/null find /etc -name passwd &> find.out2 find /etc -name passwd > find.out2 2>&1 2008/03/11 34

料流 STDIN mail -s [@ ] mail ( 離 exit? 了 ) mail -s [@ ] < somefile 2008/03/11 35

料流 利 << 來 理 cat > somefile << eof 2008/03/11 36

料流 料流 來 行 不 例行 令 例 /etc/crontab 行 來 行 令 2> /dev/null 2008/03/11 37

令 什 令 令 STDOUT 令 STDIN (STDERR ) 2008/03/11 38

令 令 令 令 行 grep, more, less 不 例 date, ls 例 tr ll 料 ll ll tr a-z A-Z 2008/03/11 39

令 見 令 ls -l /etc less echo test mail mail s testing root@localhost echo test printer lpr 2008/03/11 40

令 令 STDOUT 理 利 () 令 STDOUT 例 (cal 2007; cal 2008) less cal 2007; cal 2008 less 2008/03/11 41

令 tee 利 tee 來 行 流 累 tee a 理 2008/03/11 42

令 例 ls lr /etc less ls lr /etc sort less ls lr /etc sort uniq -c less ls lr /etc sort uniq -c sort -r less 2008/03/11 43

令 STDIN 令 tr A-Z a-z <.bash_profile cat.bash_profile tr A-Z a-z 2008/03/11 44

令 令 行 && ; (;) 令 立 令 行 立 行 令 ls /vbird; ls /tmp (&&) 令 行 (0) 令 行 ls /vbird && ls /tmp ( ) 令 行 ( 不 0) 令 行 ls /vbird ls /tmp 2008/03/11 45

令 令 利 test [ ] 來 理 test -f /vbird ; echo $? [ -f /vbird ] ; echo $? 2008/03/11 46

練 /proc/cpuinfo /proc/meminfo 來 兩 來 利 less 令來 料 mail 來 令 mail mutt 來 2008/03/11 47

練 (date) 料 錄 cpumem.info date > cpumem.info cat /proc/cpuinfo /proc/meminfo > cpumem.info 不 cpumem.info root 利 來 利 令 利 STDIN 2008/03/11 48

練 利 ( ) tee mail date; cat /proc/cpuinfo /proc/meminfo 行 (cpumem.info) root 令 ( ) 2008/03/11 49

練 1. 2. 利 cut 欄 ( : ) 3. 令 列 uid gid 例 列 student uid gid 行 4. 令 列 ( 列 ) 利 for.. do.. done script 立 /root/bin/showid.sh uid/gid 列 來 5. /root/myuid.gid.txt (hint 利 tee) 2008/03/11 50

令 讀 令 令 more less 利 見 [Space] [/] [n/n] [q] cat 參數 列 ~ 行 來 列 行 列 行 不 列 行 若 連 行 行 來 列 不 來 2008/03/11 51

令 讀 令 令 tac cat 行 理 nl cat s 類 head 讀 數行 讀 行 若 行 n 行數 tail 讀 數行 讀 行 連 f tail -f /var/log/messages ( [ctrl]-c ) reset 若 理不 令 復 2008/03/11 52

令 行 理 令 grep [-vnclriba] 串 數 略 不 便 行 串 行 量 列 例 ` 了 行 列 行 了 行 列 行 2008/03/11 53

令 行 理 令 cut [ ] filename cut -d' ' -f fields cut -c awk {print $n} filename 列 串 n 欄 ( ) 2008/03/11 54

令 行 理 令 練 /etc/passwd ssh 行 練 3 行 2008/03/11 55

令 令 wc 落 令 見 [-lcw] sort 行 見 sort [- fbmnrtuk] [file or stdin] 略 異 例 略 來 例 數 行 來 料 行 來 行 2008/03/11 56

令 令 uniq 令 sort 行 [-c] 練 last cut, sort, uniq 令 數 2008/03/11 57

令 ( 行 行 ) 立 (patch file) diff -u oldfile newfile > patch_file patch -b oldfile patchfile 2008/03/11 58

令 令 aspell check letter.txt 列 aspell list < letter.txt look 料 look somefile 2008/03/11 59

令 理 tr sed 理 行更 理 sed filename 20,50p s/old/new/g 1,50s/old/new/g 2008/03/11 60

令 ( ) 利 ( ) 來 ^ $ [a-b] [^a-b] *..* 行 行 行 行 0 ~ 0~ 2008/03/11 61

練 1. 令 aspell (hint, -- help) 列 2. /usr/bin 令 數 ( 若 行 理 ) 若連 錄 3. /usr/share/doc/html/index.html 裡 4. 5. /etc/passwd g 行 列 來 2008/03/11 62

練 6. 列 /etc/passwd 行 了 7. /etc/passwd 欄 列 8. /etc/passwd 欄 shell 列 bash shell 行 9. 列 bash 行 10. /etc/ root 列 來 ( ) 11. root 什 shell ( /etc/passwd 欄 ) 2008/03/11 63

練 六 理 (/etc/issue) 來 理 2008/03/11 64

練 六 1. student /etc/issue 錄 2. 利 vim issue 類 Welcome to \n (\l)! Red Hat Enterprise Linux Server releases 5 Kernel \r on an \m 3. /etc/issue 錄 ~/issue 異 2008/03/11 65

練 六 4. 異 料 5. + 行 6. 切 root 利 /etc/issue 更 7. 利 diff 令 /etc/issue 8. 利 來 patch -R /etc/issue 2008/03/11 66