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