linux and unix shell
TRANSCRIPT
19.pdf
19 shell
s h e l l s h e l l
s h e l l
{
1
. . .
}
{
1
. . .
}
f u n c t i o n
f u n c t i o n
{ ...
}
s h e l l
s h e l l
e c h o
19.1
s h e l l
h e l l o
e c h o
19.2
h e l l o
back from the function
19.3
$ 1 , $ 2 . . . $ 9
s h e l l
_ F I L E N A M E_ f i l e n a m e
19.4
1)
2) r e t u r n 01
19 shell 203
r e t u r n
Return 0
Return 1
19.5
i f01 i f
v a r i a b l e _ n a m e = f u n c t i o n _ n a m e
f u n c t i o n _ n a m ev a r i a b l e _ n a m e
19.6 shell
s h e l l
# ! / b i n / s h
f u n c t i o n s . m a i n
s h e l l s e t
s h e l l
u n s e t s h e l l u n s e t
s h e l l
s h e l lu n s e t u n s e t
19.7
s h e l l
f u n c t i o n s . m a i n
204 s h e l l
f i n d
1 $ 0
s h e l ls h -
19.8
. / p a t h n a m e / f i l e n a m e
s h e l l
$. functions.main
file not found
$. /functions.main
s h e l l
19.9
s e t s e ts h e l l
19.10 shell
f i n d i t
19 shell 205
19.10.1 shell
s h e l l u n s e t
u n s e t
unset function_name
$ unset findit
s e t
19.10.2 shell
f u n c t i o n s . m a i n f o r
$. /functions.main
s e t s h e l l f o r
f i n d i t
206 s h e l l
19.10.3
1.
a w k
$ 1 a w k
1 _ L E T T E R S _ O N LY
i f
19 shell 207
n a m e _ e r r o r $ @
F _ N A M ES _ N A M E
w h i l e
208 s h e l l
0
2. echo
e c h o L I N U XB S DV
e c h o
e c h o r e a d
L I N U XB S De c h o- n
L I N U XB S De c h o e c h o
V\ C
e c h oL I N U X- e s h e l l
e c h o
e c h o \ 0 0 7V
\ 0 0 7L I N U X
$ @
uni_prompt "\007 there goes the bell ,What is your name:"
What is your name:
VL I N U X / B S D
V \cz
19 shell 209
uni_prompts "\007 there goes the bellWhat is your name:"
There goes the bellWhat is your name:
3.
press any key
to continued d
d d
1m y f i l e
dd if:/dev/zero of=myfile count=512 bs=2048
d d d d
d d
s t t y d dd d
210 s h e l l
4.
i f
5. YN
c a s e
19 shell 211
$ 1 YN
c o n t i n u e _ p r o m p t
212 s h e l l
$ 1
6. I D
I D
grep passwd
grep /etc/passwd
p a s s w d5
p a s s w d
I D g r e p
w h o i s
7.
v i
n ln l
19 shell 213
n u m b e r _ f i l e s h e l l
$ number_file myfile
number_file $1
8.
t r
u p p e r $ @
s t r _ t o _ u p p e r
$ 1
214 s h e l l
9. is_upper
s t r _ t o _ u p p e r
i s _ u p p e r i f
i s _ u p p e r
i s _ u p p e r a w k
i s _ l o w e r
10.
s t r _ t o _ u p p e r s t r _ t o _ l o w e r
19 shell 215
L O W E R $ @
s t r _ t o _ l o w e r
11.
2 0 5 0
c h e c k _ l e n g t h
216 s h e l l
N A M E 1 0b r e a k
w c w c
w c
a w k
w c
12. chop
c h o p
M Y D O C U M E N T. D O CM Y D U C U M E N T . D O C
c h o p
M Y D O C U M E N T . D O C 1 0
Chop
19 shell 217
C H O P P E D c h o p
13. MONTHS
m o n t h s
30 3M a r c h
218 s h e l l
m o n t h s
months 04
A p r i l
J u n e
19.10.4
s h e l l
19.11
19.11.1
19 shell 219
e r r o r _ m s g
19.11.2
f u n c t i o n s . s hs hs h e l l
220 s h e l l
f u n c t i o n s . s h
.\
s h e l l s h e l l
19 shell 221
19.12
b a c k f u n c
1_ C O D E
_ C O D Ec o m e t
222 s h e l l
19.13
19 shell 223
19 shell 19.1 19.2 19.3 19.4 19.5 19.6 shell 19.7 19.8 19.9 19.10 shell 19.10.1 shell 19.10.2 shell 19.10.3 19.10.4
19.11 19.11.1 19.11.2
19.12 19.13
02.pdf
2 findxargs
(
)
F i n d
find
f i n d
f i n dx a rg s
f i n d
( N F S )f i n d
f i n d
(3 0 G )
F i n d
find pathname -options [-print -exec -ok]
pathname find . /
-print find
-exec find s h e l l ' c o m m -
and' {} \;{ }\
-ok - e x e c s h e l l
2.1 find
f i n d -
-name
-perm
-prune f i n d - d e p t h
- p r u n e f i n d
-user
-group
-mtime -n +n - n n+ n
nF i n d - a t i m e- c t i m e - m t i m e
- m t i m e
-nogroup / e t c / g r o u p s
-nouser / e t c / p a s s w d
-newer file1 ! file2 f i l e 1 f i l e 2
-type
b -
d -
c -
p -
l -
f -
-size n[c] nc
-depth
-fstype
/ e t c / f s t a b
-mount m o u n t
-follow f i n d
-cpio c p i o
2.1.1 name
f i n d
$ H O M E * . t x t
~' p a t h n a m e~$ H O M E
$ find ~ -name "*.txt" -print
* . t x t
$ find . -name "*.txt" -print
$ find . -name "[A-Z]*" -print
/ e t ch o s t
$ find /etc -name "host*" -print
$ H O M E
$ find ~ -name "*" -print find . -print
$ find / -name "*" -print
* . t x t
a x 3 7 . t x t
2 f i n dx a rg s 15
$ find . -name "[a-z][a-z][0--9][0--9].txt" -print
2.1.2 perm
- p e r m
7 5 5
$ find . -perm 755 -print
f i n d - p e r m - - p e r m
0 0 7c h m o d
$ find . -perm -007 -print
2.1.3
- p r u n e - p r u n e
- d e p t h - p r u n e f i n d
/ a p p s / a p p s / b i n
$ find /apps -name "/apps/bin" -prune -o -print
2.1.4 usernouser
$ H O M E
d a v e
$ find ~ -user dave -print
/ e t cu u c p
$ find /etc -user uucp -print
- n o u s e r
/ e t c / p a s s w d - n o u s e r f i n d
/ h o m e
$ find /home -nouser -print
2.1.5 groupnogroup
u s e rn o u s e r f i n d
/ a p p sa c c t s
$ find /apps -group accts -print
n o g r o u p f i n d
$ fine/-nogroup-print
16 shell
2.1.6
m t i m e
m t i m e
- n + n
5$ find / -mtime -5 -print
/ v a r / a d m3
$ find /var/adm -mtime +3 -print
2.1.7
- n e w e r
newest_file_name ! oldest_file_name
f i n d a g e . a w kb e l t s . a w k
f i n d
t o u c h
2 3 : 4 0
2 1 : 4 0
f i n d - n e w e r
$ find . -newer dstamp -print
2.1.8 type
U N I XL I N U X
2 f i n dx a rg s 17
/ e t c
$ find /etc -type d -print
$ find . ! -type d -print
/ e t c
$ find /etc -type l -print
2.1.9 size
b l o c k
N c
1 M
$ find . -size +1000000c -print
/ h o m e / a p a c h e 1 0 0
$ find /home/apache -size 100c -print
1 05 1 2
$ find . -size +10 -print
2.1.10 depth
f i n d d e p t h
f i n d f i n d
f i n d C O N . F I L E
$ find / -name "CON.FILE" -depth -print
2.1.11 mount
f i n dm o u n t
X C$ find . -name "*.XC" -mount -print
2.1.12 cpio
c p i o f i n d
c p i o
c p i o / e t c/ h o m e/ a p p s
18 shell
\s h e l l \
/
/ e t c / e t c
f i n d / e t c / h o m e/ a p p s
c p i o
c p i oC 6 5 5 3 6B
5 1 2 C 6 5 5 3 6 6 4 K
6 5 5 3 6 / 1 0 2 4
2.1.13 execokshell
- e x e c
f i n d - e x e c
- e x e c l sls -l
r m l s
e x e c { } \
e x e c p r i n t f i n d
ls -l ls -l f i n d- e x e c
f i n d - e x e c ls -l
/ l o g s5
$ find logs -type f -mtime +5 -exec rm {} \;
s h e l l
m vr m - e x e c
f i n d . L O G
5
yn
- e x e c g r e p f i n d
2 f i n dx a rg s 19
p a s s w d * p a s s w dp a s s w d . o l dp a s s w d . b a k
g r e p r o u n d e r
2.1.14 find
f i n d f i n d
$ H O M E
$ find $HOME -print
$ find ~ -print
s u i d
$ find . -type f -perm 4755 -print
0
$ find / -type f -size 0 -exec ls -l {} \;
/ v a r / l o g s7
$ find /var/logs -type f -mtime +7 -exec rm {} \;
a u d i t
$find /-name -group audit -print
A d m i n . l o g
a d m i n . l o g . 0 0 1a d m i n . l o g . 0 0 2 f i n d / l o g s 7
a d m i n . l o g
9 9 9
$ find /logs -name 'admin.log[0-9][0-9][0-9]'-atime +7 -exec rm {} \;
$ find . -type d -print -local -mount |sort
r m t
$ find /dev/rmt -print
2.2 xargs
f i n d- e x e c f i n d
e x e c e x e c f i n d
x a rg s f i n d F i n d x a rg s
x a rg s - e x e c
- e x e c
20 shell
x a rg s x a rg s
x a rg sf i n d
x a rg s
(core dump)
/tmp/core.log
$ find . -name "core" -print | xargs echo "" >/tmp/core.log
/ a p p s / a u d i t
$ find /apps/audit -perm -7 -print | xargs chmod o-w
g r e p d e v i c e
$ find / -type f -print | xargs grep "device"
g r e p D B O
$ find . -name \-type f -print | xargs grep "DBO"
\ f i n d*s h e l l
2.3
f i n d e x e c
x a rg s
2 f i n dx a rg s 21
2 find xargs2.1 find 2.1.1 name 2.1.2 perm 2.1.3 2.1.4 user nouser 2.1.5 group nogroup 2.1.6 2.1.7 2.1.8 type 2.1.9 size 2.1.10 depth 2.1.11 mount 2.1.12 cpio 2.1.13 exec ok shell 2.1.14 find
2.2 xargs2.3
03.pdf
3
c r o n t a b
a t
n o h u p
cron
At at
&
Nohup
3.1 croncrontab
c r o n
c r o n t a b c r o n t a b
s h e l l
c r o n t a b
c r o n . d e n yc r o n . a l l o w c r o n t a b
3.1.1 crontab
c r o n t a b
1 15 9
2 12 30
3 13 1
4 11 2
5 060
6
c r o n t a b
< >< >< >< >< >
< >
C r o n t a b
-
1 - 5,
1 , 4 *
* 5
#
3.1.2 crontab
c r o n t a b
30 21* * * /apps/bin/cleanup.sh
2 1 : 3 0/ a p p s / b i nc l e a n u p . s h
45 4 1,10,22 * * /apps/bin/backup.sh
11 02 24 : 4 5/ a p p s / b i nb a c k u p . s h
10 1 * * 6,0 /bin/find -name "core" -exec rm {} \;
1 : 1 0 f i n d
0,30 18-23 * * * /apps/bin/dbcheck.sh
1 8 : 0 02 3 : 0 03 0 / a p p s / b i nd b c h e c k . s h
0 23 * * 6 /apps/bin/qtrend.sh
11 : 0 0 p m/ a p p s / b i nq t r e n d . s h
c r o n t a bs h e l l
c r o n
c r o n c r o n
s h e l l
c r o n
3.1.3 crontab
c r o n t a b
Crontab [-u user] -e -l -r
-u
-e c r o n t a b
-l c r o n t a b
-r c r o n t a b
- u c r o n t a b
3 23
3.1.4 crontab
c r o n c r o n t a b
E D I TO Rc r o n c r o n t a b9 9 %U N I XL I N U X
v i $ H O M E . p r o f i l e
EDITOR=vi; export EDITOR
< u s e r > c r o n< u s e r > d a v e c r o n
5
1 5
t t y 1
c r o n t a b c r o n
$ crontab davecron
c r o n1 5
/ v a r / s p o o l / c r o n
d a v e
3.1.5 crontab
c r o n t a b
$ H O M Ec r o n t a b
$ crontab -l > $HOME/mycron
c r o n t a b
3.1.6 crontab
c r o n t a bE D I TO R v i
v ic r o n t a b
$ crontab -e
v i c r o n t a b
24 shell
c r o n
c r o n t a b
c r o n t a b
crontab -l
3.1.7 crontab
c r o n t a b
$ crontab -r
3.1.8 crontab
c r o n t a b $ H O M E
/ v a r / s p o o l / c r o n / < u s e r n a m e >< u s e r n a m e >
$ crontab
< f i l e n a m e >$ H O M E
$ H O M E
c r o n t a b re
c r o n t a b
c r o n t a b c r o n t a b
c r o n t a b d e l e t e
< C t r l - D >c r o n t a b
3.2 at
a t c r o n
1 0 m i n
c r o n t a b
a t c r o n t a b
c r o n t a b / e t ca t . a l l o wa t . d e n y
3 25
a t a t c r o n t a b
a t
at [-f script] [-m -l -r] [time] [date]
-f script
-l a t q
-r I DU N I X
a t r m
-m
time at HH H . H H M MH H : M MH : MHM
a . m .p . m .
date a t t o d a yt o m o r r o w
3.2.1 at
a t a t
a t s h e l l
a t / a t
< C T R L - D >
< E O T >< C T R L - D >2 1 : 1 0 f i n d
job 1
/a t
26 shell
a t s h e l l - f
d b _ t a b l e . s h3 : 0 0
e c h oa t
$ echo find /etc -name "passwd" -print | at now +1 minute
3.2.2
at -l
/ aa t
a t q a t
/ v a r / s p o o l / a t
3.2.3
atrm [job no] at -r [job no]
at -l
at -r
at-r [job no]
3.3 &
3 27
&
&
f i n d s h e l l
command >out.file 2>&1 &
out.file
3.3.1
f i n d s r m . c o n f
f i n d . d t
2 7 0 1 5
p s 1
3.3.2 ps
p s 1p sg r e p
ps x
p s
3.3.3
k i l l s h e l l
28 shell
k i l l
kill -signal [process_number]
( )
k i l l
n o h u p
3.4 nohup
n o h u p N o h u p ( n o
hang up)
nohup command &
3.4.1 nohup
n o h u p
n o h u p . o u t
nohup command > myout.file 2>&1
m y o u t . f i l e
p s 1
s h e l l
ps xps -ef|grep ps1
3.4.2
s h e l l n o h u p
3 29
$ chmod 744 quarterend
q t r. o u t
3.5
C r o n
30 shell
3 3.1 cron crontab3.1.1 crontab 3.1.2 crontab 3.1.3 crontab 3.1.4 crontab 3.1.5 crontab 3.1.6 crontab 3.1.7 crontab 3.1.8 crontab
3.2 at 3.2.1 at 3.2.2 3.2.3
3.3 &3.3.1 3.3.2 ps 3.3.3
3.4 nohup 3.4.1 nohup 3.4.2
3.5
04.pdf
4
S h e l l
*
[...] [ ]
[!...] [ ]
s h e l l
4.1 *
* a p p *
a p p
* * . d o c . d o c
* c l * . s e d c l
. s e d
c d
4.2
R
c o n f . l o g
f ? ? * s f
s
4.3 [...][!...]
[ . . . ] [ ] -
io
l o g .
l o g . [ 0 - 9 ] *[ 0 - 9 ] *
[ ! 0 - 9 ] * !
LPS1
32 shell
L P S
$ ls [A-Z]*
$ ls [a-z]*
$ ls [0-9]*
. . p r o f i l e. r h o s t s. h i s t o r y
$ ls .*
4.4
4 33
4 4.1 *4.2 4.3 [...][!...]4.4
05.pdf
5 shell
s h e l l
s h e l l
5.1 echo
e c h o
echo string
e c h o
\c
\f
\t
\n
$ echo "The red pen ran out of ink"
e c h o
$ H O M E t t y(
)
LINUX......
- necho
()
$ echo -n "What is your name :"
-e
e c h o \ n
e c h o \
LINUX...
- e
>
m y f i l e
$ echo "The log files have all been done"> myfile
$ echo "$LOGNAME carried them out at `date`">>myfile
m y f i l e
s h e l l e c h o
\s h e l l
e c h o/ d e v / r m t 0 \$ echo "\"/dev/rmt0"\"
" / d e v / r m t 0 "
5.2 read
r e a d
5 s h e l l 35
r e a d
read varible1 varible2 ...
s h e l l
Shell
John Lemon Doe
s h e l l r e a d
LINUX......
-n
36 shell
5.3 cat
c a t
c a t
m o r ec a t
$ cat myfile | more
$ cat myfile | pg
c a t
cat [options] filename1 ... filename2 ...
c a t
-v
m y f i l e
$ cat myfile
m y f i l e 1m y f i l e 2m y f i l e 3
$ cat myfile1 myfile2 myfile3
b i g f i l e
$ cat myfile1 myfile2 myfile3 > bigfile
c a t
c a t
< C T R L - D >
c a t D O S f t p
< C T R L - M >
c a t
5 s h e l l 37
< C T R L - D >
5.4
|
1 |2
|
s h e l l
g r e pq u a r t e r 1 . d o c
5 - 1
5-1
s e da w kg r e p w h o
a w k
d f a w k
a w k a w k g r e p
f i l e s y s t e m
/ d e v /
s e d
38 shell
Is
$ sort myfile | lp
5.5 tee
t e e T
tee -a files
- a
t e e
w h o w h o . o u t
5 - 2
5-2 tee
t a p e . l o g
t e e - a
\s h e l l
e c h o
5 s h e l l 39
screen
who
$ who
who.out
$ echo "stand-by disk cleanup starting in 1 minute"| tee /dev/console
- a
5.6
s h e l l
s h e l l
0 1 2
1 2 012
39
5.6.1
0
5.6.2
1
5.6.3
2
5.7
40 shell
5 - 1
5 - 1
5-1
command > filename
command >> filename ()
command 1 > fielname
command > filename 2>&1
command 2 > filename
command 2 >> filename ()
command >> filename 2>&1 ()
command < filename >filename2 c o m m a n d f i l e n a m e f i l e n a m e 2
command < filename c o m m a n df i l e n a m e
command sort.out
a c c o u n t f i l e . o u t
> f i l e n a m e l s
l s . o u t
$ ls >ls.out
( )
> > f i l e n a m e
0 ' > f i l e n a m e '
$ >myfile
5 s h e l l 41
5.7.2
a w k
$ sort < name.txt
s o r t
$ sort name.txt
s o r t n a m e . o u t
( )
$ sort name.out
l o u i s e c o n t e n t s . t x t
$ mail louise < contents.txt
command >
( )
5.8
( ) a c c o u n t s . o u t
$ cat account_qtr.doc account_end.doc 1>accounts.out 2>accounts.err
a c c o u n t s . e r r
a c c o u n t _ e n d . d o c
5.9
s h e l l
$ cleanup >cleanup.out 2>&1
c l e a n u p c l e a n u p . o u t
$ grep "standard"* > grep.out 2>&1
g r e p g r e p . o u t
2 > & 1
c a t
5 s h e l l 43
( i s q l
s y b a s e ) f t p
5.10 exec
e x e c s h e l l s h e l l
s h e l l
exec command
c o m m a n d s h e l l
e x e c s h e l l
e x e c
. p r o f i l e
s h e l l e x e c
e x e c
s h e l l
5.11
e x e c
4 49 s t o c k . t x t
4 s t o c k . t x t
4 l i n e 1l i n e 2
s t o c k . t x t
c p
44 shell
5.12
s h e l l
( 39 )
5 s h e l l 45
5 shell 5.1 echo5.2 read5.3 cat5.4 5.5 tee5.6 5.6.1 5.6.2 5.6.3
5.7 5.7.1 5.7.2 5.7.3
5.8 5.9 5.10 exec5.11 5.12
06.pdf
6
& &| | s h e l l
S h e l ls h e l ls h e l l { }
6.1 &&
& &
1 && 2
& & 1 (0
& & 2 & &
& &
& & & & e c h o
$ mv /apps/bin /apps/dev/bin && rm -r /apps/bin
/ a p p s / b i n / a p p s / d e v / b i n
/ a p p s / b i n
q u a r t e r _ e n d . t x t q u a r t e r. s o r t e d
q u a r t e r. s o r t e d
$ sort quarter_end.txt > quarter.sorted && lp quarter.sorted
6.2 ||
| |
1 || 2
| | | | 1 | |
2 ||
| |
| |
15
m o n t h _ e n d . t x t c o m e t
s h e l l s h e l l
$ comet month_end.txt || exit
6.3 { }
s h e l l s h e l l
s h e l l
s h e l l
1;2;. . .
{ } s h e l ls h e l l
{ } s h e l l
s h e l l
{1;2;. . . }
& &| |
c o m e t
$ comet month_end.txt || exit
s h e l l
e x i t
& &
$ sort quarter_end.txt > quarter.sorted && lp quarter.sorted
s o r t
6 47
6.4
s h e l l& &| |
& &| |
48 shell
6 6.1 &&6.2 ||6.3 { }6.4
07.pdf
7
U N I XL I N U X
s h e l l
s h e l l
R E
AAxx
g r e ps e d{ \ \ }
a w k
7-1
^
$
* *0
[ ] [ ] -
[ ] [ 1 - 5 ][ 1 2 3 4 5 ]
\ s h e l l
\
.
p a t t e r n \ { n \ } p a t t e r nn
p a t t e r n \ { n\ } m n
p a t t e r n \ { nm \ } p a t t e r nnm
7.1
. b e g
b e g . n.
ls -l
. . . x . . x . . x
1 0 4X C
. . . .X C. . . .
456X C4
A S C I I
7.2 ^
^ ls -l
ls -l d
1^ 0 0 1 0 0 1
^ . . . 4 X C . . . .
50
34 X C 4 ^
41
^ . . . 1
4c o m p
^ c o m p
4c o m p i n g
^ c o m p . . i n g
7.3 $
$^ $
t r o u b l e
t r o u b l e $
1 d $1 d
^ $
^ . $
j e t 0 1
j e t 0 1 $
7.4 *
c o m p u * t
u
1 0 1 3 3 *
7 51
7.5 \
.
\ .
^
\
* . p a s
\ * \ . p a s
*
7.6 []
[ ]
- - -
[ ]
[ 0 1 2 3 4 5 6 7 8 9 ]
-
[ 0 - 9 ]
[ a - z ]
[ A - Z a - z ]
A - Za - z
[ A - Z a - z 0 - 9 ]
[ ] s
t
s[a-z A-Z]t
52
s [ a - z ] t
C o m p u t e rc o m p u t e r
[ C c ] o m p u t e r
S c o u ts h o u tb o u g h t
[ou] .*t
ou t
s y s t e m S
[ S,s ] y s t e m \ .
[ ] *[ ] [ A - Z a - Z ] *
[ A - Z a - z ] *
^
[^a-zA-Z]
[ 0 - 9 ]
^
7.7 \{\}
* \ { \ }
pattern\{n\} n
pattern\{n,\} n
pattern\{n,m} nmn , m0 - 2 5 5
AB
A \ { 2 \ } B
A A B
A4
A \ { 4 , \ } B
A A A A BA A A A A A A BA A A B
A24
A \ { 2 , 4 \ } B
A A BA A A BA A A A BA BA A A A A B
4 x x4
7 53
[ 0 - 9 ] \ { 4 \ }X X[ 0 - 9 ] \ { 4 \ }
1) 4
2) x x
3) 4
7 - 2
7-2
^
$
^ [ t h e ] t h e
[ S s ] i g n a [ l L ] s i g n a ls i g n a L
S i g n a lS i g n a L
[Ss]igna[lL]\.
[ m a y M A Y ] m a y
^ U S E R $ U S E R
[tty]$ t t y
\ .
^ d . . x . . x . . x
^ [ l ]
[ . * 0 ] 0
[ 0 0 0 * ] 0 0 0
[ iI] I
[ i I ] [ n N ] in
[ $ ]
[ . * $ ]
^ . . . . . . $ 6
[a- zA-Z]
[ a - z ] [ a - z ] *
[ 0 - 9 \ $ ]
[ 0 - 0 A - Z a - z ]
[ 1 2 3 ] 13
[ D d ] e v i c e d e v i c eD e v i c e
D e . . c e D e
c e
54
\ q ^ q
^ . $
^\.[0-9][0-9]
' " D e v i c e " ' d e v i c e
D e [ V v ] i c e \ . D e v i c ed e v i c e
[ 0 - 9 ] \ { 2 \ } - [ 0 - 9 ] \ { 2 \ } - [ 0 - 9 ] \ { 4 \ } d d - m m - y y y y
[ 0 - 9 ] \ { 3 \ } \ . [ 0 - 9 ] \ { 3 \ } \ . [ 0 - 9 ] \ { 3 \ } \ . [ 0 - 9 ] \ { 3 \ } I Pnnn. nnn.nnn.nnn
[ . * $ ]
7.8
s h e l l
g r e p , s e da w k
7 55
7 7.1 7.2 ^7.3 $7.4 *7.5 \7.6 []7.7 \{\}7.8
08.pdf
8 grep
g r e pU N I XL I N U X g r e p
g r e p g r e p
g r e p
G r e pg r e p
E g r e pg r e p \ q
F g r e pg r e p f a s tg r e p
grep
g r e p
g r e p g r e p
g r e p GNU grep
g r e p g r e pf g r e p
e g r e pg r e p
< Ta b >g r e p
d a t a . . f
d a t a . f
1
2
3
4
5
6
7
8.1 grep
g r e p
grep [] []
8.1.1
g r e pm y s t r i n g
s h e l l
jet plane p l a n e
g r e p$ M Y VA R
8.1.2 grep
g r e p
-c
-i
-h
-l
-n
-s
-v
8.1.3
. d o c s o r t
$ grep "sort"*.doc
sort it
$ grep "sort it" *
g r e p
8.1.4
$ grep -c "48"data.f
$ 4
g r e p444 8
4 84
8 g rep 57
8.1.5
4 8
8.1.6
4 8
8.1.7
4 8 4 8 44 8 3
4 8 4 8
< Ta b >
< Ta b > t a b
g r e p \ > 4 8
8.1.8
g r e p - i
d a t a . f S e p t
8.2 grep
g r e p s h e l l
58
8.2.1
4 8 44 8 3 [ ]
4 8344 8 44 8 3
8.2.2
4 8 ^
8.2.3
- i S e p t [ ]
S e p ts e p t
S e p t 4 8 3
| |
g r e p g r e p
8.2.4
LD 5
C
8.2.5
51 9 9 61 9 9 8
5 . . 1 9 9 [ 6 , 8 ] 5 1 9 9 6
8
8 g rep 59
1 9 9 8 [ 0 - 9 ] \ { 3 \ } [ 8 ]
38
8.2.6
[ ]
0506
^
8.2.7
4
4
9 9 99
9
26
8263
60
8.2.8 grep
g r e p - E 2 1 9
2 1 6
8.2.9
^$ - n
8.2.10
$ . ' " * [] ^ | \ + ? ,\.
c o n f t r o l l . c o n f
8.2.11
f i l e n a m e . d e p o s i t
8.2.12 IP
D N S I P
I P2 0 0 0 n n n . n n n
n n n . n n . .nnn.nnn IP [ 0 - 9 ] \ { 3 \ } \ . [ 0 - 0 \ { 3 \ } \
3 3
8 g rep 61
8.3
g r e p
8-1
[ [ : u p p e r : ] ] [ A - Z ] [ [ : a l n u m : ] ] [ 0 - 9 a - zA-Z]
[ [ : l o w e r : ] ] [ a - z ] [ [ : s p a c e : ] ] t a b
[ [ : d i g i t : ] ] [ 0 - 9 ] [ [ : a l p h a : ] ] [ a - z A - Z ]
5
PD
*
g r e p*
g r e p
d e v i c e
8.4 grep
g r e p
62
|
8.4.1
8.4.2 passwd
/ e t c / p a s s w d l o u i s e
g r e p 'No such file or directory'
g r e p- s
g r e p - s
2 > $ 1
/ d e v / n u l l
g r e pe x i t
g r e p
/ t m pp a s s w d . o u t
8.4.3 ps
ps xg r e p ps x
D N S n a m e d
g r e pg r e p ps x g r e p
- vp sg r e p
8 g rep 63
ps x ps -ef
8.4.4 grep
g r e p e c h o g r e p
8.5 egrep
e g r e pe x p r e s s i o nextended grep e g r e p e g r e p
e g r e p
- f g r e p s t r i n g s4 8 44 7
d a t a . f4 8 44 7 - f
3 2 L2 C C | |
| l o u i s em a t t ypauline
w h oe g r e p
^ m a t t yp a u l i n e
s h u t d o w ns h u t d o w n sr e b o o tr e b o o t se g r e p
64
8.6
g r e p U N I X
D O S g r e p
g r e ps h e l l U N I X
8 g rep 65
8 grep 8.1 grep8.1.1 8.1.2 grep 8.1.3 8.1.4 8.1.5 8.1.6 8.1.7 8.1.8
8.2 grep 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.2.7 8.2.8 grep 8.2.9 8.2.10 8.2.11 8.2.12 IP
8.3 8.4 grep 8.4.1 8.4.2 passwd 8.4.3 ps 8.4.4 grep
8.5 egrep8.6
09.pdf
9 AWK
a w k
a w ks h e l l
a w k Bailing out
a w k : c m d . L i n e : a w k s h e l la w k
a w k a w kg r e ps e d s h e l l
a w k a w k a w k
a w k
a w k
a w k
a w k s e dg r e p
a w k
a w k A h o . We n i n b e rg e rK e r n i g h a mn a w kg a w k
a w k a w k
a w k
9.1 awk
a w k
c o m m a n d sa w k
[ - F ] a w k
p a s s w d
- F
a w k a w k a w k
a w k
- f a w k _ s c r i p t _ f i l ea w k i n p u t _ f i l e ( s )a w k
9.2 awk
a w ka w k
- Fa w k
- Fa w k
a w k
9 - 1a w k #n
a w k
9-1 awk
1 2 3 4
P. B u n n y (1 ) # 0 2 / 9 9 # 4 8 # Yellow \n
J . Tr o l l (2 ) # 0 7 / 9 9 # 4 8 4 2 # Brown-3 \n
9.2.1
a w k a w k
B E G I N
E N DB E G I N B E G I N
E N D a w k
a w k
{ } i f
l o o p i n g a w k
9.2.2
a w k $ 1$ 2 . . . $ n
$ 1 , $ 3 13 5
$ 1 , $ 2 , $ 3 , $ 4 , $ 5$ 0Aw k
$s h e l l$
p r i n ta w k
9 AWK 67
1.
g r a d e . t x t
712345
67
- F
2. a w k
s h e l la w k >
w o w
t e e
d e l e t e _ m e _ a n d _ d i e
a w k | tee delete_me_and_die
3.
a w k
a w k
4.
a w k {print $0}()
68
5.
f i e l d - 1f i e l d - 4
$ 1$ 4
6.
t a b
t a b t a b \ t
n a m eb e l t \ n
\ n B E G I N
a w k
7.
end of reportE N DE N D
E N D
8. awk
a w k a w k
a w k
9 AWK 69
a w k
a w k
a w k
a w k
9. awk
g r a d e . t x t
B E G I N a w k s h e l l
a w k a w k
a w k
9.2.3 awk
g r e p
a w k
G r e e n / G r e e n /
G r e e n
9.2.4
a w k 7
\ ^ $ . [] | () * + ?
7 a w kg r e ps e d
+ +
/X Y?Z/X Y ZY Z
9.2.5
9 - 2a w k
70
9-2 awk
< > =
< = ~
= = !~ !=
1.
i fa w k
i f
g r a d e . t x t b r o w n f i e l d - 4
{if($4~/brown/) print } f i e l d - 4b r o w n
{ }
a w k i f
b r o w n
2.
4 8 4 8
f i e l d - 34 8a w k4 8
4 8= = $ 3 = =4 8 4 8
3.
~ !~
b r o w n $0 !~/brown/
b r o w n
a w k
9 AWK 71
f i e l d - 4
awk$4 !="brown"{print $0} grade.txt
b r o w nb r o w nb r o w n - 2b r o w n - 3 b r o w n - 2
4.
f i e l d - 6
f i e l d - 7
5.
6.
7.
[ ] [ ]
g r e e n / [ G g ] r e e n /
8.
a . / . . . a /
a
9.
y e l l o wb r o w n | |
72
Ye l l o wB r o w n
G r e e ng r e e n [ ]
10.
4 8 ^
a w k7 7
a w k
&& AND :
|| O R
!
11. AND
P. B u n n y Ye l l o w ( $ 1 = = " P. B u n n y " & &
$ 4 = = " Ye l l o w " )& &
12. Or
Ye l l o wB r o w n | |
9.2.6 awk
a w k 9 - 3
9-3 awk
A R G C
A R G V
E N V I R O N
FILENAME a w k
F N R
F S - F
9 AWK 73
()
N F
N R
O F S
O R S
R S
A R G C a w k A R G VA R G C
A R G V [ n ]n
E N V I R O N
E N V I R O N [E D I TO R] =Vi
F I L E N A M Ea w k a w k
F N Ra w k N R
F Sa w k - F
F S = ""
N F
O F S #O F S = " # "
O R S \ n
R S ( \ n )
9.2.7 NFNRFILENAME
a w k
N R
N R
print NRE N D
N F
E N D
B r o w nA N D
B r o w n
74
N F $ P W Da w k
/
9.2.8 awk
a w k
= += *= / = %= ^ =
|| && ! ~!~
< >
+ - * / % ^
+ + --
1.
a w k
n a m e = $ nn a m e n
n a m e b e l tn a m e = $ 1 ; b e l t s = $ 4 a w k
n a m eb e l t sYe l l o w
2.
1) B E G I N
2)
B E G I N a w k
2 7
2 72 7
9 AWK 75
B A S E L I N EB E G I N
3.
a w k
a w ka w kN RN F
$ 1 = $ 1 + 515
M . Ta n s l e y 4 03 9 $ 6 = $ 6 - 1
4.
J . Tr o l l
J . L . Tr o l l$ 1 = " J . L . Tr o l l " " "
5.
1 0 0
6.
a w k
{ $ 4 = $ 2 + $ 3 }3
423
g r a d e . t x t 8
{ $ 8 = $ 7 - $ 6 }
B E G I N t a b
76
7.
+ =
$ 1 t o t a l t o t a l + = $ 1
a w k
t o t + = $ 6t o ta w k
6 E N D 6 a w k
8.
ls -l a w ka w kd
E N D
ls -l d
5 9
d^ [ d ]
t o t
9 AWK 77
9.2.9
a w k 9 - 4
9-4 awk
g s u b ( r, s ) $ 0sr
g s u b ( r, s , t ) tsr
i n d e x ( s , t ) s t
l e n g t h ( s ) s
m a t c h ( s , r ) s r
s p l i t ( s , a , f s ) f ssa
s p r i n t ( f m t , e x p ) f m te x p
s u b ( r, s ) $ 0 s
s u b s t r ( s , p ) sp
s u b s t r ( s , p , n ) spn
g s u b s e d
$ 0g s u b
$ 0
i n d e xst s t l e n g t h s
m a t c h s r s p l i t f s
sas p r i n tp r i n t f f m t
e x ps u brs s$ 0 r
s u bspsp s u b s t rspn n
a w k
1. gsub
/ /
/4 8 4 24 8 9 9
2. index
st
B u n n yn y
3. length
J . Tr o l l
78
4. match
m a t c h
0 A N C Dd
0A N C DDA N C DD
J . L u l uu
5. split
s p l i t
- A D2 - K P 9 - J U 2 - L P - 1 s p l i t
( " A D 2 - K P 9 - J U 2 - L P - 1 "p a r t s _ a r r a y" - "s p l i t
4
s p l i tm y a r r a ym y a r r a y
6. sub
s u b S T Rpoped popo pill
s u bs u b/ o p /" o p "S T R o p
pO Ped pope pill
J . Tr o l l
2 92 4 s u b/ 2 6 /" 2 9 "$ 0
2 4J . Tr o l l
7. substr
s u b s t r
1 5
9 AWK 79
a w k L Ta n s l - e y
379 9a w k
s u b s t r
1
B E G I N E N D t
8. s h e l la w k
a w k
a w k a w k
s t a n d - b ya w k
a w k
a w k
9.2.10
\ n
\ n
{ } / \ { /a w k
9 - 5a w k
9-5 awk
\ b \ t t a b
\ f \ d d d
\ n \ c \ \
\ r
80
May Day t a b May Day
1 0 41 4 11 7 1Day
\ 1 0 4DA S C I I\ 1 4 1aA S C I I
9.2.11 awkprintf
t a b a w k
p r i n t f
p r i n t f %
p r i n t fp r i n t f[ ]
9.2.12 printf
9-6 awk printf
-
Wi d t h 00
. p r e c
9-7 awk printf
% c A S C I I
% d
% e
% f 1 2 3 . 4 4
% g a w k ef
% o
% s
% x
1.
A S C I I6 5 6 5a w kp r i n t fA S C I I
p r i n t f
a w k
9 9 9
2.
9 AWK 81
1 5 \ n
p r i n t
p r i n t f
3. a w k
a w k a w k
a w ka w k
awk =
a w k
A G E1 0 a w k 1 0
a w k
df -k a w k 4 $ 4 ~ / [ 0 - 9 ] /
1 0 2 4d f i f ( $ 4 < T R I G G E R )T R I G G E R
df -k
d f
a w k w h ow h o
a w k L O G N A M E
w h oa w k
82
r o o t
root you are connected to ttyp1
4. awk
a w k
a w k
a w k
awk t o t + = $ 6 END{print "club student total points" t o t } g r a d e . t x t
s t u d e n t _ t o t . a w ka w ka w k
a w k
/bin/awk -f
a w k
9 AWK 83
E R R O R *
a w k
a w k
a w k
a w k
5. a w kF S
F S#
F S
84
a w k F SB E G I N a w k
F S / e t c / p a s s w d 15;
p a s s w d15
6. a w k
a w ka w k
awk script_file var=value input_file
N FM A X
/ e t c / p a s s w dp a s s w d7
a w k
9 AWK 85
a w kd u
d u a w k
9.2.13 awk
s p l i t
s p l i tm y a r r a ym y a r r a y
For (element in array ) print array[element]
1 2 3 # 4 5 6 # 6 7 8 s p l i t
86
/ d e v / n u l l
s p l i t
#
1) Ye l l o wO r a n g eR e d
2 )
2 0 6 0
a w k
a w k
9 AWK 87
B E G I NF S# Ye l l o wO r a n g eR e d
B E G I NB E G I N
c o l o r 1
Ye l l o wO r a n g eR e d
S e n i o r _ o r _ j u n i o r 2 j u n i o r
s e n i o r
E N D
\ a w k
9.3
a w k
a w k a w ka w ks h e l l
s h e l l a w k
88
9 AWK 9.1 awk9.2 awk 9.2.1 9.2.2 9.2.3 awk 9.2.4 9.2.5 9.2.6 awk 9.2.7 NF NR FILENAME9.2.8 awk 9.2.9 9.2.10 9.2.11 awk printf9.2.12 printf 9.2.13 awk
9.3
10.pdf
10 sed
s e d
s e d
Vi s e d s e d
s e d
s e d
s e d s e da w k
s e d s e d
s e d
s e d
s e d s e d
g r e pa w k s e d
g r e pa w k
10.1 sed
s e d
10.2 sed
s e d s e d s e ds e d
s e d
s e d
sed [] s e d
s e d s e d
s e d
sed [] -f sed
s e ds e d
s e d []
s h e l l s e d
s e d
n s e dp
c s e d
f s e d s e d s e d
sed -f myscript.sed input_filem y s c r i p t . s e ds e d
10.2.1 sed
s e d m y o u t f i l e
10.2.2 sed
s e d
1)
2 ) 7
1 0 - 1s e d
10-1 s e d
x x 1
x , y xy2525
/ p a t t e r n / / d i s k //[a-z]/
/ p a t t e r n / p a t t e r n / / d i s k / d i s k s /
p a t t e r n / , x / r i b b o n / , 3
x , / p a t t e r n / 3 . / v d u /
x , y ! xy1 , 2 !
10.2.3 sed
1 0 - 2S e d
10-2 sed
p
=
a \
i \
d
c \
90
()
s
r
w
q
l A S C I I
{ }
n
g 2 /pattern n/
y
n
s e d q u o t e . t x t
10.3 sed
s e d
\ 7 7
s e d
10.4 sed
s e d
10.4.1 print
p r i n t [ a d d r e s s [a d d r e s s ] P s e d
- n
10.4.2
13
10 sed 91
10.4.3
N e a v e / p a t t e r n / / N e a v e /
10.4.4
s e d
q u o t e . t x t
t h es e dt h e
l i n e _ n u m b e r, / p a t t e r n /
4 , / t h e / t h e
10.4.5
$ \ /\$/ p
10.4.6
1 , $$
10.4.7
0 i n g / . * i n g /
i n g
10.4.8
92
10.4.9
$$
10.4.10
= / p a t t e r n / =
- e
s e d e
= sed -n -e /pattern/p -e /pattern/=
10.4.11
a \
s e d
s e d
s e d
s e d
s e d
a\ s e da \
s e d
s e d
s e d s h e l l
s e d
10 sed 93
10.4.12 sed
a p p e n d . s e d
file not found . \
s e d s e d
/ b i n
/ c o m p a n y / a \s e d
10.4.13
a t t e n d a n c eutter confusion followed
94
4
10.4.14
The honeysuckle band played all night long for only $90The office Di b b l e
band played well / H o n e y s u c k l e /s e d
c h a n g e . s e d
chmod u+x change.sed
10 sed 95
10.4.15
s e d
[ a d d r e s s [a d d r e s s ] ] d
1 d
N e a v e
10.4.16
[ a d d r e s s [address]] s/ pattern-to-find /replacement-pattern/[g p w n]
s s e d p a t t e r n - t o - f i n d r e p l a c e m e n t - p a t t e r n
g g
p s e d p - n - n
w
96
n i g h tN I G H T n i g h t N I G H T
$ 9 0 $ \
r e p l a c e m e n t - p a t t e r n s e d
g T h e
Wo w
w s p l e n d i dS P L E N D I D
s e d . o u t
s e d
10.5
&&
&
s e ds/nurse/"Hello"&/p
The local nurse Miss P.Neave was in attendance
The honeysuckle band played all night long for only $90
10.6 sed
> s e d
10 sed 97
[ a d d r e s s [address]]w filename
w s e d f i l e n a m e
q u o t e . t x t 12f i l e d t
N e a v e f i l e d h t
10.7
s e d
address r filename
rs e d f i l e n a m e
s e d e x . t x t
s e d e x . t x tq u o t e . t x t / c o m p a n y /
10.8
s e d
address q
/ . a . * / a0
qs e d
98
10.9
cat -v filename
cat filenamec a t - v
s e d
[ a d d r e s s[ a d d r e s s ] ] l
l
l
1$
c a t
s e d
s e d \ 0 3 3O PF 1
t e r m i n f ot e r m c a p
F 1v i
v i
< C t r l >< v > a
F 1 [ O P ]
< E S C >F 1
10.10 sed
s e d s e d
10.10.1
s e d
d o s . t x t
10 sed 99
1) # #
2) 00 0
3) ^ M
^ @^ L
d o s . t x t
1 #
#
2 0^ ^ 0 *0
s / 0 * / / g
3 ^ M
s / m / / g^ M
^ M F 1 sed s/
< C t r l >vv^< C t r l >
< r e t u r n > ^ M
s e d
c a t s e d s e d
s e d
100
s e d s e d
10.10.2
s q l
1) s / - * / / g - - - - - -
2) / $ / d
3) $ d
4) 1 d
5) awk {print $1}
c a t s e d
10.10.3
U N HU N D
U N HU N D
[ 0 - 9 ]
10 sed 101
10.10.4
p a s s e d
$
10.10.5 shellsed
s e d
10.10.6 sedshell
s e d s h e l l s h e l l
N E W- N A M E s e d
10.11
[ ] [ ]t a b
s / \ . $ / / g
-e /abcd/d a b c d
s / [ ] [ ] [ ] * / [ ] / g
s / [ ] [ ] * / / g
s / \ . [ ] [ ] * / [ ] / g
/ $ / d
s / . / / g
s /CO L \ ( . . . \ ) / / g C O L
s / \ / / / g \
s / [ ] / [ ] / / g t a b
S / [ ] / / g t a b
s / [ ] * / / g t a b
102
1. \
s e d \
2. /
"Mr Wi l l i s " s e dM r" B r u c e "
3.
s e da c c o u n t s . d o c
4.
s e da c c o u n t s . d o c
5.
s e d . d o ca c c o u n t s
6.
x
s e d
10.12
s e d s e d
s e d s e d
s e d
10 sed 103
10 sed 10.1 sed 10.2 sed10.2.1 sed 10.2.2 sed 10.2.3 sed
10.3 sed 10.4 sed 10.4.1 p rint 10.4.2 10.4.3 10.4.4 10.4.5 10.4.6 10.4.7 10.4.8 10.4.9 10.4.10 10.4.11 10.4.12 sed 10.4.13 10.4.14 10.4.15 10.4.16
10.5 10.6 sed 10.7 10.8 10.9 10.10 sed10.10.1 10.10.2 10.10.3 10.10.4 10.10.5 shell sed 10.10.6 sed shell
10.11 10.12
11.pdf
11
P I C KU N I X P I C K
P I C K
s o r t
uniq
join
cut
paste
split
11.1 sort
s o r t
s o r t U N I X
11.1.1
U N I X / L I N U Xs o r t s o r t
s o r t
s o r t
s o r t s o r t
s o r t
s o r tu n i qj o i nc u tp a s t es p l i t
s o r t
11.1.2 sort
s o r t
sort -cmu -o output_file [other options] +pos1 +pos2 input_files
s o r t
-c
-m
-u
-o s o r t
-b
-n
-t t a b
-r
+n n
n n + n
post1 mnmn 4657
11.1.3
- o r e s u l t s . o u t
11.1.4 sort
s o r t - t
s o r t - t
01 s o r t
v i d e o . t x t1
234 - t
11.1.5 sort
s o r t 01 s o r t
s o r t 0011
11.1.6
3 0 4 0 0 s o r t - c
11 105
106
s o r t
11.1.7 sort
s o r tsort filename 0 s o r t
s o r t
11.1.8 sort
s o r t - r s o r t
0
11.1.9
2 1 t 1
1 1 23
11.1.10
t 3
- n
- n 3
2 t 2
3
The Hill s o r t3
- n
A l i e n s - rA l i e n s
11.1.11
- u
A l i e n A l i e n
- u s o r t
11 107
11.1.12 ksort
s o r t k1 1
1 s o r t
k
1 - k 4
11.1.13 k
41 -k4 -k1
11.1.14 sort
- n s o r t
023
11.1.15 pos
f i e l d _ n u m b e r c h a r a c t e r s _ i n
108
11 109
+ 1 . 2 13
11.1.16 headtail
s o r t
4 - k 4 s o r t
h e a d head -1
t a i lh e a d 1
2 tail -1 s o r t t a i l
h e a dt a i l h e a d
Ta i l
h e a dt a i l 1 0
2 0
7
11.1.17 awksort
s o r t a w k
s o r t a w k
11.1.18
sort -m sorted_file1 sorted_file2
-m +o v i d e o . s o r t
+ o
11.2 sort
s o r t / e t c / p a s s w d 1
a w ka w k
s o r td f d f
- b 4+ 4
I P I P
I P
110
I P 3
11.3 uniq
u n i q u n i q
u n i qs o r t
s o r t u n i q
u n i q
u n i qMay Day 4
May Dayu n i q
-u
-d
-c
-f nn
- f - n
m y f i l e . t x tu n i q
5 May Daysort -uMay Day
Going Down
11 111
112
- c May Day
1.
- d
2.
- n - 5 5 1
1 2 - n 2 2
u n i q
1u n i qO P
- f
11.4 join
j o i n S Q L j o i n
j o i n f i l e 1f i l e 2
j o i n
t a b
j o i n2 0 2 0D B M S
j o i n
an n n - a 1
- a 2
o n.m nm1 . 3 1 nm
1 . 32 . 1
j n m nm
t t a b - t
n a m e . t x t
t o w n . t x t
M . G o l l s12 Hidd Rd
0 j o i n
j o i n
1.
j o i n
- a
P. H e l l e r
2.
- o j o i n
1 . 12 . 2
11 113
-jn m 132
p e r s I Dp e r s 2 I D
p e r s4p e r s 22
j o i n 4 j o i n
5 a w k$ awk '{print $4}'
11.5 cut
c u t
c u t
cut [options] file1 file2
-c list
-f field
-d t a b
- c
- c 15-7 157
-c1-50 5 0
-f - c
-f 15 15
- f 110-12 11 01 2
p e r s ' p e r s '
114
11.5.1
- d - d3
- f 3 I D
11.5.2
c u t 13 I D
/ e t c / p a s s w d 13
- c
c u t
ls -l - c
ls -l cut -c1-10
11 115
11.6 paste
c u t p a s t e
p a s t e p a s t e t a b
- d
p a s t e
paste -d -s -file1 file2
-d t a b@- d @
-s
- ls -l |paste
p a s t e
11.6.1
11.6.2
t a b - d
- s
I D
116
11.6.3 paste
p a s t e - -
4
11.7 split
s p l i t
v is o r t
s p l i t
split -output_file-size input-filename output-filename
o u t p u t - f i l e - s i z e s p l i to u t p u t - f i l e - s i z e
1 0 0 0 2 8 0 03
1 0 0 01 0 0 08 0 0x [ a a ]x [ z z ]x [ a a ][ z z ]
b i g o n e . t x t2 8 0 0s p l i t
o u t p u t - f i l e - s i z e 6
11 117
2
6s p l i t
11.8
s o r tj o i ns p l i t
u n i qc u tp a s t e
118
11 11.1 sort 11.1.1 11.1.2 sort 11.1.3 11.1.4 sort 11.1.5 sort 11.1.6 11.1.7 sort11.1.8 sort 11.1.9 11.1.10 11.1.11 11.1.12 k sort 11.1.13 k 11.1.14 sort 11.1.15 pos 11.1.16 head tail 11.1.17 awk sort 11.1.18
11.2 sort11.3 uniq 11.4 join 11.5 cut 11.5.1 11.5.2
11.6 paste 11.6.1 11.6.2 11.6.3 paste
11.7 split 11.8
12.pdf
12 tr
12.1 tr
t r t r
t r12
t r1 2
t r
t r - c - d - s [ " s t r i n g 1 _ t o _ t r a n s l a t e _ f r o m " ] [ " s t r i n g 2 _ t o _ t r a n s l a t e _ t o " ] i n p u t _
f i l e
-c 1 A S C I I
-d 1
-s
I n p u t - f i l e
12.1.1
t r
12
[a-z] a-z
[A-Z] A-Z
[0-9]
/octal A S C I I
[O*n] On[ O * 2 ]O O
t r [c l a s s ]
c n t r l 1 2 - 1
[ ]
[\ 0 1 2]\ 0 1 2t r
t r
\ {
12-1 tr
\ a Ctrl-G \ 0 0 7
\ b Ctrl-H \ 0 1 0
\f Ctrl-L \ 0 1 4
\n Ctrl-J \ 0 1 2
\ r Ctrl-M \ 0 1 5
\t Ctrl-I tab \ 0 11
\ v Ctrl-X \ 0 3 0
12.1.2
r e s u l t s . t x t
c o p s . t x t
12.1.3
v i
- s [ a - z ]
t r
c a t t r
12.1.4
p l a n e . t x t
120
- s \ 0 1 2
\ n
12.1.5
t r [ a - z ]
[ A - Z ]
t r
[l o w e r][u p p e r]
f i l e - t o - t r a n s l a t en e w - f i l e - n a m e
12.1.6
f i l e - t o - t r a n s l a t en e w - f i l e - n a m e
12.1.7
- c- s
[ a - z ][ A - Z ]tr -cs "[a-z][A-Z]""[\012*]"
12 tr 121
[ a - z ][ A - Z ] 1
- s - c t r
12.1.8
t r d o sU N I X f t p
c a t
- v
^ t a bC t r l - MC t r l - Z
- sA S C I I^ 1 3 6^ M0 1 5t a b0 11^ Z0 3 2 ,
t a b^ " \ 1 3 6 " " [ \ 0 11 * ] " s t a t . t m p
^ M\ n^ Z s t a t . t m p
12.1.9
^ M
122
D o sU N I X
^ M^ Z
t a b
p a s s w d t a b
t a b0 11p a s s w d t r
t a b
12.1.10
[ c h a r a c t e r * n ]
0
0
0 [ 0 * 4 ]
40
12.2
t r s e d
t rt r
12 tr 123
12 tr 12.1 tr12.1.1 12.1.2 12.1.3 12.1.4 12.1.5 12.1.6 12.1.7 12.1.8 12.1.9 12.1.10
12.2
13.pdf
13
/ e t c / p a s s w d
/ e t c / p a s s w d
$HOME.profile
$ H O M E . p r o f i l e
/ e t c / p a s s w d
7
1 2 5 6
7s h e l l/ b i n / s hBourne Shell
P a s s w d p a s s w d
/ e t c / p r o f i l e . p r o f i l e
p r o f i l e
13.1 /etc/profile
/ e t cp r o f i l e
PAT H
PAT H
/ e t c / p r o f i l e
126
p r o f i l e
Q U I T< C t r l - c >
L O G N A M E m a nM A N PAT H
m a n
v t 2 2 0
u m a s k
< C t r l -C>Q U I T
s t t y
13 127
/ v a r / a d m / m e s s a g e s
u l i m i t
i d n kp s a l o md a v e
p r o f i l e
13.2 $HOME.profile
/ e t c / p r o f i l e $ H O M E p a s s w d
$ H O M E2
. p r o f i l e s h e l l
/ e t c / p r o f i l e . p r o f i l e
s h e l l
. p r o f i l e p r o f i l e
. p r o f i l e u s e t / e t c / p r o f i l e
. p r o f i l e . p r o f i l e
E D I TO R c r o n
T E R Mv t 1 0 0v t 2 2 0
b i n p a t h b i n
PAT H
p w d
A S C I I
2 5 11 6 9
128
L I N U X
e c h o
/ u s r / a d m i n
A D M I N = / u s r / a d m
w h ow c
. p r o f i l e . p r o f i l e/ e t c / p r o f i l e
. / p a t h n a m e / f i l e n a m e
. p r o f i l e
$. .profile
$. ./profile
. p r o f i l e
13.3 stty
s t t y s t t y stty -a
13 129
s t t y
^ ?< C t r l - H > s t t y
stty name character
^ H
$ stty erase '\^H'
. p r o f i l e s t t y ' C o n t r o l
H 'v i
C t r lVVH
s t t y
i n t r ^ C
e c h o e c h o
- e c h o e c h o
e o f ^ D
k i l l ^ Y
s t a r t ^ Q
s t o p ^ S
s t t y
stty -g
s t t y s t t y
/ e t c / p r o f i l e stty -g
s t t y
s t t y
s t t y stty -ge c h o s t t y
LINUX
L I N U X e c h o - eecho -e
130
s t t y s t t y
13.4 .logout
Bourne shells h e l l . l o g o u t e x i t
t r a p t r a pBourne shell
. l o g o u t . p r o f i l e
trap "$HOME /.logout"0
. l o g o u t
. l o g o u t s h e l l 0
s h e l l s h e l l . p r o f i l e t r a p
. l o g o u t
13.5
. p r o f i l e
13 131
13 13.1 /etc/profile13.2 $HOME.profile13.3 stty 13.4 .logout 13.5
14.pdf
14 shell
s h e l l s h e l l s h e l l
s h e l l
4
s h e l l
shell
14.1 shell
E D I TO R
E D I TO R c r o n
E D I TO R
E D I TO R
v i
$ isql -Udavet -Pabcd -Smethsys
- S D S Q U E RY
D S Q U E RY - S D S Q U E RY
$ isql -Udavet -Pabcd
14.2
s h e l l f i l e - n a m e
l o o p . d o c s h e l l s h e l l
s h e l l
1 4 - 1
s h e l l
$ variable-name=value $ { v a r i a b l e - n a m e = v a l u e }
s h e l l
14-1
Va r i a b l e - n a m e = v a l u e v a r i a b l e - n a m e
Va r i a b l e - n a m e + v a l u e v a r i a b l e - n a m e
Va r i a b l e - n a m e : ? v a l u e v a r i a b l e - n a m e
Va r i a b l e - n a m e ? v a l u e v a r i a b l e - n a m e
Va r i a b l e - n a m e : = v a l u e v a r i a b l e - n a m e
Va r i a b l e - n a m e : - v a l u e v a r i a b l e - n a m e
14.2.1
e c h o $
L O G N A M Ee r r o r- m s g
s h e l l $ L O G N A M E
14.2.2
u n s e t
unset variable-name
14.2.3 shell
s e t s h e l l
14 shell 133
s e t s h e l l
14.2.4
14.2.5
$ { v a r i a b l e : - v a l u e }
c o l o u rb l u ee c h oc o l o u r
$ { v a r i a b l e : = v a l u e }
0 3 : 0 0We e k l y
a t
134
f i l e
$ { v a r i a b l e : + v a l u e }
v a r i a b l e = " "
$ D E T I N A T I O N = " "
14.2.6
s o u r c ep a s s w dd e s tc p
d e v i c e m t
14.2.7
v a r i a b l e - n a m e = v a l u e
readonly variable-name
14 shell 135
r e a d o n l y
14.3
s h e l l
s h e l l
. p r o f i l e
/ e t c / p r o f i l e p r o f i l e
e x p o r t
14.3.1
V A R I A B L E - N A M E = v a l u eexport VARIABLE-NAME
V A R I A B L E - N A M E = v a l u e
Export VARIABLE-NAME
14.3.2
e n v
136
14.3.3
u n s e t
14.3.4 shell
Brourne shel l
/ e t c / p r o f i l e s h e l l
1. CDPAT H
c dC D PAT H
c d C D PAT HC D PAT H
$ CDPATH=:/home/dave/bin:/usr/local/appsexport CDPATH.
$ cd apps
c dC D PAT H a p p s
2. EXINIT
E X I N I T v i v i
1 0 t a b
$ EXINIT='set nu tab=10';export EXINIT
3. HOME
H O M E p a s s w d 2
H O M E c d
$ cd $ HOME
4. IFS
14 shell 137
I F Ss h e l l
t a bI F S I F S
echo PAT H
$ IFS=; export IFS
< s p a c e > < t a b > t a b
5. LOGNAME
6. MAIL
M A I L /var/spool/mail/s h e l l
M A I L
$ MAIL=/usr/mail/daveexport MAIL
7. MAILCHECK
M A I L C H E C K6 0 s 2 m
$ MAILCHECK=120export MAILCHECK
8. MAILPAT H
M A I L PAT HM A I L
$ MAILPATH=/var/spool/dave:/var/spool/adminexport MAILPATH
M A I Ld a v ea d m i n
9. PAT H
PAT H
H O M E
$ PATH=$HOME/bin:.:/bin:/usr/binexport PATH
H O M E / b i n / b i n
/ u s r / b i n
PAT H / e t c / p r o f i l e
$ PATH=$PATH:/$HOME/bin:. export PATH
/ e t c / p r o f i l ePAT H$ H O M E / b i n
10. PS1
s h e l l #$
138
11. PS2
P S 2 > P S 2
12. SHELL
S H E L L s h e l l / e t c / p a s s w d s h e l l
s h e l l
13. TERMINFO
/ u s r / l i b / t e r m i n f o/ u s r / s h a r e / t e r m i n f o
$ TERMINFO=/usr/lib/terminfoexport TERMINFO
14. TERM
T E R MT E R M
v t 1 0 0v t 2 0 0v t 2 2 0 - 8
$ TERM=vt100export TERM
15. TZ
G M T0E D T
14.3.5
1. EDITO R
$ EDITOR=viexport EDITOR
2. PWD
c d
3. PA G E R
p gm o r em a n
$ PAGER='pg -f -p%d'export PAGER
4. MANPAT H
14 shell 139
m a n
$ MANPATH=/usr/apps/man:/usr/local/manexport MANPATH
5. LPDESTP R I N T E R
$ LPDEST=hp3si-systems
14.3.6 set
$ H O M E . p r o f i l e s e t- a
set -a / e t c / p r o f i l e
$ H O M E . p r o f i l e
14.3.7
s h e l l
f a t h e rc h i l d
f a t h e rf i l mA Few Good Men
c h i l d f i l mDie Hard
f a t h e r
140
f a t h e r f i l mc h i l d f i l m
f a t h e re x p o r tc h i l d f i l m
e x p o r t f i l m
f i l m
14.4
4
s h e l l
9 s h i f t
s h i f t 9 $
0
Did You See Th e Full Mo o n
$ 0 $ 1 $ 2 $ 3 $ 4 $ 5 $ 6 $ 7 $ 8 $ 9
Did Yo u S e e T h e F u l l M o o n
14 shell 141
14.4.1
6789
$ 0 b a s e n a m e $ 0
14.4.2
f i n d $ 1
142
$ 1g r e p i dg r e p i dp a s s w d
14.4.3
s h e l l
7
1 4 - 2
14-2 s h e l l
$ #
$ * 9
$ $ I D
$ ! I D
$ @ $ #
$ - s h e l l s e t
$ ? 0
p a r a m
14 shell 143
I D
14.4.4
$ ?0
01
/ t m p$ ?
$ ? c pc a n n o t . . .
/ d e v / n u l lb i n
b i n
$ !1
144
14.5
s h e l l s h e l l
14 shell 145
14 shell 14.1 shell 14.2 14.2.1 14.2.2 14.2.3 shell 14.2.4 14.2.5 14.2.6 14.2.7
14.3 14.3.1 14.3.2 14.3.3 14.3.4 shell 14.3.5 14.3.6 set 14.3.7
14.4 14.4.1 14.4.2 14.4.3 14.4.4
14.5
15.pdf
15
15.1
s h e l l s h e l l
*s h e l l s h e l l
1 5 - 1
15-1 shell
" "
' ' \
15.2
$`\
s h e l l
m y d a t e
s h e l l" " m y d a t ed a t e
d a t e
g r e pDavey Wi r e
g r e pD a v e yWi r e
s h e l l
s h e l l
$ b o y$ B O Y
15.3
s h e l l
15.4
s h e l l
s h e l l h e l l o h e l l o
d a t e
s h e l l
15 147
m y d a t e
m y d a t e
d a t em y d a t e
s h e l l
15.5
s h e l l
& * + ^ $ ` " | ?
e c h o* *
$ echo \*
*
$ $ s h e l l I D
$ $
A S C I I s h e l l
148
L I N U X
- e
e x p r* *
e c h o $ 1 9 . 9 9
$
$
15.6
1)
2)
15 149
15 15.1 15.2 15.3 15.4 15.5 15.6
16.pdf
16 shell
s h e l l s h e l l
s h e l l
shell
shell
16.1 shell
s h e l l
s h e l l
U N I XL I N U Xs h e l l
s h e l l
16.2
# ! / b i n / s h
s h e l lBourne shell
#
s h e l l
16.3
c l e a n u p
/ u s r / a d m / / u s r / l o c a l / a p p s / l o g
c h m o d
$ chmod u+x cleanup
$ cleanup
$ cleanup
sh:cleanup:command not found
$. /cleanup
s h e l l . p r o f i l e
PAT H $ H O M E
$ pwd
$ /home/dave/bin
p w d b i n . p r o f i l e
$ H O M E / b i n
P A T H = $ P A T H : $ H O M E / b i n
b i n
$ cd $HOME
$ mkdir bin
. p r o f i l eb i nPAT H . p r o f i l e
$. ./profile
21 3
152 s h e l l
c h m o d
16.4
s h e l l
s h e l l
16 shell 153
s h e l l 16 shell 16.1 shell 16.2 16.3 16.4
17.pdf
17
Te s t
i ft h e ne l s e
t e s t
e x p r
e x p r $ ? t e s te x p r0
1
17.1
t e s t
test condition
[ c o n d i t i o n ]
1 7 - 1
17-1
- d - s 0
- f - w
- L - u s u i d
- r - x
s c o r e s . t x t 0
0 s c o r e s . t x t
s c o r e s . t x t
a p p s b i n
a p p s b i n
s u i d
s u i d
17.2
O K s h e l l
-a
-o
!
s c o r e s . t x tr e s u l t s . t x t
r e s u l t s . t x t
17.3
5
17 155
s t r i n g _ o p e r a t o r
=
=
-z
-n
E D I TO R
v i
e c h o
t a p et a p e 2
t a p et a p e 2
17.4
" n u m b e r " n u m e r i c _ o p e r a t o r " n u m b e r "
[ " n u m b e r " n u m e r i c _ o p e r a t o r " n u m b e r " ]
n u m e r i c _ o p e r a t o r
-eq
-ne
-gt
-lt
-le
-ge
1 3 01 3 0
156 s h e l l
11 3 02 0 0
1 3 01 0 0
s o u r c e _ c o u n td e s t _ c o u n t :
too many arg u m e n t s
17.5 expr
e x p r
expr argument operator argument
e x p r
s h e l l
17 157
17.5.1
e x p r 0 1
e x p r
17.5.2
e x p r
d e v / n u l l
0
e x p r
1
h e l l oh e l l o
e x p r1 0
h e l l oh e l l o
17.5.3
e x p r e x p r . *
0
e x p r . d o c
158 s h e l l
17.6
e x p rt e s t
if then elsec a s e
17 159
17 17.1 17.2 17.3 17.4 17.5 expr 17.5.1 17.5.2 17.5.3
17.6
18.pdf
18
whilef o runtil loops
if then else
18.1
$ echo $?
4 $ ?$ $
| | s h e l l s h e l l 1 9
s h e l le x i t
exit n
n
e x i t s h e l ls h e l l
e x i ts h e l l
0
1
s h e l l
s h e l l s h e l l
#
18.2
s h e l l
18.2.1
i ft h e ne l s e
0 1
c a s e
18.2.2
3
for
Until u n t i l
While w h i l e
f o r f o r
e c h oL I N U XB S D e c h oecho -e -n
e c h o U N I XVB S D e c h o1 9
s h e l l
18.3 if then else
i f 01 i f
if 1
then 1
elif 2
then 2
else 3
18 161
f i
i f
If 1 1
Then
1 1
elif 2 1
then
2 2
else 12
3 3
fi
i f f i i f f i
e l i fe l s e e l i fe l s eI f
e l i f i fif then fi
18.3.1 if
i f
i f
then
f i
i f t h e n
i f
if t h e n
f i
1 01 2 i f
e c h o
e l s e
18.3.2
162 s h e l l
r e t u r nn a m e
18.3.3 grep
g r e pi f
g r e p g r e pD a v e d a t a . f i l e
D a v e \ >
g r e p g r e p0g r e pi f
g r e p i f
18.3.4 grep
g r e p
g r e p P e t e r
18 163
18.3.5
c p m y f i l em y f i l e . b a k
` basename $0`
>/dev/null 2>&1
18.3.6
D I R E C TO RY
" / " /
1
164 s h e l l
18.3.7
i f t e s t . t x tL O G N A M E
18.3.8
i f $ #
3
18.3.9
c r o na t
18 165
t e s t - t
t e s t1
18.3.10 if else
i f
if
t h e n
1
e l s e
2
f i
i fe l s e
18.3.11
E D I TO RE D I TO R
18.3.12
L O G N A M E r o o t
L O G N A M E
r o o t r o o t
1
r o o tL O G N A M Ee l s e
f i r o o t
166 s h e l l
18.3.13
$ 1 D I R E C TO RY
ls -A
18.3.14 null
t h e ne l s e
i f s h e l l
t h e n
18 167
18.3.15
D I R E C TO RY
if ["$DIRECTORY"=""]
if[$# -lt 1]
Yy
168 s h e l l
18.3.16
c p$ 1$ 2
/ d e v / n u l l
s o r t a c c o u n t s . q t r
3 0 0
18.3.17 if
i f i ff i
18.3.18
E D I TO R
18 169
v i
v i
y
Yy $ E D I TO R =
r e t u r n -z $EDITO R
v iE D I TO Rv i
E D I TO R
E D I TO R
18.3.19
* . t x t
170 s h e l l
18.3.20
1 0 0
yY
C O U N TO R
18 171
18.3.21
s t t y
p a s s w d s t t y
I Dm a y d a y I N VA L I D _ U S E RI N VA L I D _ PA S S W D
n o y e s
I D
I Dd a v ep a u l i n e
172 s h e l l
18.3.22 elif
if then elsee l i f
18.3.23 elif
e l i f r o o tl o u i s ed a v e
r o o tl o u i s ed a v e
18 173
18.3.24
/ u s r / o p t s / a u d i t / l o g s/ u s r / l o c a l / a u d i t / l o g s
174 s h e l l
18.4 case
c a s e c a s e
c a s e
case i n
1 }
1
. . .
; ;
2
2
. . .
e s a c
c a s e i n
*
*
[..]
18.4.1 case
15 c a s eA N S c a s e
A N SA N S
;
c a s e
c a s e
*
18 175
*
18.4.2 |
c a s e | v t 1 0 0 | v t 1 0 2v t 1 0 0v t 1 0 2
v t 1 0 0v t 1 0 2v t 1 0 0 | v t 1 0 2
T E R Mv t 1 0 0 *
T E R Mv t 1 0 0c a s eT E R M *
T E R M
176 s h e l l
18.4.3 yn
c a s e yn
Yyy e s c a s e Nnn o
18.4.4 case
c a s e
$ # 1
18 177
c a s e p a s s w ds t a r ts t o ph e l p
18.4.5
c a s e
2 3 44 5 36 5 54 5 4
c a s e
178 s h e l l
18.4.6
w h e n
c a s e
18 179
c a s e if then else
18.5 for
f o r
for i n
d o
1
2
d o n e
180 s h e l l
f o r
s h e l l I n f o r
i n
18.5.1 for
1 2 3 4 5
18.5.2
f o r orange red blue greye c h o l o o p
e c h o$ l o o p
18.5.3 forls
l s
18 181
18.5.4 for
f o r i n
for params in"$@"
for params in"$*"
i n f o r$ @$ *
i n"$ @"
f o r f i n d
182 s h e l l
f i n d - n a m e
18.5.5 for
f o r f o r
18.5.6 for
f o r c p . b a k
c p l s
18.5.7
L P S O l sc a t l s
c a t t r .U C f o r l s
18 183
18.5.8 sed
s e d . H O L D . m v
m v
18.5.9
e x p r l sf o r
w c
18.5.10 for
f o r
w h oa w k f o r
184 s h e l l
18.5.11 for
f o r f o r
for 1 in1
d o
for 2 in 2
d o
1
. . .
d o n e
d o n e
f o rA P P SS C R I P T S
A P P S
S C R I P T S t e e
f o r
S C R I P T SA P P S
18 185
18.6 until
u n t i l u n t i lw h i l e
w h i l eu n t i l u n t i l
u n t i l
until
1
. . .
d o n e
18.6.1 until
w h o r o o tI S - R O O Tg r e p
r o o t s i m o n r o o t
s l e e p u n t i l
186 s h e l l
18.6.2
u n t i l / t m p / m o n i t o r. l c k
p r o c e s s . m a i n
p r o c e s s . m a i n L C K
p r o c e s s . m a i n p r o c e s s
p r o c e s s . m a i nL C K
L C K L C K
18.6.3
u n t i l
/ l o g s $L O O K_O U T $ L O O K _ O U T
a w kg r e p/ l o g s
9 0 %
9 0 %
18 187
18.7 while
w h i l e
while
d o
1
2
. . .d o n e
w h i l ed o
0d od o n e 0
18.7.1 while
w h i l e C O U N T E R5
C O U N T E R0C O U N T E R1
15
18.7.2 while
w h i l e F I L M< C t r l -
D >
188 s h e l l
18.7.3 while
w h i l e
I D
w h i l e
$ L I N E .
18.7.4 IFS
I F S I F S
I F S t a b3
N A M ED E P TI D
e c h o t a b
18 189
18.7.5
w h i l e
James Lenod
James Lenod
c a s ee x p r
190 s h e l l
18.7.6
S TATG I F T
G I F T e x p r
e x p rL O O PTO TA L 0 I T E M STO TA L
I T E M STO TA L
18 191
e x p r
e x p r
e x p r
TO TA L 0e x p r
192 s h e l l
18.7.7
w h i l e
w c
6
18.7.8 #
w h i l e
c a s e#
18 193
#**
#
18.7.9
194 s h e l l
I T E M
s e d
w h i l e e x p r
18 195
18.7.10 while
5 w h i l e
34m y f i l e . t x tm y f i l e . b a k
w h i l e
n u l l
196 s h e l l
18.8 breakcontinue
s h e l l
break
continue
18.8.1 break
b r e a k b r e a k c a s e
break 2
18.8.2 case
5 s h e l l
b r e a k
18.8.3 continue
c o n t i n u e b r e a k
18 197
18.8.4
Peter James
2
Peter James
198 s h e l l
18.9
w h i l en u l l h i l en u l l
w h i l ec a s e
/ D D / M M / Y Y Y Y
$ date +%d/%m/%y
3 2 / 0 5 / 1 9 9 9
h o s t n a m e - s
w h i l ew h i l e
while
d o
d o n e
e c h o
c a s e
18 199
c a s e
CAPS LOCK
Qq 0
L I N U XBSD echoV
echo "\007 the bell ring"
e c h o
t p u tt p u tc l e a r
200 s h e l l
18.10
18 201
18 18.1 18.2 18.2.1 18.2.2
18.3 if then else 18.3.1 if 18.3.2 18.3.3 grep 18.3.4 grep 18.3.5 18.3.6 18.3.7 18.3.8 18.3.9 18.3.10 if else 18.3.11 18.3.12 18.3.13 18.3.14 null 18.3.15 18.3.16 18.3.17 if 18.3.18 18.3.19 18.3.20 18.3.21 18.3.22 elif 18.3.23 elif 18.3.24
18.4 case 18.4.1 case 18.4.2 |18.4.3 y n18.4.4 case 18.4.5 18.4.6
18.5 for 18.5.1 for 18.5.2 18.5.3 for ls 18.5.4 for 18.5.5 for 18.5.6 for 18.5.7 18.5.8 sed 18.5.9 18.5.10 for 18.5.11 for
18.6 until 18.6.1 until 18.6.2 18.6.3
18.7 while 18.7.1 while 18.7.2 while 18.7.3 while 18.7.4 IFS 18.7.5 18.7.6 18.7.7 18.7.8 #18.7.9 18.7.10 while
18.8 break continue 18.8.1 break18.8.2 case 18.8.3 continue18.8.4
18.9 18.10
01.pdf
1
setuid
chownc h g r p
umask
()
1)
2)
3) s h e l l
1)
2)
3)
1.1
i
ls -l
s h e l l
total 4232
- r w x r- x r- x 9
9 9
r w x
r- x
r- x
rwx
1
root
root r o o t(r o o t )
3578 K
Oct 14 04:44
dmesg
1.2
ls -l
d
l ( )
s
b
c
p
-
1.3
t o u c h
$ touch myfile
ls -l
2 shell
(
)
r w - r- - r
a d m i n
1-1 ls -l
( ) -
( ) r w -
( ) r- -
( ) r- -
( )
1)
2) ( )
3)
r
w /
x
m y f i l e
- r w - r- - r--
m y f i l e
u m a s k
(1 - 2 )
1-2
r-- --- ---
r-- r-- --- ( )
r-- r-- r- -
rwx r-- r- -
rwx r-x ---
1 3
()
rwx r-x r- x
rw- rw- ---
rw- rw- r- -
rw- rw- ---
1.4
( )c h m o d
1.4.1
c h m o d
chmod [who] operator [permission] filename
w h o
u
g
o
a ( )
o p e r a t o r
+
-
=
p e r m i s s i o n
r
w
x
s s e t - I D
t *
l
u,g,o
* tt
t
t (
) t
4 shell
1.4.2 chmod
c h m o d m y f i l e r w x
rwx rwx
chmod a-x myfile rw- rw- rw-
chmod og-w myfile rw- r-- r- -
chmod g+w myfile rw- rw- r- -
chmod u+x myfile rwx rw- r- -
chmod go+x myfile rwx rwx r- x
m y f i l e
( )
$ chmod u+x o-w myfile
m y f i l e a d m i n
$ chmod u+x dt
1.4.3
c h m o d
chmod [mode] file
m o d e
1 - 3
1-3 /
0 4 0 0 0 0 1 0
0 2 0 0 0 0 0 4
0 1 0 0 0 0 0 2
0 0 4 0 0 0 0 1
0 0 2 0
1 - 3
1 - 37
1 5
6 4 4
0 4 0 0 + 0 2 0 0 ( ) = 0 6 0 0
0 0 4 0 () = 0 0 4 0
0 0 0 4 () = 0 0 0 4
0 6 4 4
1 - 4
1-4
r w x r w x r w x
4 + 2 + 1 4 + 2 + 1 4 + 2 + 1
1 - 4
m y f i l e
r w - r - - r - -
4 + 2 4 4
6 4 4
1.4.4 chmod
c h m o d
chmod 666 rw- rw- rw-
chmod 644 rw- r-- r- -
chmod 744 rwx r-- r- -
chmod 664 rw- rw- r- -
chmod 700 rwx --- ---
chmod 444 r-- r-- r- -
y o a
a d m i n
chmod 644*
6 shell
- R
chmod -R 664 /usr/local/home/dave/*
/ u s r / l o c a l / h o m e / d a v e
- R
1.4.5
1.5
c h m o d
1 - 51 - 6
1-5
r w x
1-6
drwx rwx r- x ( 7 7 5 )
drwx r-x r- - ( 7 5 4 )
drwx r-x r- x ( 7 5 5 )
- - x
d o c s
p a y
a d m i n
a d m i n
1.6 suid/guid
s u i dg u i d
1 7
s u i d s h e l l
g u i d
1.6.1 suid/guid
g u i d
U N I Xs u i dg u i d / b i n/ s b i n
$ ls -l | grep '^...s'
s u i d
$ ls -l | grep '^...s..s'
s u i dg u i d
s u i d
s u i d 4g u i d
24+2
sx s u i dg u i d
g u i d
l o g i ns u i d rwx rw- r-- (741)
c h m o d 4chmod 4741 r w s
rw- r- -
$ chmod 4741 logit
1.6.2 suid/guid
1-7 s u i d / g u i d
chmod 4755 rws r-x r- x s u i d
chmod 6711 rws --s --s s u i dg u i d
chmod 4764 rws rw- r- - s u i d
8 shell
s u i d / g u i d rwx r-x r- x
s u i d
chmod u+s
rws r-x r-x
s u i d rwS r-x r- xS
s u i d
c h m o d
chmod
1.7 chownchgrp
/ e t c / p a s s w d
I D s u i d
c h o w n
chmod -R -h owner file
- R - h
1.7.1 chown
p r o j e c t l o u i s ep a u l i n e
1.7.2 chgrp
c h g r pc h o w n
p a u l i n e a d m i ns y b a d m i n
1.7.3
1 9
i d
1.7.4
m a t t ys y b a d m i na p p s g e np o s t
1.8 umask
u m a s k
c h m o d u m a s k
u m a s k
s h e l lu m a s k
u m a s k / e t c / p r o f i l e
u m a s k
u m a s k $ H O M E . p r o f i l e. b a s h _ p r o f i l e
1.8.1 umask
u m a s k (
)u m a s k 6
c h m o d
u m a s k7
umask nnn
n n nu m a s k0 0 0 - 7 7 7
u m a s k
u m a s k u m a s k
1 - 8 u m a s k
u m a s k /
u m a s k
u m a s k002 6 6 47 7 5
u m a s k u m a s k
10 shell
1-8 umask
u m a s k
0 6 7
1 6 6
2 4 5
3 4 4
4 2 3
5 2 2
6 0 1
7 0 0
u m a s k0 0 2
7 7 7 ( )
u m a s k 0 0 2
u m a s k0 0 2
1) rwx rwx rwx (777)
2) umask0 0 2 - - - - - - -w-
3) rwx rwx r-x (775)
4) rw- rw- r-- (664)
u m a s k0 2 2
1) rwx rwx rwx (777)
2 ) u m a s k0 2 2 - - - -w- -w-
3) rwx r-x r-x (755)
4) rw- r-- r-- (644)
1.8.2 umask
1 - 9u m a s k
1-9 u m a s k
u m a s k
0 2 2 7 5 5 6 4 4
0 2 7 7 5 0 6 4 0
0 0 2 7 7 5 6 6 4
0 0 6 7 7 1 6 6 0
0 0 7 7 7 0 6 6 0
umask u m a s k
1 11
u m a s ku m a s k
$ umask 002
u m a s k
u m a s k /
u m a s k6 0 0 /
0 6 6
1.9
1.9.1
/ u s r / l o c a l / a d m i n / s a l e s
$ H O M E
$ H O M E
$ H O M E
/ u s r / o p t / a p p / l o g
ln [-s] source_path target_path
1.9.2
4 0
$ H O M E
. p r o f i l e / u s r / l o c a l / m e n u s / p r o f i l e s a l e s . p r o f i l e
a d m i n . p r o f i l e
$ H O M E s a l e s . p r o f i l e
$ H O M E a d m i n . p r o f i l e
t a rg e t _ p a t h l n
12 shell
m a t t y
( )
p r o f i l e4 0
/ u s r / o p t /
m o n i t o r / r e g s t a r / v a r / a d m / l o g s
$ ln -s /usr/opt/monitor/regstar/reg.log /var/adm/logs/monitor.log
7 7 7rwx rwx rwx
/ v a r / t m p
/ v a r / t m p( )
l n / v a r
/ t m p
/ v a r
1.10
chmod -R
s u i d
s u i d
1 13
s h e l l1 1.1 1.2 1.3 1.4 1.4.1 1.4.2 chmod 1.4.3 1.4.4 chmod 1.4.5
1.5 1.6 suid/guid1.6.1 suid/guid1.6.2 suid/guid
1.7 chown chgrp1.7.1 chown 1.7.2 chgrp 1.7.3 1.7.4
1.8 umask1.8.1 umask 1.8.2 umask
1.9 1.9.1 1.9.2
1.10
20.pdf
20
$ 1 . . $ 9 $ #
u s a g e
shift
getopts
shiftg e t o p t s
u s a g e c a s e
U N I XL I N U X
1 2
s h e l ls h i f t s h i f t$ 1$ 9
20.1 shift
s h i f t
w h i l e
20.1.1 shift
s h i f t
20.1.2
e v a l
eval echo \$$#s h i f tshift 'expr $# -2'
20 225
20.1.3 shift
s h i f t t r
-l
-u
s h i f t - l- u
u s a g e
c a s e s h i f t
u s a g e
c a s e c a s ec a s e
*- * - p- q
226 s h e l l
* f o r - f
c a s e
- l- u
T R C A S E
E X T . U C . L C
O P T y e sn o
t r t rc a s ef o r
20 227
228 s h e l l
-l -c 23 -v12
s h i f t g e t o p t s
20.2 getopts
g e t o p t s g e t o p t s
20.2.1 getopts
g e t o p t sg e t o p t s
a A L Lt r u e
h H E L Pt r u e
20 229
f F I L Et r u e
v V E R B O S Et r u e
f a l s e
g e t o p t s
getopts option_string variable
while getopts ahfgv OPTION
w h i l eo p t i o n _ s t r i n g5- a- h- f- g- v
v a r i a b l eO P T I O N
230 s h e l l
20.2.2 getopts
g e t o p t so p t i o n _ s t r i n g
g e t o p t s
o p t i o n _ s t r i n g O P T I O N
g e t o p t s O P T I O N
20.2.3 getopts
g e t o p t s
o p t i o n _ s t r i n g
getopts ahfvc: OPTION
ahfv c
O P TA R G
o p t i o n _ s t r i n g
while getopts :ahfgvc: OPTION
c a s e
g e t o p t s
20 231
- c
20.2.4
g e t o p t s
g e t o p t s
232 s h e l l
d
g e t o p t s O P TA R G
g e t o p t s
f o r t r- c a s e s h i f t
g e t o p t ss h i f t
20.2.5 getopts
t r- c a s eg e t o p t sg e t o p t ss h i f t
V E R B O S E
V E R B O S En o c a s e
y e s i f
/ d e v / n u l l
>/dev/null 2 >&1
V E R B O S E - v V E R B O S E
m y f i l e
tr-case -l -v myfile1 myfile2 ...
tr-case -v -l myfile1 myfile2 ...
g e t o p t s s h i f t
20 233
U N I XL I N U X
234 s h e l l
- a
- c
- d
- e
- f
- h
- i
- l
- o
- q
- p
-v
20.3
s h i f tg e t o p t sg e t o p t s
s h i f t
s h i f t $ 1 . . $ 9 s h i f t
20 235
20 20.1 shift 20.1.1 shift 20.1.2 20.1.3 shift
20.2 getopts20.2.1 getopts 20.2.2 getopts 20.2.3 getopts 20.2.4 20.2.5 getopts
20.3
21.pdf
21
s h e l l
t p u t
tput
t p u t GNU tput
t p u t / e t c / t e r m i n f o/ e t c / t e r m c a p
t p u t
21.1 tput
t p u t t p u t
$ tput init
t p u t /
21.1.1
b e l
b l i n k
b o l d
c i v i s
c l e a r
c n o r m
c u p xy
e l
e l l
s m s o
r m s o
s m u l
r m u l
s c
rc
s g r 0
r e v
21.1.2
c o l s
i t t a b
l i n e s
21.1.3
t p u t
c h t s
h s
21.2 tput
t p u t t p u t
21.2.1 tput
t p u t
variable_name='tput name'
21.2.2
i f t p u t
21.2.3 tput
tput belc l
21 237
21.2.4
1)
2) tput civis
2 5 l l2 5 h
[
U N I XL I N U X e c h o
\ 0 3 3 \e c h o @
echo @e c h o - e\ 1 0 0
v
echo \ 1 0 0
c l e a r h o m eV T
E S C I Je c h o
e c h o ' < CT R L - V> hit the key then [?25h'
< C T R L - V > ,
238 s h e l l
21.2.5
t p u t
cup r c
r c
21 239
21.2.6
t p u t
t p u t 2
1 0
centertxt 15 THE MAIN EVENT
centertxt 15 $1
21.2.7
t p u tt e r m i n f o t p u t
240 s h e l l
i n f o c m pt e r m i n f o
$ infocmp $TERM
t e r m p u t
21.2.8
c a t F 1cat -v
< C t r l - c >
c a tF 1^ [ O P ]F 2 ( [ O Q ] ) [ [ [ A ]
F 1F 2 c a t
21 241
21.2.9
A N S I
1.
3 0 3 4
3 1 3 5
3 2 3 6
3 3 3 7
2.
4 0 4 4
4 1 4 5
4 2 4 6
4 3 4 7
242 s h e l l
[background_number;foreground_number m
21.2.10
e c h o
e c h o
< C t r l - v >< E S C A P E > [ 4 032 m
e c h oc a s e
r e d - y e l l o w
colour red-yellow
e c h o . p r o f i l e
2 1 - 2
21 243
21-1 tput
2 1 - 1
244 s h e l l
21 245
21.2.11
w h i l e
r e a d _ c h a r t r a p
231 5
p r i v. u s e r
r o o t
d a v em a t t y p e t e rl o u i s e
246 s h e l l
F O U N D
U S E R
U S E R w h o a m i
c o n t i n u e
t e s t 10
p a s s w d
21-2
21 247
R e s t r i c t
2 1 - 2d a v e
248 s h e l l
21 249
250 s h e l l
p r o f i l ee x e c
U N I XL I N U Xs h e l l
21.3
t p u t
21 251
21 21.1 tput21.1.1 21.1.2 21.1.3
21.2 tput 21.2.1 tput 21.2.2 21.2.3 tput21.2.4 21.2.5 21.2.6 21.2.7 21.2.8 21.2.9 21.2.10 21.2.11
21.3
22.pdf
22
D B F I L E
1 0
2 0
2 0
-
IT
:::
t r a p231 5
22.1
1)
2)
r e a d _ a _ c h a r
22 253
g r e pg r e p_ C O D E a w k
0 g r e p$ _ C O D E \ >
254 s h e l l
w h i l e w h i l e
if ["$NUM"!=""]
i ft h e ne l s e
Staff Number:No Input DetectedThis Field Requires a Number
t h e n a _ n u m b e r
0 1
NU M_ PA S S0 1
l e n g t h _ c h e c k 1 0
1 001L E N _ PA S S0
1
c h e c k _ d u p l i c a t e
D U P L I C AT E0 0A N D
t h e n
w h i l eb r e a k
Staff Number : Non_Numeric or Too Many Numbers In Field
23
c h a r a c t e r s
22 255
c a s e5
c a s e
c o n t i n u e _ p r o m p t Y N YN
Ni f w h i l e
Y
echo "$NUM:$F_NAME:$S_NAME:$DEPART">>$DBFILE
s l e e p 1 s
D B F I L E
256 s h e l l
D B F I L E
22 257
258 s h e l l
22 259
260 s h e l l
22 261
262 s h e l l
22.2
1)
2)
3)
4)
g r e pa w k
1 0 0
a w ka w k
g r e p
a w kg r e pD B F I L E
a w k
I F S
I F S
I F S
S A V E D I F S = $ I F S
I F S = :
I F S
I F S = $ S A V E D I F S
g e t _ r e c
q
if ["$STR"!=""]t h e n
[-2 $STR]
0
b r e a k
n o
22 263
grep -v S T RS T R
g r e p D B F I L E
D B F I L E
264 s h e l l
22 265
22.3
{ d e f a u l t _ v a r i a b l e = v a r i a b l e }
266 s h e l l
grep -v
g r e p
grep -v $CODE $DBFILE >$HOLD1
D B F I L E
D B F I L E
22 267
268 s h e l l
22 269
22.4
c a t a w k
270 s h e l l
22 271
272 s h e l l
22.5
22 273
22 22.1 22.2 22.3 22.4 22.5
23.pdf
23
s h e l l
set
i ff i
s h e l l
s h e l l
23.1
23.1.1
f o rw h i l eu n t i lc a s e
d o n e w h i l e
w h i l e d o
23.1.2
s h e l l v i v iset nu
v i< E S C > set nu
s h e l l
23.1.3
- e q
[: missing ']'
23.1.4
23.1.5 for
f o r $
23.1.6 echo
e c h o e c h o
e c h o
e c h o
23.2 set
s e t s e t
set -n
set -v
set -x
s e t+-+-
s e t
f o r
set -x
23 275
s e t
23.3
s e te c h o
276 s h e l l
23 23.1 23.1.1 23.1.2 23.1.3 23.1.4 23.1.5 for 23.1.6 echo
23.2 set 23.3
24.pdf
24 shell
s h e l l s h e l l
Bourne shell / b i nu s r / b i n
Bourne shell
c dp w d
/ b i n / p w d
24.1 shell
2 4 - 1
24-1
t r u e
. s h e l l
b r e a k f o rw h i l eu n t i lc a s e
c d
c o n t i n u e
e c h o
e v a l
e x e c s h e l l
exit s h e l l
e x p o r t s h e l l
p w d
r e a d
r e a d o n l y
r e t u r n
s e t
s h i f t
test
t i m e s s h e l l
t r a p
u l i m i t s h e l l
u m a s k
u n s e t s h e l l
w a i t
24.1.1 pwd
$ pwd
/ t m p
24.1.2 set
s h e l l s e ts e t
s e t
set param1 param2 ..
a c c o u n t s . d o ca c c o u n t s . b a k
s e t
24.1.3 times
t i m e s s h e l l
t i m e s
24.1.4 type
t y p e t y p e
278 s h e l l
24.1.5 ulimit
u l i m i t s h e l l / e t c / p r o f i l e
s h e l l. p r o f i l e u l i m i t
ulimit options
u l i m i t
- a
- c
- f
u l i m i t
0
24.1.6 wait
w a i tw a i t I D
$ wait
24.2
s h e l l
24 s h e l l 279
24 shell 24.1 shell 24.1.1 pwd24.1.2 set24.1.3 times24.1.4 type24.1.5 ulimit24.1.6 wait
24.2
25.pdf
25 1
< P > < / P >
< B R >
< H R >
< P R E > < / P R E >
< B > < / B >
< I > < / I >
< O L > < / O L >
link
< F O R M > < / F O R M >
M E T H O D p o s tg e t
A C T I O N
< I N P U T. . . >
N A M E
S I Z E
T Y P E
< S E L E C T. . . >
N A M E
S I Z E
N A M E
< / S E L E C T >
a p a c h eWe b / e t c / h t t p d / l o g s/ u s r / l o c a l / a p a c h e / l o g s
We bc g i
c g i f i r s t p a g e . c g i
c g i - b i n 7 5 5
29 cgi 327
s h e l l e c h o M I M E
e c h o M I M E c g i
e c h o< H T M L > H T M L
H T M L < H 1 >< H n > < H 6 >
< H 2 >< C E N T E R >Stand-By To
S t a n d - To< / H T M L >
U R L
h t t p : / / y o u r _ s e r v e r / c g i - b i n / f i r s t p a g e . c g i
y o u r _ s e r v e r
D N S
I n t e r n e t
2 9 - 2
29-2 firstpage
29.4.2 shell
s h e l l
w h o w c
328 s h e l l
U S E R S
i f 1 0
< P R E > d f
e c h o < P R E >
< P R E >
U R L
h t t p : / / y o u r _ s e r v e r / c g i - b i n / p a g e t w o . c g i
y o u r _ s e r v e r
2 9 - 3
29-3 pagetwo.cgi
29 cgi 329
29.4.3 SSI
c g iWe b c g i
c g iH T M L
c g i ( S