You are on page 1of 356

shell


setuid
chownchgrp
umask

()

1)
2)
3) shell

1)
2)
3)

1.1





i


ls -l

shell

total 4232
- r w x r- x r- x 9
9 9

rwx

r-x

r-x

rwx

1
root
root root(root)
3578 K
Oct 14 04:44
dmesg

1.2

ls -l

d
l ( )
s
b
c
p
-

1.3
touch
$ touch myfile

ls -l

(
)

rw-

r--

admin

1-1 ls -l

( )( )rw( )r-( )r--

( )
1)
2) ( )
3)

r
w /
x
myfile
-

rw-

r--

r--

myfile

umask

(1-2)

1-2

r-- --- --r-- r-- --r-- r-- r-rwx r-- r-rwx r-x ---

( )

shell

()

rwx r-x r-x


rw- rw- --rw- rw- r-rw- rw- ---

1.4

( ) c h m o d

1.4.1
chmod
chmod [who] operator [permission] filename

who
u
g
o
a ( )
operator
+
-
=
permission
r
w
x
s set-ID
t *
l
u,g,o
* tt
t

t (
) t

1.4.2 chmod
c h m o d m y f i l e r w x
rwx rwx

chmod a-x myfile


chmod og-w myfile
chmod g+w myfile
chmod u+x myfile
chmod go+x myfile

rw- rw- rwrw- r-- r-rw- rw- r-rwx rw- r-rwx rwx r-x

myfile

( )

$ chmod u+x o-w myfile

m y f i l e a d m i n

$ chmod u+x dt

1.4.3
chmod
chmod [mode] file

mode

1-3
1-3 /

0400
0200
0100
0040
0020


0010
0004
0002
0001

1 - 3

1-37

shell

644
0400+0200( )

=0600

0040()

=0040

0004()

=0004
0644

1-4
1-4

r w x
4+2+1

r w x
4+2+1

r w x
4+2+1

1 - 4

myfile
r w -

r - -

4+2

r - 4

644
1.4.4 chmod
chmod

chmod 666
chmod 644
chmod 744
chmod 664
chmod 700
chmod 444

rw- rw- rwrw- r-- r-rwx r-- r-rw- rw- r-rwx --- --r-- r-- r--

yoa
admin

chmod 644*

-R
chmod -R 664 /usr/local/home/dave/*

/usr/local/home/dave
- R

1.4.5

1.5
chmod

1-51-6
1-5
r

1-6

drwx rwx r-x(775)


drwx r-x r--(754)
drwx r-x r-x(755)

- - x

docs
pay
admin
a d m i n

1.6 suid/guid
s u i dg u i d

shell

suid shell

g u i d

1.6.1 suid/guid

g u i d

UNIX suidguid /bin/sbin

$ ls -l | grep '^...s'

suid
$ ls -l | grep '^...s..s'

suidguid
suid
suid 4 guid
24+2
s x s u i dg u i d
guid
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 suid/guid

chmod 4755

rws r-x r-x

chmod 6711

rws --s --s

chmod 4764

rws rw- r--

s u i d

s u i dg u i d

s u i d

suid/guid rwx r-x r-x


suid
chmod u+s <filename>

rws r-x r-x


suid rwS r-x r-xS
suid
chmod
chmod

1.7 chownchgrp

/ e t c / p a s s w d
I D s u i d

chown
chmod -R -h owner file

- R - h

1.7.1 chown

project louise pauline


1.7.2 chgrp
chgrpchown

pauline adminsybadmin
1.7.3

10

shell

id

1.7.4

mattysybadminappsgenpost

1.8 umask
u m a s k
c h m o d u m a s k

umask
shellumask
u m a s k / e t c / p r o f i l e
umask
umask $HOME.profile.bash_profile
1.8.1 umask
u m a s k (
) u m a s k 6
c h m o d
umask 7

umask nnn

nnnumask000-777

umask
u m a s k u m a s k
1-8 umask
u m a s k /
umask
umask002 664775
u m a s k u m a s k

11

1-8 umask

umask
0
1
2
3
4
5
6
7

6
6
4
4
2
2
0
0

7
6
5
4
3
2
1
0

umask002
777( )
umask 002

umask002
1)

rwx rwx rwx (777)

2) umask002

- - - - - - -w-

3)

rwx rwx r-x (775)

4)

rw- rw- r-- (664)

umask022
1)

rwx rwx rwx (777)

2) umask022

- - - -w- -w-

3)

rwx r-x r-x (755)

4)

rw- r-- r-- (644)

1.8.2 umask
1-9 umask
1-9 umask
umask
022
027
002
006
007

755
750
775
771
770

umask umask

644
640
664
660
660

12

shell

umaskumask
$ umask 002

umask

u m a s k /
u m a s k 6 0 0 /
066

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
/usr/opt/app/log

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
admin.profile
$HOME sales.profile
$ 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

13

matty

( )

profile 40

/usr/opt/

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

/var /tmp
/ v a r / t m p( )
l n/ v a r
/tmp

/var

1.10

chmod -R

suid
suid

2 findxargs
(
)
F i n d

find
find
findx a rg s
find
( N F S )f i n d

find
(30G )
Find
find pathname -options [-print -exec -ok]

pathname find . /
-print find
-exec

find s h e l l ' c o m m -

and' {} \;{}\
-ok -exec shell

2.1 find
f i n d -

-name
-perm
-prune find -depth
-prunefind
-user
-group
-mtime -n +n -n n+n
nFind-atime-ctime -mtime

2 findxargs

15

-mtime
-nogroup /etc/groups
-nouser /etc/passwd
-newer file1 ! file2 file1 file2
-type
b -
d -
c -
p -
l -
f -
-size n[c] n c
-depth
-fstype

/etc/fstab
-mount mount
-follow find
-cpio cpio
2.1.1 name
f i n d

$ H O M E * . t x t
~'pathname~ $HOME
$ find ~ -name "*.txt" -print

*.txt
$ find . -name "*.txt" -print

$ find . -name "[A-Z]*" -print

/etc host
$ find /etc -name "host*" -print

$HOME
$ f i n d ~ - n a m e " * " - p r if
nt ind . -print

$ find / -name "*" -print

* . t x t
ax37.txt

16

shell

$ 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
007chmod
$ find . -perm -007 -print

2.1.3

- p r u n e - p r u n e
-depth -prune find
/apps /apps/bin
$ find /apps -name "/apps/bin" -prune -o -print

2.1.4 usernouser
$ H O M E
dave
$ find ~ -user dave -print

/etc uucp
$ find /etc -user uucp -print

- n o u s e r
/etc/passwd -nouser find
/home
$ find /home -nouser -print

2.1.5 groupnogroup
u s e rn o u s e r f i n d
/apps accts
$ find /apps -group accts -print

n o g r o u p f i n d

$ fine/-nogroup-print

2 findxargs

17

2.1.6
mtime
m t i m e
- n + n

5
$ find / -mtime -5 -print

/var/adm 3
$ find /var/adm -mtime +3 -print

2.1.7
- n e w e r

newest_file_name ! oldest_file_name

find age.awk belts.awk

find

t o u c h

2 3 : 4 0

21:40
f i n d- n e w e r

$ find . -newer dstamp -print

2.1.8 type
UNIXLINUX

18

shell

/etc
$ find /etc -type d -print

$ find . ! -type d -print

/etc
$ find /etc -type l -print

2.1.9 size
b l o c k
N c

1M
$ find . -size +1000000c -print

/home/apache 100
$ find /home/apache -size 100c -print

10 512
$ find . -size +10 -print

2.1.10 depth
f i n d d e p t h
find find

f i n d C O N . F I L E

$ find / -name "CON.FILE" -depth -print

2.1.11 mount
f i n d m o u n t
XC
$ find . -name "*.XC" -mount -print

2.1.12 cpio
c p i o f i n d
cpio
c p i o / e t c/ h o m e/ a p p s

19

2 findxargs

\shell \
/

/ e t c / e t c
f i n d / e t c / h o m e/ a p p s
cpio
cpio C65536 B
5 1 2 C 6 5 5 3 6

6 4 K

65536/1024
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 find-exec

find -execls -l

/logs 5
$ find logs -type f -mtime +5 -exec rm {} \;

shell
mvrm -exec
f i n d . L O G
5

y n
-exec grepfind

20

shell

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
grep rounder

2.1.14 find
find find
$HOME
$ find $HOME -print
$ find ~ -print

suid

$ find . -type f -perm 4755 -print

0
$ find / -type f -size 0 -exec ls -l {} \;

/var/logs 7
$ find /var/logs -type f -mtime +7 -exec rm {} \;

audit
$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
999
$ f i n d / l o g s - n a m e ' a d m i n . l o g [ 0 - 9 ] [ 0 - 9 ]'[
-0
at9
i]
me +7 -exec rm {} \;

$ find . -type d -print -local -mount |sort

rmt
$ 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

2 findxargs

21

x a rg s x a rg s

xargsfind
x a rg s

( c o r e d u m p )

/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

grep device
$ find / -type f -print | xargs grep "device"

grep DBO
$ f i n d . - n a m e \ type f -print | xargs grep "DBO"

\find*shell

2.3
f i n d e x e c
x a rg s

crontab
at

nohup

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

cron.denycron.allow crontab
3.1.1 crontab
c r o n t a b

159

1230

131

112

060

23

crontab
<><><><><>
<>
C r o n t a b

-
1 - 5,
1 , 4 *
* 5
#
3.1.2 crontab
crontab
30 21* * * /apps/bin/cleanup.sh

21:30/apps/bincleanup.sh
45 4 1,10,22 * * /apps/bin/backup.sh

110224:45/apps/binbackup.sh
10 1 * * 6,0 /bin/find -name "core" -exec rm {} \;

1:10find
0,30 18-23 * * * /apps/bin/dbcheck.sh

18:0023:0030/apps/bindbcheck.sh
0 23 * * 6 /apps/bin/qtrend.sh

11:00pm/apps/binqtrend.sh
c r o n t a bs h e l l
c r o n
cron cron
s h e l l

cron
3.1.3 crontab
crontab
Crontab [-u user] -e -l -r

-u
-e crontab
-l crontab
-r crontab
- u c r o n t a b

24

shell

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 b 9 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
tty1

crontab cron
$ crontab davecron

cron 15
/var/spool/cron
dave
3.1.5 crontab
crontab

$ H O M E c r o n t a b

$ crontab -l > $HOME/mycron

crontab
3.1.6 crontab
crontab EDITOR vi
vicrontab
$ crontab -e

v i c r o n t a b

25

c r o n

crontab

c r o n t a b

crontab -l

3.1.7 crontab
crontab
$ crontab -r

3.1.8 crontab
c r o n t a b $ H O M E
/var/spool/cron/<username><username>

$ crontab <filename>

<filename>$HOME
$ H O M E
crontab re
crontab
c r o n t a b c r o n t a b
crontab delete
<Ctrl-D> crontab

3.2 at
a t c r o n
10min
crontab
a t c r o n t a b

c r o n t a b / e t c a t . a l l o wa t . d e n y

26

shell

at at crontab

at
at [-f script] [-m -l -r] [time] [date]

-f script
-l atq
-r

I D U N I X

atrm
-m
time

at HH H . H H M MH H : M MH : MHM

a.m.p.m.
date

at todaytomorrow

3.2.1 at
at at
at shell

at / at
<CTRL-D>

< E O T >< C T R L - D >2 1 : 1 0 f i n d


job 1

/at

27

at shell -f

db_table.sh 3:00
echoat
$ echo find /etc -name "passwd" -print | at now +1 minute

3.2.2
at -l

/ aa t
a t q a t
/var/spool/at

3.2.3

a t r m [ j o b n o ]a t - r [ j o b n o ]

at -l
at -r

at-r [job no]

3.3 &

28

shell

&

&

find shell

command >out.file 2>&1 &

out.file

3.3.1
f i n d s r m . c o n f
find.dt

27015

p s 1

3.3.2 ps

ps1 psgrep

ps x

ps
3.3.3
k i l l s h e l l

29

kill
kill -signal [process_number]

( )

kill

nohup

3.4 nohup

nohup Nohup (no


hang up)

nohup command &

3.4.1 nohup
n o h u p
nohup.out
nohup command > myout.file 2>&1

myout.file

ps1

shell

ps x ps -ef|grep ps1
3.4.2
s h e l l n o h u p

30

shell

$ chmod 744 quarterend

qtr.out

3.5

C r o n

S h e l l

*

[...] [ ]
[!...] [ ]
s h e l l

4.1 *
* app*
app

* *.doc .doc

* c l * . s e d c l
.sed

c d

32

shell

4.2

c o n f . l o g

f ? ? * s f
s

4.3 [...][!...]
[...] [ ] -
io

l o g .
log.[0-9]*[0-9] *

[ ! 0 - 9 ] * !

LPS1

33

LPS

$ ls [A-Z]*

$ ls [a-z]*

$ ls [0-9]*

. .profile.rhosts.history

$ ls .*

4.4

5 shell
shell



shell

5.1 echo
echo
echo string

echo
\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

5 shell

35
()

$ echo -n "What is your name :"

-e

echo \n

echo \

LINUX...
- e

>
myfile
$ echo "The log files have all been done"> myfile

$ echo "$LOGNAME carried them out at `date`">>myfile

myfile

s h e l l e c h o
\s h e l l
echo/dev/rmt0 \
$ echo "\"/dev/rmt0"\"
"/dev/rmt0"

5.2 read
read

36

shell

r e a d

read varible1 varible2 ...

s h e l l

Shell

John Lemon Doe

shell read

LINUX......
-n

5 shell

37

5.3 cat
c a t
c a t
m o r e c a t

$ cat myfile | more

$ cat myfile | pg

cat
cat [options] filename1 ... filename2 ...

cat
-v
myfile
$ cat myfile

myfile1myfile2myfile3
$ cat myfile1 myfile2 myfile3

bigfile

$ cat myfile1 myfile2 myfile3 > bigfile

c a t
c a t
<CTRL-D>

c a t D O Sf t p
<CTRL-M>

c a t

38

shell

<CTRL-D>

5.4
|

1 |2
|

s h e l l

grep quarter1.doc

5-1

Is

5-1

sedawkgrep who
awk

d f a w k
a w k a w k g r e p
filesystem

/ d e v /
sed

5 shell

39

$ sort myfile | lp

5.5 tee
t e e T

tee -a files

-a
tee
w h o w h o . o u t

5-2

who.out

screen
who

$ who

5-2 tee

t a p e . l o g
t e e - a

\s h e l l

e c h o

40

shell

$ echo "stand-by disk cleanup starting in 1 minute"| tee /dev/console

-a

5.6
s h e l l
shell

0
1
2

12 012
39
5.6.1
0
5.6.2
1
5.6.3
2

5.7

5 shell

41

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

commandfilename

command << delimiter

delimiter

command <&m

command >&m

command <&-

5.7.1
/ e t c / p a s s w d I D
sort.out sort
( ) s o r t

$ cat passwd | awk -F: '{print $1}' | sort

1>sort.out

5-1
$ cat passwd | awk -F: '{print $1}' | sort

>sort.out

account file.out
> f i l e n a m e l s
ls.out
$ ls >ls.out

( )
>>filename

0 '>filename'
$ >myfile

42

shell

5.7.2
awk
$ sort

< name.txt

s o r t

$ sort name.txt

s o r t n a m e . o u t
( )
$ sort

<name.txt >name.out

louise contents.txt
$ mail louise < contents.txt

command << delimiter


shelldelimiter
s h e l l
delimiter
E O F M AY D AY < <
myfile TERMLOGNAME

5.7.3
2
grep missilestrident

g r e p
/dev/null( )
$ grep "trident" missiles 2>/dev/null

/dev/null

grep.err

5 shell

43

g r e p > >
( )

5.8

( ) accounts.out
$ cat account_qtr.doc account_end.doc 1>accounts.out 2>accounts.err

accounts.err

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

44

shell

( i s q l

s y b a s e )f t p

5.10 exec
exec shell shell
shell
exec command

command shell
exec shell
e x e c
. p r o f i l e
shell exec
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 line1line2

stock.txt

cp

5 shell

45

5.12
s h e l l

(39)

&&|| shell
Shell shellshell {}

6.1 &&
&&
1 & & 2

& & 1 (0
& & 2 & &

&&

& & & & e c h o

$ mv /apps/bin /apps/dev/bin && rm -r /apps/bin

/apps/bin /apps/dev/bin
/apps/bin
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
quarter.sorted
$ sort quarter_end.txt > quarter.sorted && lp quarter.sorted

6.2 ||
||
1 | | 2

47

| | | | 1 | |
2 ||
||

||
1 5

m o n t h _ e n d . t x t c o m e t
shell shell
$ comet month_end.txt || exit

6.3 { }
s h e l l s h e l l
shell
s h e l l

1;2;...

{ } s h e l l s h e l l
{ } s h e l l
shell
{1;2;...}

&&||
c o m e t

$ comet month_end.txt || exit

s h e l l
exit
&&
$ sort quarter_end.txt > quarter.sorted && lp quarter.sorted

s o r t

48

shell

6.4
s h e l l & &| |

&&||


7
UNIXLINUX
s h e l l
s h e l l





RE

AAx x

grepsed {\\}
awk
7-1
^
$
*
[]
\
.
pattern\{n\}
pattern\{n\}m
pattern\{nm\}

*0
[ ] [] [1-5][12345]
s h e l l
\

pattern n
n
pattern nm

50

7.1
. beg
beg.n.
ls -l
...x..x..x

1 0 4 X C

. . . .X C. . . .

456XC4

ASCII

7.2 ^
^ ls -l
ls -l d

1^001 001

^...4XC....

51

3 4 X C 4 ^

41
^...1

4comp
^comp

4 c o m p i n g

^comp..ing

7.3 $
$^ $
trouble
trouble$

1d$ 1d

^$

^.$

jet01
jet01$

7.4 *

compu*t

10133*

52

7.5 \

\.

^
\^
*.pas
\*\.pas

7.6 []
[]

- - -

[]

[0123456789]

-
[0-9]

[a-z]

[A-Za-z]

A-Za-z

[A-Za-z0-9]

[ ] s
t
s[a-z A-Z]t

53

s[a-z]t

Computercomputer
[Cc]omputer

Scoutshoutbought
[ou] .*t

ou t
system S
[ S,s]ystem\.

[ ] *[ ] [ A - Z a - Z ] *

[A-Za-z]*

^
[^a-zA-Z]

[^0-9]

7.7 \{\}
* \ { \ }

pattern\{n\} n
pattern\{n,\} n
pattern\{n,m} nmn,m0-255
A B
A\{2\}B

AAB
A4
A\{4,\}B

AAAABAAAAAAAB AAAB
A24
A\{2,4\}B

AABAAABAAAABABAAAAAB

4 xx4

54

[ 0 - 9 ] \ { 4 \ }X X[ 0 - 9 ] \ { 4 \ }

1) 4
2) xx
3) 4

7-2
7-2
^

^[the]

the

[Ss]igna[lL]

s i g n a l s i g n a L
SignalSignaL

[Ss]igna[lL]\.

[mayMAY]

m a y

^USER$

USER

[tty]$

tty

\.

^d..x..x..x

^[^l]

[.*0]

[000*]

000

[iI]

[iI][nN]

in

[^$]

[^.*$]

^......$

[a- zA-Z]

[a-z][a-z]*

[^0-9\$]

[^0-0A-Za-z]

[123]

13

[Dd]evice

deviceDevice

De..ce

D e
ce

55

\^q

^q

^.$

^\.[0-9][0-9]

'"Device"'

device

De[Vv]ice\.

Devicedevice

[0-9]\{2\}-[0-9]\{2\}-[0-9]\{4\}
[0-9]\{3\}\.[0-9]\{3\}\.[0-9]\{3\}\.[0-9]\{3\}
[^.*$]

dd-mm-yyyy
IPnnn. nnn.nnn.nnn

7.8
s h e l l

grep,sedawk

8 grep
g r e pU N I XL I N U X g r e p
grep grep
grep
Grepgrep
E g r e p g r e p \ q

F g r e pg r e p f a s t g r e p

grep
grep


grep grep
g r e p GNU grep

g r e p g r e pf g r e p
egrepgrep
<Tab>g r e p
data..f
data.f
1
2
3
4
5
6
7

8 grep

57

8.1 grep
grep
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$MYVAR

8.1.2 grep
grep
-c
-i
-h
-l
-n
-s
-v
8.1.3
.doc sort
$ grep "sort"*.doc

sort it
$ grep "sort it" *

grep
8.1.4
$ grep -c "48"data.f
$4

grep4 4 48
48 4

58

8.1.5

48
8.1.6
48

8.1.7
4 8 4 8 44 8 3
48 48
<Tab>

<Tab>tab
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

8 grep

59

8.2.1
484483 []
4834 484483

8.2.2
48 ^

8.2.3
- i S e p t [ ]
Septsept

S e p t 4 8 3
| |

grep grep
8.2.4
L D 5

8.2.5
51 9 9 61 9 9 8
5 . . 1 9 9 [ 6 , 8 ] 5 1 9 9 6
8

60

1 9 9 8 [ 0 - 9 ] \ { 3 \ } [ 8 ]
38

8.2.6
[]
05 06

8.2.7
4

4
9999

9
26
8263

8 grep

61

8.2.8 grep
g r e p - E 2 1 9
216

8.2.9
^$ -n

8.2.10
$ . ' " * [] ^ | \ + ? ,\.

conftroll.conf

8.2.11

filename.deposit

8.2.12 IP
D N S I P
I P2 0 0 0 n n n . n n n
nnn.nn.. nnn.nnn IP [0-9]\{3\}\.[0-0\{3\}\
3 3

62

8.3
grep
8-1

[[:upper:]]
[[:lower:]]
[[:digit:]]

[A-Z]
[a-z]
[0-9]

[[:alnum:]]
[[:space:]]
[[:alpha:]]

[0-9a-zA-Z]
tab
[a-zA-Z]

PD

*
grep*

grep

device

8.4 grep
g r e p

8 grep

63

|
8.4.1

8.4.2 passwd

/etc/passwdlouise
grep'No such file or directory'
grep-s

grep -s

2 > $ 1
/dev/null

grepexit
grep
/tmppasswd.out
8.4.3 ps
ps x g r e p ps x
DNS named

g r e p g r e p ps x g r e p
-v psgrep

64

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 grepstrings 48447

d a t a . f4 8 44 7 - f

32L2CC| |

| l o u i s em a t t ypauline
who egrep

^ 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

8 grep

65

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

9 AWK
awk

awkshell
a w k Bailing out
awk:cmd.Line: awk shellawk
awk awk grepsed shell

a w k a w k a w k
awk




awk
awk
a w k s e dg r e p

awk
a w k A h o . We n i n b e rg e rK e r n i g h a m n a w kg a w k

a w k a w k
awk

9.1 awk
awk
commandsawk
[ - F ] a w k
p a s s w d
-F
a w k a w k a w k

awk

9 AWK

67

- 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
awkawk
- F a w k
-Fawk
awk

9 - 1a w k # n
a w k

9-1 awk
1
P.Bunny(1)
J.Troll(2)

#
#

2
02/99
07/99

#
#

48
4842

#
#

Yellow \n
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
awk
{} if
looping awk

9.2.2
a w k $ 1$ 2 . . . $ n

$ 1 , $ 3 13 5
$ 1 , $ 2 , $ 3 , $ 4 , $ 5 $ 0 Aw k

$shell$
print awk

68

1.
g r a d e . t x t

712345
67
-F

2. awk
s h e l l a w k >
wow

t e e
d e l e t e _ m e _ a n d _ d i e
awk | tee delete_me_and_die
3.
awk
awk

4.
awk {print $0}()

9 AWK

69

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
awk

7.
end of report ENDEND
E N D

8. awk
a w k a w k

awk

70

awk
awk
awk


awk

9. awk
grade.txt

BEGIN awk shell


a w k a w k
<Ct r l - D > a w k

9.2.3 awk
g r e p
awk
G r e e n/ G r e e n /
Green
9.2.4
a w k 7

\ ^ $ . [] | () * + ?

7 awk grepsed
+

/XY?Z/XYZYZ
9.2.5
9-2awk

9 AWK

71

9-2 awk

<
<=
==
!=


>=
~

!~

1.
i f a w k
if
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

brown

2.
4 8 4 8
field-3 48awk 48

4 8 = = $ 3 = =4 8 4 8

3.
~ !~
b r o w n $0 !~/brown/
brown
awk

72

field-4

awk$4 !="brown"{print $0} grade.txt


brownbrownbrown-2brown-3 brown-2

4.
f i e l d - 6
field-7

5.

6.

7.
[] []
green /[Gg]reen/

8.
a . / ^ . . . a /
a

9.
yellowbrown | |

9 AWK

73

YellowBrown
Greengreen []

10.
48 ^
awk 7 7
awk

&& AND :
|| OR
!
11. AND
P. B u n n y Ye l l o w ( $ 1 = = " P. B u n n y " & &
$4=="Yellow")&&

12. Or
Ye l l o wB r o w n | |

9.2.6 awk
a w k 9 - 3

9-3 awk
ARGC
ARGV
ENVIRON
FILENAME
FNR
FS

awk

-F

74

()

NF
NR
OFS
ORS
RS

A R G C a w k A R G VA R G C
ARGV[n]n
E N V I R O N
ENVIRON[EDITOR]=Vi
F I L E N A M Ea w k a w k

F N R a w k N R

FSawk -F
FS=""
NF
OFS #OFS="#"
ORS \n
RS (\n)
9.2.7 NFNRFILENAME
awk
N R
N R
print NREND
N F
END

B r o w n A N D
Brown

9 AWK

75

NF $PWDawk
/

9.2.8 awk
awk

= += *= / = %= ^ =

|| && !
~ ~
!
< <= == != >>
+ - * / % ^
+ + --

1.
a w k
n a m e = $ nn a m e n
n a m e b e l t n a m e = $ 1 ; b e l t s = $ 4 a w k
n a m e b e l t s Ye l l o w

2.

1) BEGIN
2)
BEGIN awk

27
2727

76

BASELINEBEGIN

3.
awk
awkawkNRNF
$1=$1+5 15

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.
awk
{$4=$2+$3} 3
4 23
g r a d e . t x t 8
{ $ 8 = $ 7 - $ 6 }
BEGINtab

9 AWK

77

7.
+ =
$ 1 t o t a l t o t a l + = $ 1
awk
t o t + = $ 6t o ta w k
6 E N D 6 a w k

8.

ls -l awkawk d
END
ls -l d
5 9

d ^[^d]
tot

78

9.2.9
awk 9-4
9-4 awk
gsub(r,s)
gsub(r,s,t)
index(s,t)
length(s)
match(s,r)
split(s,a,fs)
sprint(fmt,exp)
sub(r,s)
substr(s,p)
substr(s,p,n)

$0sr
tsr
st
s
s r
fssa
fmt exp
$0 s
sp
sp n

g s u b s e d
$ 0 g s u b
$0
indexst s tlength s
m a t c h s r s p l i t f s
s as p r i n tp r i n t f f m t
e x ps u brs s $ 0 r
subspsp substrspn n
awk
1. gsub
/ /
/ 48424899

2. index
st
Bunnyny

3. length
J . Tr o l l

9 AWK

79

4. match
m a t c h
0 A N C D d
0 ANCDD ANCDD
J.Luluu

5. split
s p l i t
- AD2 - 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

splitmyarray myarray

6. sub
s u b S T Rpoped popo pill
s u bs u b/ o p /" o p "S T R o p
pOPed pope pill
J.Troll
2 9 2 4 s u b/ 2 6 /" 2 9 "$ 0
24J.Troll

7. substr
substr

1 5

80

a w k L Ta n s l - e y
3 7 99awk

s u b s t r
1

B E G I N E N D t

8. shellawk
awk
a w k a w k

stand-byawk

awk

awk

9.2.10

\ n
\n
{ } / \ { /a w k

9-5awk
9-5 awk
\b
\f
\n
\r

\t
\ddd
\c

tab

\\

9 AWK

81

May Day t a b May Day


104141171 Day

\104DASCII\141aASCII
9.2.11 awkprintf
t a b a w k
printf
p r i n t f %

printf printf[ ]
9.2.12 printf
9-6 awk printf
Width
.prec

00

9-7 awk printf


%c
%d
%e
%f
%g
%o
%s
%x

ASCII

123.44
awk ef

1.
A S C I I6 5 6 5a w kp r i n t fA S C I I
printf

awk

9 9 9

2.

82

1 5 \ n

p r i n t
printf

3. awk
awk awk
awk awk
awk =

awk
A G E1 0 a w k 1 0

awk

df -k a w k 4 $ 4 ~ / ^ [ 0 - 9 ] /
1 0 2 4 d f i f ( $ 4 < T R I G G E R ) T R I G G E R

df -k

df
a w k w h o w h o

a w k L O G N A M E
who awk

9 AWK

83

root
root you are connected to ttyp1

4. awk
awk
a w k

awk
awk tot+=$6 END{print "club student total points"tot} grade.txt
s t u d e n t _ t o t . a w k a w k a w k
awk

/bin/awk -f
awk

84

E R R O R *
awk
awk

awk

awk

5. awkFS
FS#
FS

9 AWK

85

a w k F S B E G I N a w k

F S / e t c / p a s s w d 1 5;
passwd 1 5

6. awk
awkawk
awk script_file var=value input_file

NFMAX

/etc/passwdpasswd7
awk

86

awkdu

du awk

9.2.13 awk
split

splitmyarray myarray

For (element in array ) print array[element]

1 2 3 # 4 5 6 # 6 7 8 s p l i t

/dev/null

9 AWK

87

split

1) YellowOrangeRed
2)
2 0 6 0
awk
awk

88

B E G I N F S # Ye l l o wO r a n g eR e d

B E G I N B E G I N

color 1
YellowOrangeRed
S e n i o r _ o r _ j u n i o r 2 j u n i o r
senior
END
\ a w k

9.3
awk
a w k a w k a w ks h e l l
shell awk

10

sed

s e d
s e d
Vi s e d s e d
s e d





sed
s e d s e da w k
s e d s e d

sed
s e d
sed sed
g r e pa w k s e d
grepawk

10.1 sed
s e d

10.2 sed
s e d s e d s e ds e d
sed
sed
sed [] sed

sed sed
sed
sed []

-f

sed

sedsed

90

s e d []

s h e l l s e d

sed
n sedp

c sed

f s e d s e d s e d
sed -f myscript.sed input_filemyscript.sedsed
10.2.1 sed

s e d m y o u t f i l e

10.2.2 sed
sed
1)
2) 7
10-1sed
10-1 sed
x
x,y
/pattern/
/pattern/pattern/
pattern/,x
x,/pattern/
x,y!

x 1
xy25 25
/disk//[a-z]/
/disk/disks/
/ribbon/,3
3./vdu/
xy1,2!

10.2.3 sed
10-2Sed
10-2 sed
p
=
a\
i\
d
c\

10 sed

91
()

s
r
w
q
l
{}
n
g
y
n

ASCII

2/pattern n/

sed quote.txt

10.3 sed
s e d
\ 7 7
sed

10.4 sed
sed
10.4.1 print
print [address[address]P sed

- n

10.4.2
13

92

10.4.3
Neave /pattern//Neave/

10.4.4
s e d
quote.txt
thesedthe

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 /
ing

10.4.8

10 sed

93

10.4.9
$$

10.4.10
= /pattern/=

-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
sed
s e d

a\ seda\
s e d
sed
s e d s h e l l

sed

94

10.4.12 sed
append.sed

file not found .\


sed sed
/bin
/company/

a\sed

10.4.13

attendance utter confusion followed

10 sed

95

10.4.14

The honeysuckle band played all night long for only $90The office Dibble
band played well / H o n e y s u c k l e /s e d
change.sed

chmod u+x change.sed

96

10.4.15
sed
[ a ddress[address]]d

1d

Neave

10.4.16

[ a ddress[a d d r e s s ] ] s / 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 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

10 sed

97

n i g h tN I G H T n i g h t N I G H T

$ 9 0 $

replacement-pattern sed

g T h e
Wow

w s p l e n d i d S P L E N D I D
sed.out
sed

10.5
& &

&
seds/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

98

[ a ddress[a d d r e s s ] ] w f i l e n a m e

w sed filename
quote.txt 12filedt

Neave filedht

10.7
s e d

address r filename

rsed filename
sedex.txt

sedex.txt quote.txt /company/

10.8
sed
address q

/ . a . * / a 0

qsed

10 sed

99

10.9

cat -v filename

cat filenamecat-v
sed
[ a d dress[address]]l

l
l
1$
cat

sed

s e d \ 0 3 3 O PF 1

t e r m i n f ot e r m c a p
F1vi
vi

<Ctrl> <v> a^

F1[OP]
<ESC>F1

10.10 sed
sed sed

10.10.1
sed
dos.txt

100

1) ##
2) 000
3) ^M
^ @^ L

dos.txt
1 #
#

2 0^ ^0* 0
s/^0*//g

3 ^ M
s/^m//g^M
^ M F 1 sed s/
< C t r l >v v ^ < C t r l >
<return> ^M
s e d

c a t s e d s e d
sed

10 sed

101

sed sed
10.10.2

sql

1) s/-*//g------
2) /^$/d
3) $d
4) 1d
5) awk {print $1}
cat sed

10.10.3
U N HU N D
UNHUND

[ 0 - 9 ]

102

10.10.4

passed
$

10.10.5 shellsed
sed

10.10.6 sedshell
s e d s h e l l
NEW-NAME sed

10.11
[] [ ]tab
s/\.$//g
-e /abcd/d
s/[][][]*/[]/g
s/^[][]*//g
s/\.[][]*/[]/g
/^$/d
s/^.//g
s/COL\(...\)//g
s/^\///g
s/[]/[]//g
S/^[]//g
s/[]*//g

abcd

COL
\
tab
tab
tab

s h e l l

10 sed

103

1. \
sed\

2. /
"Mr Willis" sedMr"Bruce"

3.
sedaccounts.doc

4.
sedaccounts.doc

5.
sed.docaccounts

6.
x

sed

10.12
sed sed
sed sed

s e d

11
P I C KU N I X P I C K
P I C K

sort
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
sort
sort
s o r t s o r t
sort
sort uniqjoincutpastesplit
sort
11.1.2 sort
sort
sort -cmu -o output_file [other options] +pos1 +pos2 input_files

sort
-c
-m
-u
-o sort

11

105

-b
-n
-t tab
-r
+n n
n n +n
post1 mnmn 465 7

11.1.3
-o results.out

11.1.4 sort
s o r t - t

s o r t - t
01 sort
v i d e o . t x t1
234 -t

11.1.5 sort
s o r t 01 s o r t

sort 0 01 1
11.1.6
30 400 sort-c

106

sort

11.1.7 sort
sortsort filename 0 sort
sort

11.1.8 sort
sort -r sort
0

11.1.9
2 1 t 1
1 1 23

11.1.10
t3

11

107

-n

- n 3
2 t2

3
The Hill sort 3

-n

A l i e n s - r A l i e n s

11.1.11
- u
Alien Alien

-u sort

108

11.1.12 ksort
s o r t k 1 1
1 s o r t
k
1 -k4

11.1.13 k
4 1 -k4 -k1

11.1.14 sort
- n s o r t

02 3
11.1.15 pos

field_number characters_in

11

109

+ 1 . 2 1 3

11.1.16 headtail
s o r t
4- k 4 s o r t
head head -1

tailhead 1
2 tail -1 s o r t t a i l

headtail head
Tail
headtail 10
20
7

11.1.17 awksort
s o r t a w k
s o r t a w k

110

11.1.18

sort -m sorted_file1 sorted_file2

-m +o video.sort
+o

11.2 sort
s o r t / e t c / p a s s w d 1
awkawk

sort df df

- b 4+ 4

I P I P
I P

11

111

I P 3

11.3 uniq
uniq uniq

u n i qs o r t
s o r t u n i q
uniq

u n i q May Day 4
May Day uniq

-u
-d
-c
-f n n
-f -n
myfile.txt uniq

5 May Day sort -u May Day


Going Down

112

-c May Day

1.
-d

2.
- n - 5 5 1

1 2 - n 2 2

uniq

1 uniq OP

-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
join

t a b
join 20 20DBMS
join

11

113

an n n - a 1
-a2
o n.m n m 1 . 3 1 nm
1.32.1
j n m n m
t tab -t
name.txt
town.txt

M . G o l l s 12 Hidd Rd
0 join

join
1.
j o i n
-a

P. H e l l e r

2.
- o j o i n

1.12.2

114

-jn m 132

p e r s I D p e r s 2 I D
pers4 pers22

join 4join
5 awk $ awk '{print $4}'

11.5 cut
c u t

cut
cut [options] file1 file2

-c list
-f field
-d tab
-c
-c15-7 1 57
-c1-50 50
-f -c
-f 15 15
-f110-12 11012
pers'pers'

11

115

11.5.1
-d -d 3
-f3ID

11.5.2
cut 13 ID

/etc/passwd 13

-c

cut

ls -l -c

ls -l cut -c1-10

116

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
paste
paste -d -s -file1 file2

-d tab @-d@
-s
- ls -l |paste

paste

11.6.1

11.6.2
tab -d

-s
ID

11

117

11.6.3 paste
p a s t e - -
4

11.7 split
split
vi sort

split
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 t o u t p u t - f i l e - s i z e
1000 2800 3
10001000800 x[aa]x[zz]x [aa][zz]

bigone.txt2800split

output-file-size 6

118

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

12 tr
12.1 tr
t r t r
tr 12
tr 1 2




tr
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 riannpsulta_t e _ t o " ]
file

-c 1 ASCII
-d 1
-s

Input-file
12.1.1
tr
12
[a-z]

a-z

[A-Z] A-Z
[0-9]

/octal ASCII
[O*n] O n[O*2]OO
tr [class]
c n t r l 1 2 - 1

[ ]
[\ 0 1 2]\ 0 1 2t r

tr

120

\{
12-1 tr

\a
\b
\f
\n
\r
\t
\v

Ctrl-G
Ctrl-H
Ctrl-L
Ctrl-J
Ctrl-M
Ctrl-I tab
Ctrl-X

\007
\010
\014
\012
\015
\011
\030

12.1.2
r e s u l t s . t x t
cops.txt

12.1.3
vi

-s [a-z]
tr

cat tr

12.1.4
plane.txt

12

tr

121

-s \012

\n

12.1.5
t r [ a - z ]
[A-Z]
tr

[lower][upper]

file-to-translate new-file-name

12.1.6

file-to-translate new-file-name

12.1.7
-c-s

[a-z][A-Z]tr -cs "[a-z][A-Z]""[\012*]"

122

[ a - z ][ A - Z ] 1
-s -c tr

12.1.8
tr dosUNIX ftp

c a t
-v

^^^^^^tabCtrl-M Ctrl-Z
- s A S C I I^ 1 3 6^ M0 1 5t a b0 11^ Z0 3 2 ,

tab^^^^^^"\136""[\011*]" stat.tmp

^M\n^Z stat.tmp

12.1.9
^M

12

tr

123

DosUNIX
^M^Z
tab
p a s s w d t a b
tab 011passwd tr

tab

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
trtr


13

/ e t c / p a s s w d


/etc/passwd
$HOME.profile
$HOME.profile
/etc/passwd
7

1 2 5 6
7 shell/bin/sh Bourne 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

profile

13.1 /etc/profile
/etcprofile

PATH


126

PAT H

/etc/profile

13

127

profile
QUIT <Ctrl-c>
L O G N A M E m a n M A N PAT H
man
vt220

umask

<Ctrl-C>QUIT
stty

128

/var/adm/messages
ulimit
idnkpsalomdave

profile

13.2 $HOME.profile
/ e t c / p r o f i l e $ H O M E p a s s w d
$HOME2

. p r o f i l e s h e l l
/etc/profile .profile
shell
. p r o f i l e p r o f i l e
.profile uset /etc/profile
.profile .profile

E D I TO R c r o n
TERM vt100vt220
b i n p a t h b i n
PAT H

pwd
A S C I I
251 169

13

129

LINUX
echo
/usr/admin
ADMIN=/usr/adm

whowc

.profile .profile/etc/profile

./pathname/filename

.profile
$. .profile

$. ./profile

.profile

13.3 stty
stty stty stty -a

130

s t t y
^? <Ctrl-H> stty

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'vi
CtrlVV H
stty

intr
echo
-echo
eof
kill
start
stop

^C

^D
^Y
^Q
^S

echo
echo

stty
stty -g

s t t y s t t y
/ e t c / p r o f i l e stty -g
stty
stty
s t t y stty -g e c h o s t t y

LINUX
LINUX echo -eecho -e

13

131

s t t y s t t y

13.4 .logout
Bourne shellshell .logout exit

t r a p t r a pBourne shell
.logout .profile
trap "$HOME /.logout"0

.logout

. l o g o u t s h e l l 0
shell shell .profiletrap
.logout

13.5
. p r o f i l e

14 shell
s h e l l s h e l l s h e l l
shell
4
shell

shell





14.1 shell

EDITOR
E D I TO R c r o n
E D I TO R
EDITOR
vi

$ isql -Udavet -Pabcd -Smethsys

-S DSQUERY
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
shell
14-1
s h e l l

14 shell

133

$ variable-name=valu
e ${variable-name=value}

s h e l l

14-1
Variable-name=value
Variable-name+value
Variable-name:?value
Variable-name?value
Variable-name:=value
Variable-name:-value

variable-name
variable-name
variable-name
variable-name
variable-name
variable-name

14.2.1
echo $

LOGNAME error-msg

s h e l l $ L O G N A M E

14.2.2
unset
unset variable-name

14.2.3 shell
set shell

134

s e t s h e l l

14.2.4

14.2.5

${variable:-value}

c o l o u rb l u ee c h o c o l o u r

${variable:=value}

0 3 : 0 0We e k l y
at

14 shell

135

file

${variable:+value}

variable=""
$DETINATION=""

14.2.6

sourcepasswddestcp

device mt

14.2.7

variable-name=value
readonly variable-name

136

readonly

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 RIABLE-NAME=valuee x p o r t V A R I A B L E - N A M E

VARIABLE-NAME=value
Export VARIABLE-NAME

14.3.2

env

14 shell

137

14.3.3
unset

14.3.4 shell
Brourne shell
/etc/profile shell

1. CDPATH
cdCDPATH
c d C D PAT H C D PAT H

$ C D P A T H = : / h o m e / d a v e / b i n : / u s r / l o c a l e
/ a pxppso r t C D P A T H .

$ cd apps

cd CDPATH apps
2. EXINIT
E X I N I T v i v i
10 tab
$ EXINIT='set nu tab=10';export EXINIT

3. HOME
H O M E p a s s w d 2
HOME cd

$ cd $ HOME

4. IFS

138

I F Ss h e l l
t a bI F S I F S
echo PATH

$ IFS=<space><tab>; export IFS

<space><tab>tab
5. LOGNAME

6. MAIL
M A I L /var/spool/mail/<login name>s h e l l

MAIL
$ M A I L = / u s r / m a i l / d ae
v ex p o r t M A I L

7. MAILCHECK
M A I L C H E C K 6 0 s 2 m

$ MAILCHECK=12
e
0 xport MAILCHECK

8. MAILPATH
MAILPATH MAIL
$ M A I L P A T H = / v a r / s p o o l / d a v e : / v a r / s p o o l /e
a dxmpionr t M A I L P A T H

MAILdaveadmin
9. PATH
PAT H

H O M E

$ P A T H = $ H O M E / b i n : . : / b i n : / u s re
/ b ixnp o r t P A T H

H O M E / b i n / b i n
/usr/bin
PATH /etc/profile
$ P A T H = $ P A T H : / $ H O M E / b i
n:.
export PATH

/ e t c / p r o f i l e PAT H $ H O M E / b i n

10. PS1
s h e l l # $

14 shell

139

11. PS2
PS2 > PS2

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
shell

13. TERMINFO
/usr/lib/terminfo/usr/share/terminfo
$ T E R M I N F O = / u s r / l i b / t e r m ie
n fxop o r t T E R M I N F O

14. TERM
TERMTERM
vt100vt200vt220-8
$ T E R M = v t 1 0e
0 xport TERM

15. TZ

GMT0EDT
14.3.5

1. EDITOR

$ E D I T O R = ve
i xport EDITOR

2. PWD
cd
3. PAGER
pgmoreman
$ P A G E R = ' p g - f - p %e
d'xport PAGER

4. MANPATH

140

man
$ M A N P A T H = / u s r / a p p s / m a n : / u s r / l o c a le
/ mxapno r t M A N P A T H

5. LPDESTPRINTER

$ 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
$HOME.profile

14.3.7
s h e l l

fatherchild
fatherfilmA Few Good Men
child film Die Hard
father

14 shell

141

father filmchild film


father export childfilm

e x p o r t f i l m
film

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

Did

You

See

The

Full

Moon

$7

$8

$9

142

14.4.1

6 789

$ 0 b a s e n a m e $ 0

14.4.2
f i n d $ 1

14 shell

143

$ 1g r e p i d g r e p i dp a s s w d

14.4.3
s h e l l
7
14-2
14-2 shell
$#
$*
$$
$!
$@
$$?

9
ID
ID
$#
shell set
0

p a r a m

144

ID
14.4.4
$ ?0
01
/tmp$?

$ ? c pc a n n o t . . .

/ d e v / n u l l b i n

b i n
$!1

14 shell

145

14.5
s h e l l s h e l l

15

15.1

s h e l l s h e l l

*s h e l l s h e l l

15-1
15-1 shell
""
''

15.2
$`\
s h e l l

15

147

mydate

s h e l l" " m y d a t ed a t e
date
grepDavey Wire
grepDavey Wire

s h e l l

s h e l l
$ boy$BOY

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

date

shell

148

mydate

mydate

date mydate

shell

15.5
s h e l l
& * + ^ $ ` " | ?
echo* *

$ echo \*
*

$ $ s h e l l I D
$$

A S C I I s h e l l

15

149

LINUX
-e

expr* *

echo $19.99
$

15.6

1)
2)

shell
16 shell
s h e l l s h e l l

shell
shell
shell

16.1 shell
s h e l l

shell
UNIXLINUXshell
shell

16.2

#!/bin/sh
shellBourne shell
#

152

shell

16.3
cleanup

/usr/adm/ /usr/local/apps/log

chmod
$ chmod u+x cleanup

$ cleanup

$ cleanup
sh:cleanup:command not found

$. /cleanup

s h e l l . p r o f i l e
PATH $HOME
$ pwd
$ /home/dave/bin

p w d b i n . p r o f i l e
$HOME/bin
PATH=$PATH:$HOME/bin

bin
$ cd $HOME
$ mkdir bin

.profilebinPATH .profile
$. ./profile

213

16 shell

153

chmod

16.4
s h e l l
shell

17

Test
ifthenelse

test
expr
e x p r $ ?t e s te x p r0
1

17.1
test
test condition

[condition]

17-1
17-1
-d
-f
-L
-r

-s
-w
-u
-x

suid

s c o r e s . t x t 0

0 scores.txt

scores.txt
appsbin

17

155

appsbin
suid

suid

17.2
O K s h e l l

-a
-o
!

scores.txtresults.txt
results.txt

17.3

156

shell

string_operator
=

=
-z

-n

EDITOR

vi

echo

tapetape2

tapetape2

17.4

"number"numeric_operator"number"

["number"numeric_operator"number"]

numeric_operator
-eq
-ne
-gt
-lt
-le
-ge
130130

17

157

1130200

130100

source_countdest_count:

too many arguments

17.5 expr
expr
expr argument operator argument

expr

shell

158

shell

17.5.1
e x p r 0 1
expr

17.5.2
expr

d e v / n u l l
0

e x p r
1
hellohello

e x p r1 0
hellohello
17.5.3
e x p r e x p r . *
0

expr .doc

17

159

17.6
e x p rt e s t
if then elsecase

18


whileforuntil loops
if then else

18.1

$ echo $?

4 $? $$
| | s h e l l s h e l l 1 9

shellexit
exit n

n
exit shellshell
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

18

161

s h e l l

18.2.1
i ft h e ne l s e
0 1

case

18.2.2
3
for
Until

until

While

while

for for

e c h o L I N U XB S D e c h oecho -e -n
e c h o U N I X VB S D e c h o 1 9
shell

18.3 if then else


i f 0 1 i f

if 1
then 1
elif 2
then 2
else 3

162

shell

fi
if
If 1

Then

elif 2

then
2

else

12

fi

if fiif fi
elifelse elifelseIf
elif ifif then fi

18.3.1 if
if
if
then
fi
i f t h e n
if
if then

fi

1012 if
e c h o
else

18.3.2

18

163

returnname

18.3.3 grep
g r e pi f
g r e p g r e p D a v e d a t a . f i l e
Dave\>

grep grep0grepif
grep if
18.3.4 grep
g r e p
grep Peter

164

shell

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

DIRECTORY
" / " /
1

18

165

18.3.7
if test.txt LOGNAME

18.3.8
if $#

18.3.9
c r o na t

166

shell

t e s t - t
test1

18.3.10 if else
if
if
then
1
else
2
fi
ifelse
18.3.11
E D I TO R E D I TO R

18.3.12
LOGNAME root
LOGNAME
r o o t r o o t
1
rootLOGNAMEelse
f i r o o t

18

167

18.3.13

$1 DIRECTORY
ls -A

18.3.14 null
t h e ne l s e

i f s h e l l

then

168

shell

18.3.15

DIRECTORY
if ["$DIRECTORY"=""]

if[$# -lt 1]

Yy

18

169

18.3.16
c p$ 1$ 2
/dev/null

sort a c c o u n t s . q t r
300

18.3.17 if
if iffi
18.3.18
E D I TO R

170

shell

vi
vi
y

Yy $ E D I TO R =
r e t u r n -z $EDITO R
vi E D I TO Rvi
E D I TO R
E D I TO R
18.3.19

* . t x t

18

171

18.3.20

100

yY
COUNTOR

172

shell

18.3.21

s t t y
passwd stty
ID maydayINVALID_USERINVALID_PASSWD
n o y e s

I D
IDdavepauline

18

173

18.3.22 elif
if then elseelif
18.3.23 elif

e l i f r o o tl o u i s ed a v e
rootlouisedave

174

shell

18.3.24
/usr/opts/audit/logs/usr/local/audit/logs

18

175

18.4 case
c a s e c a s e
case
case in
1}
1
...
;;
2
2
...

esac
c a s e i n

*

[..]

18.4.1 case
15 c a s e A N S c a s e
ANSANS
;
case
case
*

176

shell

18.4.2 |
case | vt100|vt102vt100vt102
vt100vt102vt100|vt102
T E R M v t 1 0 0 *
T E R Mv t 1 0 0 c a s e T E R M *
TERM

18

177

18.4.3 yn
case yn
Yyyes case Nnno

18.4.4 case
case
$ # 1

178

shell

c a s e p a s s w ds t a r ts t o ph e l p

18.4.5

case
234453655454
c a s e

18

179

18.4.6

when
case

180

shell

c a s e if then else

18.5 for
for
for in
do
1
2
done

18

181

f o r
s h e l l I n f o r

in
18.5.1 for
1 2 3 4 5

18.5.2
f o r orange red blue grey e c h o l o o p
echo$loop

18.5.3 forls
ls

182

shell

18.5.4 for
for in
for

params

in"$@"

params

in"$*"

for

in for $@$*

in"$@"

f o r f i n d

18

183

find -name

18.5.5 for
f o r f o r

18.5.6 for
f o r c p . b a k
cp ls

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

184

shell

18.5.8 sed
s e d . H O L D . m v
mv

18.5.9
expr lsfor

wc

18.5.10 for
f o r
who awk for

18

185

18.5.11 for
for for
1

for
do

for
do

i n1

i n 2

1
...
done
done

for APPSSCRIPTS

A P P S

S C R I P T S t e e
f o r
SCRIPTS APPS

186

shell

18.6 until
u n t i l u n t i l w h i l e
w h i l e u n t i l u n t i l

u n til
until
1
...
done

18.6.1 until
who rootIS-ROOTgrep
r o o t s i m o n r o o t
s l e e p u n t i l

18

187

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

process.main LCK
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
awkgrep/logs
9 0 %
9 0 %

188

shell

18.7 while
while
w h i l e
do

1
2
...
done

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 R 5
COUNTER0 COUNTER1

15

18.7.2 while
w h i l e F I L M< C t r l D>

18

189

18.7.3 while
while
ID

w h i l e
$LINE.

18.7.4 IFS
I F S I F S
I F S t a b 3
NAMEDEPTID
echotab

190

shell

18.7.5
while
James Lenod
James Lenod

caseexpr

18

191

18.7.6

STATGIFT

G I F T e x p r
e x p r L O O PTOTAL 0 I T E M STOTAL
ITEMSTOTAL

192

shell

expr

expr

expr

TOTAL 0 e x p r

18

193

18.7.7

w h i l e

wc

18.7.8 #

while
c a s e #

194

shell

# **

18.7.9

18

195

I T E M
sed

while expr

196

shell

18.7.10 while
5 while
34myfile.txtmyfile.bak
while
null

18

197

18.8 breakcontinue
shell
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
break

18.8.3 continue
c o n t i n u e b r e a k

198

shell

18.8.4

Peter James
2
Peter James

18

199

18.9
w h i l e n u l l h i l e n u l l

w h i l ec a s e

/ D D / M M / Y Y Y Y

$ date +%d/%m/%y
32/05/1999

hostname-s

while while
while
do

done

e c h o

case

200

shell

case
CAPS LOCK
Qq 0

LINUXBSD echo V
echo "\007 the bell ring"

echo
tputtputclear

18

201

18.10

19 shell

shell shell

shell

{
1
...
}

{
1
...
}
function
function

{ ...
}

s h e l l
shell

echo

19 shell

203

19.1

s h e l l
hello
echo

19.2

h e l l o
back from the function

19.3
$ 1 , $ 2 . . . $ 9
s h e l l

_FILENAME_filename

19.4

1)
2) return 01

204

shell

return

R e t u r n 0
R e t u r n 1

19.5

i f 0 1 i f

variable_name=function_name

function_name variable_name

19.6 shell
shell
#!/bin/sh
functions.main
s h e l l s e t
shell
u n s e t s h e l l u n s e t
s h e l l
shell unset unset

19.7
shell
functions.main

19 shell

205

find
1 $ 0
shellsh-

19.8

./pathname/filename

shell
$. functions.main

file not found


$. /functions.main

<> <> <> <> s h e l l

19.9
set setshell

19.10 shell
f i n d i t

206

shell

19.10.1 shell
s h e l l u n s e t
unset
unset
function_name
$ unset findit

set
19.10.2 shell
f u n c t i o n s . m a i nf o r

$. /functions.main

set shellfor

findit

19 shell

207

19.10.3

1.

awk

$1 awk
1 _LETTERS_ONLY

if

208

shell

n a m e _ e r r o r $ @
F_NAMES_NAME

while

19 shell

209

2. echo
echo LINUXBSDV
echo
echo read
LINUXBSDecho-n
LINUXBSDecho echo

V\C

e c h o L I N U X- e s h e l l

echo
echo \007 V
\007LINUX

$@
uni_prompt "\007 there goes the bell ,What is your name:"
What is your name:
VLINUX/BSD
V \cz

210

shell

u n i _ p r o m p t s " \ 0 0 7 t h e r e g o e s t h e W
b ehlalt i s y o u r n a m e : "

T h e r e g o e s t h e b eW
ll hat is your name:

3.
press any key
to continue dd
d d
1myfile
dd if:/dev/zero of=myfile count=512 bs=2048

d d d d
d d
stty dd dd

19 shell

211

4.

if

5. YN

case

212

shell

$ 1 YN

continue_prompt

19 shell

213

$1

6. ID

I D
grep passwd
grep /etc/passwd
p a s s w d5
passwd
ID grep

whois

7.
vi
nl nl

214

shell

number_file shell
$ number_file myfile

number_file $1

8.

tr

u p p e r
str_to_upper

$1

$ @

19 shell

215

9. is_upper
str_to_upper
is_upper if

is_upper

i s _ u p p e r a w k

is_lower
10.
s t r _ t o _ u p p e r s t r _ t o _ l o w e r

216

shell

L O W E R

$ @

str_to_lower

11.

2 0 5 0

check_length

19 shell

217

N A M E 1 0b r e a k

w c w c
w c
awk
wc

12. chop
c h o p
M Y D O C U M E N T. D O C M Y D U C U M E N T . D O C
chop
MYDOCUMENT.DOC 10

Chop

218

shell

CHOPPED chop

13. MONTHS
m o n t h s

303March

19 shell

219

months
months 04

April

June
19.10.4

s h e l l

19.11

19.11.1

220

shell

e r r o r _ m s g

19.11.2

functions.shshshell

19 shell

221

f u n c t i o n s . s h

.\<path to file>

shell shell

222

shell

19.12

backfunc

1_CODE
_CODE comet

19 shell

223

19.13

20
$ 1 . . $ 9 $ #
usage

shift
getopts
shiftgetopts

usage case

UNIXLINUX

20

225

1 2

shellshift shift $1$9

20.1 shift
s h i f t
w h i l e

20.1.1 shift
shift

20.1.2
eval
eval echo \$$#shiftshift 'expr $# -2'

226

shell

20.1.3 shift
s h i f t t r

-l
-u
shift -l-u

u s a g e
case shift
usage

c a s e c a s ec a s e
*-* -p-q

20

227

* f o r - f

case

-l-u
TRCASE
EXT .UC.LC
OPT

yes no

t r t r c a s ef o r

228

shell

20

229

- l - c 2 3 -12
v

shift getopts

20.2 getopts
g e t o p t s g e t o p t s

20.2.1 getopts
getoptsgetopts
a ALLtrue
h HELPtrue

230

shell

f FILEtrue
v VERBOSEtrue
false

getopts
getopts

option_string variable

while getopts ahfgv OPTION

whileoption_string5-a-h-f-g-v
variableOPTION

20

231

20.2.2 getopts
getoptsoption_string
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

getopts OPTION

20.2.3 getopts

g e t o p t s

option_string
getopts ahfvc: OPTION

ahfv c
O P TA R G

option_string
while getopts :ahfgvc:

OPTION

case

getopts

232

shell

-c

20.2.4
g e t o p t s
getopts

20

233

g e t o p t s O P TA R G

getopts
fort r- c a s e shift
getoptsshift
20.2.5 getopts
t r- c a s egetopts getoptsshift
VERBOSE
V E R B O S E n o c a s e
yes if

/dev/null
> / d e v / n u l l 2 > & 1

V E R B O S E - v V E R B O S E
myfile
tr-case -l -v myfile1 myfile2 ...

tr-case -v -l myfile1 myfile2 ...

g e t o p t s s h i f t

234

shell

UNIXLINUX

20

-a
-c
-d
-e
-f
-h
-i
-l
-o
-q
-p
-v

235

20.3

s h i f tg e t o p t s g e t o p t s
shift
s h i f t $ 1 . . $ 9 s h i f t

21
s h e l l
tput

tput


tput 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

tput

21.1 tput
tput tput
$ tput init

t p u t /

21.1.1

bel
blink
bold
civis
clear
cnorm
cup
el
ell
smso
rmso
smul
rmul
sc
rc
sgr0
rev

xy

21

237

21.1.2

tab

cols
it
lines

21.1.3
tput

chts
hs

21.2 tput
tput tput
21.2.1 tput
tput
variable_name='tput name'

21.2.2
if tput

21.2.3 tput
tput belcl

238

shell

21.2.4

1)

2) tput civis
25l l 25h
[

UNIXLINUX echo

\ 0 3 3 \e c h o @

echo @echo-e\100

v
echo \100

clear homeVT
ESCIJ echo

e c h o ' < CT R L - V> h i t t h e < E S C A P E > k e y t h e n [ ? 2 5 h '

<CTRL-V>,

21

21.2.5
tput
cup r c

r c

239

240

shell

21.2.6
t p u t
tput 2

10

c e n t e r t x t 1 5T H E M A I N E V E N
T


centertxt 15 $
1

21.2.7
tputterminfo tput

21

241

i n f o c m pt e r m i n f o

$ infocmp $TERM

termput

21.2.8
c a t F 1cat -v
<Ctrl-c>
cat F1^[OP]F2([OQ])[^[[A]

F 1F 2 c a t

242

shell

21.2.9
ANSI

1.

30
31
32
33

34
35
36
37

2.

40
41
42
43

44
45
46
47

21

243

<ESCAPE> [background_number;foreground_number m

21.2.10
e c h o
echo

<Ctrl-v><ESCAPE> [4032 m
echocase

red-yellow
colour red-yellow

echo .profile
21-2

244

shell

21-1 tput

21-1

21

245

246

shell

21.2.11
while

read_char trap
2315

priv.user

r o o t
davematty peterlouise

21

247

F O U N D
USER
U S E R w h o a m i
continue

test 1 0

passwd

21-2

248

shell

Restrict

21-2dave
qQ

21

249

250

shell

21

251

profile exec
UNIXLINUX shell

21.3
t p u t

22

DBFILE

10
20
20
-

IT

<Staff number>:<First name>:<Second name>:<Department>

trap 2315

22.1

1)
2)

22

253

read_a_char

254

shell

grepgrep_CODE awk
0 g r e p $ _ C O D E \ >

22

255

w h i l e w h i l e

if ["$NUM"!=""]

i ft h e n e l s e

Staff Number:No Input Detec


T
t ehdi s F i e l d R e q u i r e s a N u m b e r

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 0 0 1LEN_PASS0
1
check_duplicate
DUPLICATE0 0 A N D
then
while break

S t a f f N u m b e r : N o n _ N u m e r i c o r T o o M a n y N u m b e r s I
n Field

2 3
characters

256

shell

case 5

case


c o n t i n u e _ p r o m p t Y N YN

Nif while

Y
e c h o " $ N U M : $ F _ N A M E : $ S _ N A M E : $ D E P A R T " > > $ DB F I L E

s l e e p 1 s

DBFILE

DBFILE

22

257

258

shell

22

259

260

shell

22

261

262

shell

22.2

1)
2)
3)
4)
g r e pa w k
100
awk awk
grep
awkgrepDBFILE

awk
I F S
I F S

IFS
SAVEDIFS=$IFS

IFS=:

IFS
IFS=$SAVEDIFS

22

263

get_rec

if ["$STR"!=""
t
] hen

[-2 $STR]

b r e a k

no

264

shell

grep -v STRSTR

g r e p D B F I L E
DBFILE

22

265

266

shell

22.3

{ default_variable=variable}

22

267

grep -v
grep
grep -v $CODE $DBFILE >$HOLD1

DBFILE

D B F I L E

268

shell

22

269

270

shell

22.4
c a t a w k

22

271

272

shell

22

273

22.5

23
s h e l l


set

iffi
s h e l l
shell

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
while do

23.1.2

s h e l l v i v iset nu
v i< E S C > set nu <return>
shell
23.1.3
-eq

23

275

[: missing ']'

23.1.4

23.1.5 for
for $
23.1.6 echo
e c h o e c h o
echo
e c h o

23.2 set
set set
set -n
set -v
set -x
set +-+-
s e t

f o r
set -x

276

shell

set

23.3
set echo

24 shell
s h e l l s h e l l
Bourne shell /binusr/bin

Bourne shell
cdpwd

/bin/pwd

24.1 shell
24-1
24-1

.
break
cd
continue
echo
eval
exec
exit
export
pwd
read
readonly
return
set
shift
test
times
trap
ulimit
umask
unset
wait

true
shell
forwhileuntilcase

shell
shell
shell

shell

shell

shell

24.1.1 pwd

278

shell

$ pwd
/tmp

24.1.2 set
s h e l l s e ts e t

set

set param1 param2 ..

accounts.docaccounts.bak

s e t

24.1.3 times
t i m e s s h e l l
times

24.1.4 type
t y p e t y p e

24 shell

279

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
shell.profile ulimit
ulimit options

ulimit

-a
-c
-f

ulimit

24.1.6 wait
wait wait ID

$ wait

24.2
shell

shell
25 <<
w h i l e < <
<<



ftp

command <<word
text
word

< < s h e l l< <


shell ( )

<<

25.1

$ cat >> myfile <<NEWFILE

N E W F I L E
myfile

t a b s h e l l
<< -
cat >> myfile <<- NEWFILE
...

25.2
vi
QUICKDOC

282

shell

25.3
< <

c r o n
< < s y b _ b a c k u p

1) syb_backup
2) 2
3) 3
4) Y
syb_backup

25 <<

283

s y b _ b a c k u p >>$log_f 2>&1
$log_f /logs/sql.backup.log

<<MAYDAY s y b _ b a c k u p
MAYDAY

<<

25.4 ftp
< < f t p f t p
a n o n y m o u s f t p

1)
2) ASCII
3)
4)
t r a c e r o u t e
t r a c e r o u t e f t p

284

shell

/tmp /tmp
.ftp

25 <<

285

286

shell

ftp <<ftp -i -n
u s e r $ U S E R @ T H I S H O S T
dave@bumper

DEST_HOSTFILENAME

ftp DEST_HOST
my_favourite_host

25.5
s h e l l < <

<<
select into

25 <<

287

< < f o r
<<sql

<<shell

s h e l l MAYDAY

288

shell

25.6
< < < <
f t p < <

26 shell



trap
eval
logger

26.1

c a t

26.1.1 date

date

date option + %format

hh:mm

290

shell

d dm my y
ddhhmm

26.1.2
$ $

$ $
$ $ S h e l l $ $

26 shell

291

rm /tmp/*.$$shell rm /tmp/*.408

26.2

1
2
3
9
11
15


SIGHUP
SIGINT
SIGQUIT
SIGKILL
SIGSEGV
SIGTERM

<CTRL-C>

0 . l o g o u t s h e l l
0 exit <CTRL-D>

kill [-signal no:| signal name] process ID

kill 15

292

shell

26.2.1
1 D N S
named
kill -1 1Named
m o n _ w e b 9
ps

ps -ef ps xa

kill -9 157

kill -s SIGKILL 157

-skill SIGKILL 157

g r e p

kill -9

26 shell

293

26.2.2

9
s h e l l 1231 5

1)
2)

294

shell

3)

trap

26.3 trap
trap
trap name signal(s)

n a m e n a m e
Name Signal

1)
2)
3)
trap
trap "" 2 3
trap"commands" 2 3
trap 2 3

23
23 commands
23

26.3.1
<Ctrl-C>2

trap
trap "do_something" signal no:(s)

26 shell

295

trap "my_exit" 2

t r a p 2 m y _ e x i t

m y _ e x i t 2 $ L O O P
< C t r l - C > 2

26.3.2

d fp s H O L D 1 . $ $H O L D 2 . $ $
$ $ < C T R L - C >

296

shell

23
<CTRL-C>
2
case
1 1
2 c a s e
case

26 shell

297

<CTRL-C>

26.3.3
lockit while
trap 2315

$ stty sane

298

shell

lockit

26.3.4
/etc/profile
trap12315

26 shell

299

trap

9
trap""signal no:(s)

trap"do something" signal no:(s)

trap ""1 2 3 15

trap"my_exit" 1 2 3 15 my_exit
w h i l e
trap

6 sleep

300

shell

< C t r l - C >
trap
<Ctrl-C>my_exit

t r a p

26.4 eval
eval

eval

eval
26.4.1
t e s t f cat testf
MYFILE echo

cat testfMYFILE
$ MYFILE
= c a t t e s t
f

26 shell

301

echo testf

eval eval

eval
cat testf
CAT_PASSWD cat /etc/passwd | more
eval

eval

e v a l $ $ # s h e l l

26.4.2
data

eval

302

shell

d a t a P C4 8 6
N A M ET Y P EE v a l N A M ET Y P E
PC486 PC 486

eval
eval

26.5 logger
m e s s a g e s / v a r / a d m
/var/log syslog messages
/etc/syslog.conf

UNIXLINUX

logger




/ v a r / a d m / m e s s a g e s

logger
logger -p -I message

26 shell

303

-p
-i
26.5.1 logger

message

crontab 30

$ test_logger

message

26.5.2 logger

logger
231 5

304

shell

logger
tty0tty02
/etc/profile

26 shell

305

logger

26.6

27


5 0 0

pingall /etc/hosts ping


backup_gen
del.lines sed
access_deny
logroll
nfsdown unmountnfs

27.1 pingall
p i n g a l l
/etc/hosts ping
/ e t c / h o s t s # w h i l e
awk ADDR
forping

27.2 backup_gen

27

307

b a c k u p _ g e n

backup.defaults

[ ]
[rmt0]

rmt1rmt3

[]

[]

sybase

f i n dc p i o

308

shell

27

309

310

shell

backup.defaultscontinue_prompt

27

311

312

shell

27.3 del.lines
sed

sed

s e d
s e d $ $

s h i f t w h i l e

del.lines -help

27

313

27.4 access.deny
/ e t c / n o l o g i n
/ e t c t o u c h n o l o g i n
root

/etc/profile

/etc nologin

314

shell

rm /etc/nologin

/ e t c / p a s s w d *

L I N U X l o g i n . a c c e s s

d e n y. a c c e s s / e t c / p r o f i l e
lockout.users all
root
lockout.users

trap
lockout.users
all
all
all root
grep all\>
get_users lockout.users#
r o o t r o o t

L O G N A M E N A M E S
NAMESlockout.users
4 0

/ e t c / p r o f i l e

. /apps/bin/deny.access

/ a p p s / b i n

27

315

l o c k o u t . u s e r s / a p p s / e t c
s e t
l o c k o u t . u s e r s u n s e t
unset/etc/profile
unset getusers

316

shell

27.5 logroll

c r o n

16
B L O C K _ L I M I T
8 4 K
LOGS
f o r d u
B L O C K _ L I M I T
0
c r o n

27

317

27.6 nfsdown
n f s

n f s

nfs
L I S T n f s f o r
grepdf nfs nfsmount
machine: remote_directory

NFS_MACHINEumount

27.7

28

L I N U X L I N U X
V UNIX


rc.scripts
rc.scripts
inittab

rc.script
s t a r ts t o p
r c . s c r i p t

r c . s c r i p t
shell

28.1
r c . s c r i p t s (

)/etc/rcN.d

/etc/rc.d/rcN.d
N 7 r c N . d 06
rcS.d

LINUX

28

319

c d r c N . d r c . s c r i p t s

28.2
shell rc.scripts

run level

LINUX
$ runlevel
23
3

28.3 inittab

i n i t

inittab
/ e t c i n i t

inittab
id:rstart:action:process

id
rstart
a c t i o n i n i t p r o c e s s

320

shell

w a i tr e s p a w nw a i t r e s p a w n

process inittab

3
1 01 6

15:5:wait:/etc/rc.d/rc 5

5 5 / e t c / r c . d / r c/ e t c / r c . d / r c/ e t c / r c . d / r c 5 . d

2345
1 s t t y S 1m i n g e t t y
vt100

28.4
i n i t
/ e t c / r c . d / r c/ e t c / r c . i n i t

r cr c . i n i t f o r
K stop
S s t a r t

r c N . d

28

321

/usr/sbin/init.d/etc/init.d
LINUX
/etc/rc.d/init.d

r c . <> r c run command r u n


controlreal crucial

rc.scripts
rc.name stop
rc.name start
r e s t a r ts t a t u s

rcN.d
28.4.1
(28-1)

28-1
0
1
2
3
4
5
6

UNIX X-windows

28.4.2
rcN.d
Snnn.script_name

Knnn.script_name

S
K
n n0 09 9 0 0 09 9 9

322

shell

rc3.d S45.myscript
rc2.d S45.myscript
script_name
/usr/sbin/init.d
/etc/rc.d
/etc/init.d

i n i t

K23,myscript K12.named L I N U X
K
28.4.3



( )/etc/init.d/usr/sbin/init.d/etc/rc.d
rcN.d
rc.audit 354
621 r c N . d 3 5

case startstop

28

323

LINUX
LINUX

s t a r t s t o p
init.d

rcN.d/etc/rc.d /etc/rc.d/init.d

ls -l / e t c / i n i t . d / r c . a u d i t
( r c 4 . d
rc5.d)

(
6 ) 21 45

28.5 inittab
inittab

inittab

324

shell

3
inittab
$ cp /etc/initab /etc/inittab.bak

inittab

r c . d i s k c h e c k e r 3
/usr/local/etc/rc.diskchecker

28.6
/ e t c / i n i t t a b
rc.local /etc
inittab

/ b i n( / u s r / s b i n) s h u t d o w n

28.7

29 cgi
P C We b s h e l l
cgi

cgi
(Server Side Includes,SSI)
get
post

Webcgi
We b
We b ( a p a c h eC e r n) ( N e t s c a p eInternet Explorer)
c g i c g i

We b 2 0
We b apache We b
Netscape
HTMLWeb
HTML

29.1 Web
We b H T M L We b
HTML Web

We b

We b
cgi

29.2 cgi
c g i
c g i P e r l

326

shell

shell 29-1
Web
apache?

Web

cgi

29-1 cgi

29.3 Web
(URL)WebURL


h t t pf t pm a i l t of i l et e l n e tn e w s h t t p(
)
D N S I P

TCP 80
We b i n d e x . h t m l
URL
http://localhost/index.html

i n d e x . h t m l We b
URL
http://localhost/

29.4

cgiHTM

We b U R L
c g i - b i n c g i c g i
c g i We b
H T M L
HTML Web 29-1
HTML
29.4.1 cgi
c g i We b c g i - b i n
s r m . c o n fS c r i p t A l i a s
c g i . c g i We b h t m l
htdocs .html
chmod 755 script.cgi

We b n o b o d y h t t p d . c o n f

29

cgi

327

We b
p a s s w d n o b o d y n o b o d y
/ e t c / p a s s w d
*
29-1 HTML
<HTML></HTML>
<HEAD></HEAD>
<TITLE></TITLE>
<BODY></BODY>
<Hn></Hn>
<P></P>
<BR>
<HR>
<PRE></PRE>
<B></B>
<I></I>
<OL></OL>
<A HREF=url>link</A>
<FORM></FORM>
METHOD
ACTION
<INPUT...>
NAME
SIZE
TYPE
<SELECT...>
NAME
SIZE
<OPTION VALUE>
</SELECT>

HTML

postget

NAME

apacheWeb /etc/httpd/logs/usr/local/apache/logs
Webcgi

c g i f i r s t p a g e . c g i
cgi-bin 755

328

shell

shell echo MIME


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


Stand-To </HTML>

URL
http://your_server/cgi-bin/firstpage.cgi

your_server
D N S
I n t e r n e t

29-2

29-2 firstpage

29.4.2 shell
shell
w h o w c

29

cgi

329

U S E R S
if 10

< P R E > d f
e c h o < P R E >
< P R E >
URL
http://your_server/cgi-bin/pagetwo.cgi

your_server
29-3

29-3 pagetwo.cgi

330

shell

29.4.3 SSI
c g i We b c g i
c g i H T M L

c g i ( S S I )
S S I

S S I S S I
server-passed apache

We b kill -1 S S I
.shtml.html
29.4.4
n

cgi-bin hitcount.cgi

../cdi-bin/counter access
1 ../cgi-bin/counter
c o u n t e r 1
counter1( )

$ chmod 666 counter

Web( HTML htdocs


html) .shtml .shtml

29

cgi

331

S S IL A S T _ M O D I F I E D a p a c h e
Web(www.apache.org) SSI
SSI

<!--#command argument="value"-->

cgihitcount
exec
cgi
value
i n d e x . h t m l
URL index.html

29-4

332

shell

srm.conf
DirectoryIndex

i n d e x . h t m l
Web
URL
http://<server_name>/main.shtml

http://<server_name>

2 9 - 4

LAST_

MODIFIED
cron counter 1
29.4.5 Web
c g i e n vs e t
main.shtml cgi

<A HREF="/cgi-bin/printenv.cgi">Environment</A>

A HREF E n v i r o n m e n t
</A>
main.shtml

p r i n t e n v. c g i e n v
<PRE>

29

29-5

29-5

29-6

cgi

333

334

shell

(2 9 - 6 )

29.4.6

29-2 cgi envset


29-2 cgi W eb
DOCUMENT ROOT
GATEWAY_INTERFACE
HTTP_ACCEPT
HTTP_CONNECTION
HTTP_HOST
HTTP_USER_AGENT
REMOTE_HOST
REMOTE_ADDR*
REQUEST_METHOD
SCRIPT_FILENAME
SCRIPT_NAME
SERVER_ADMIN
SERVER_NAME
SERVER_PROTOCOL
SERVER_SOFTWARE
QUERY_STRING
CONTENT_TYPE
CONTENT_LENGTH

Web HTML
cgi
MIME
HTTP

IP

cgi
cgi
Web
DNSIP

Web
get
MIME
post

* Internet
c g i

29

cgi

335

29.5 getpost

c g i

cgi getpost
29.5.1 get
getgetHTML
U R L
Q U E RY _ S T R I N G R E Q U E S T _ M E T H O D

1.
main.shtml booka.cgi

main.shtml

booka.cgi cgi-bin

336

shell

b o o k a _ r e s u l l t . c g i
get

30 contact
film
actor

view_cineview_vid on
(
4 30) textarea
submit clear
cgibooka_result.cgicgi-bin

QUERY_STRINGREQUEST_METHODQUERY_STRING

29

cgi

337

booka.cgi REQUEST_METHOD
get29-7
(29-8)29-9
QUERY_STRING

29-7 getcgi

29-8

338

shell

29-9

QUERY_STRING

contact
film
actor
view_cine
view_vid
textarea

David Tansley
The Sound Of Music
Bruce Willis
on
on
!"%$%^*^&*()*()(*
Hows that!!

2.
Q U E RY _ S T R I N G

+
&
=
% x y x y1 6A S C I I
QUERY_STRING textarea
c g i% x y (x y1 6 )
A S C I I 1 6 &% +=()A S C I I1 2 7
(%29
1 6

29

cgi

339

&
+
=
% xy ASCII

eval

p r i n t f

340

shell

p r i n t fe c h o 1 6
printf \nQUERY_STRING
1 6% x y s e d \ x n n(
nn16)printf

conv.cgi c g i - b i n b o o k a . c g i
c o n v. c g i b o o k a _ r e s u l t . c g i

<FORM action="/cgi-bin/conv.cgi" METHOD=GET>

c o n v. c g i 2 9 - 1 0

29-10

get get
U R L U R L

QUERY_STRING
cgipost post
29.5.2 post
post get post

29

cgi

341

post getpost

<FORM action"/cgi-bin/conv.cgi" METHOD=POST>

C O N T E N T _ L E N G T H p o s t
get CONTENT_LENGTH

cat conv.cgi
get post

cat -cat
Q U E RY _ S T R I N G p o s t c a t
g e t

cgibooka.cgi
<FORM action="/cgi-bin/conv.cgi"METHOD=GET>

<FORM action="/cgi-bin/conv.cgi"METHOD=POST>

conv.cgi

342

shell

p r i n t f e c h o
printf
post
http://<server_name>/cgi-bin/booka.cgi

29-11
29-12

29

cgi

343

29-11 postcgi

29-12 post

3. cgi
Wonder Gifts

344

shell

1 9 9 8

13

29

cgi

345

d e p t q t r
s t d o u t p r i n t e rs c r e e nb o t h ( C H E C K E D)

346

shell

post 16
( ) p r i n t f
qtr_1998.txt
while DEPTYEARQP1P2P3P4
$dept( )DEPT $qtr(
)Q

URL URL( )
http://<server_name>/cgi-bin/gifts.cgi

29-13

29-13

29

cgi

347

29-14

29-14

29.5.3

cgi
l i s t We b
temp while (
)
echo "<OPTION>$LINE"

menu_selection

348

shell

29.5.4
c g i

6 0

dfspace.cgi
<meta http-equiv="Refresh" content=60;URL=http:/linux.pc/cgibin/dfspace.cgi">

RefreshWeb content=60
URL

onoff
df

c e l l s p a c i n g b o r d e r c o l s

df sed
awk 56
percentmount
TRTD
6 0

29

cgi

349

URL URL
http://<server_name>/cgi-bin/dfspace.cgi

29-15 ( )

29-15 df

29.6
cgiHTML
H T M L

shell
s h e l l

basename

basename path

basename shell

myscript
myscript: give me a file

$0

cat

cat options files

-v
cat
$ cat myfile

myfile
$ cat myfile myfile2 >>hold_file

(myfilemyfile2)hold_file

cat

compress

shell

351

compress options files

-v
compress .Z

cp

cp options file1 file2

-i
-p
-r
myfilemyfile1.bak
$ cp myfile1 myfile1.bak

get.prd/usr/local/sybin /usr/local/bin

/logs /hold/logs
$ cp -r /logs /hold/logs

diff

diff options file1 file2

-c ()
-I
comm diff

diff 233

dircmp

352

shell

dircmp options directory1 directory2

-s
dircmpdiff

dirname

dirname pathname

basename

du

du options directory

-a
-s
du 512

/var 14929(512)

file

file filename

fuser

fuser options file

-k

shell

353

-u
f u s e r - u- m
if fuser
/dev/hda5

/dev/hda5
$ fuser -k /dev/hda5

doc_part

fuser ID
f u s e r e ps -efps xa g r e p
ID

head

head -number files

head 10 -number

$ head -1 myfile

$ head -30 logfile |more

logfile30

logname

logname

mkdir

mkdir options directory

354

shell

-m

HOLD_AREA

more

more options files

pagepg

-c
-d
-n n
$ more /etc/passwd

passwd
$ cat logfile |more

logfile

nl

nl options file

-I n1
-p
nl
$ nl myscript

myscript
$ nl myscript >hold_file

hold_file
$ nl myscript | lpr

printf

printf format arguments

awkprintf
format
%[- +]m.nx

shell

355

- m n
%
s
c
d
x16
o10
p r i n t f

\a
\b
\r
\f
\n
\t
$ printf "Howzat!\n"
Howzat!

\n

16ASCII+

10

pwd

pwd

rm

rm options files

356

shell

-i ()
-r
rm

/var/spool/tmp

rmdir

rmdir options directory

-p
$ rmdir /var/spool/tmp/lp_HP

/var/spool/tmplp_HP

script

script option file

-a
s c r i p t

$ script mylogin

script mylogin

shutdown

shutdown

$ shutdown now

$ shutdown -g60 -I6 -y

60

sleep

sleep number

shell

$ sleep 10

10

strings

strings filename

touch

touch options filename

-t MMDDhhmm

myfile

6109:30 myfile2

tty

tty

tty

tty -s
0
1

uname

uname options

-a
-s
-v

357

358

shell

uncompress

uncompress files

$ uncompress myfile

myfile .Z

wait

wait process ID

process ID

1299
$ wait 1299

$ wait

wc

wc options file
s

-c
-l
-w

w h o w c

wc

shell

359

VAR

whereis

whereis command_name

whereis

w h e r e i s
shell

who

who options

-a
-r (LINUX runlevel)
-s
whoami who
who