, shell , . 1, 1. - shell () 0, () . , , , , , . , UNIX , , . , - tree , - . - . 9-15 , , - , , . , . , . , , - , - . tree - 17-20. find UNIX. , , . ${1:-.} : $1 ( ) ( , ), . - . ( ). tree ( tree ),- " ", . find , . , . - . , - , . , - sed Unix. Sed - " - ", , - . -e , . sed, , 1. , - , . , , . , . . , ( /) (/). - . g , , - . , , . (\) - - , sed, - . ( 19) - , ( /) " " . . , . ( 20) ( ) , /. , /, find. , . \1 sed - , ( ) , - . sed - , - , /. 2.1.2. thead - ----------------------------------------------------- : thead ----------------------------------------------------- thd ( ) .  - . , thead .   thead [dir...]   $ find $HOME/src -name "*.c" -print | sort | thead ( ) .   1 : 2 # @(#) thead v1.0 Prints head of files in tree Author: Russ Sage 2 4 if [ "`echo $1|cut -c1`" = "-" ] 5 then echo "$0: arg error" 6 echo "usage: $0 [dir ...]" 7 exit 1 8 fi 10 case $# in 11 0) while read FILE 12 do 13 if file $FILE | fgrep text >/dev/null 2>&1 14 then echo "\n:::::::::::::::::::::" 15 echo " $FILE" 16 echo "\n:::::::::::::::::::::" 17 head -15 $FILE 18 fi 19 done;; 20 *) for NAME in $* 21 do 22 find $NAME -type f -print | sort | wile read FILE 23 do 24 if file $FILE | fgrep text >/dev/null 2>&1 25 then echo "\n:::::::::::::::::::::" 26 echo " $FILE" 27 echo "\n:::::::::::::::::::::" 28 head -15 $FILE 29 fi 30 done 31 done;; 32 esac   FILE NAME ,  thead? , UNIX. , - UNIX . - , . - head - UNIX - . , , . - . Thead - ( ) . thead? Thead - head UNIX. head , , - , , UNIX. , . , , . $ thead $HOME (*.c), . . ( ) $HOME , . thead , : $ find $HOME -name "*.c" -print | sort | thead find C, thead. , ( ), - ( ). - - - UNIX, . . UNIX -- , wc, awk, sort. - . - , . thead . , "-" , . thead , . , thead . , thead (stdin) , - EOF. ( , thead .) , thead, - . head "" - .  1. $ thead /etc , - /etc. , /etc . - . 2. $ thead /usr/include (*.h), - sys. 3. $ find $HOME -ctime 0 -print | thead , - 24 . , . , .  4-8 . thead , , (-) . - "-", "argument error" ( ) - thead . shell, , - , . 4, . echo $1 ( ), - cut. cut , . -c1 . cut BSD BSD cut, "" . , . who: for NAME in 'who | sed "s/^\([^ ]*\).*/\1/"' do done () sed . - , . (^) , ([^ ]), (*). . \( \). \1. .* - , , , . , \( \). - , , , - "cut -f1". (`), . , - . . , "-". - , if. , (- ) () , , - then if-then. - , , , . (case). , , - . , 11-19 while. , while , , - . , - (stdin). , - , file UNIX. file fgrep ( grep, ), , . fgrep - ( ), . - . file fgrep , - . , then ( 14-17). , , . , while . , then ( 14-17). , , - (:) , head UNIX 15 . , - . , - . , ( * case). for - ( 20). (*) case - , , . - (catchall) . for $* . , , . find - . "" " ", - . find sort, . while, FILE ( 27). , , head. 13-18 24-29, , . - , , . shell, , . shell System V , - . , while , , for - .   , find thead. - -name -ctime , . ( -) -n, , head n .   ? $ find $HOME -name "*.c" -print | thead $ find $HOME -name "*.c" -exec head {} \; , . - . , , thead, , find , , . 2.1.3. tgrep - -------------------------------------------------------------- : tgrep -------------------------------------------------------------- tgrep  . , tgrep .   tgrep [-c|-h] string [file ...]   # tgrep "profanity" / "profanity" ( !)   1 : 2 # @(#) tgrep v1.0 Search for string in tree Author: Russ Sage 2 4 OPT="" 6 for ARG in $@ 7 do 8 if [ "`echo $ARG|cut -c1`" = "-" ] 9 then case $ARG in 10 -c) OPT="-name \"*.c\"" 11 shift;; 12 -h) OPT="-name \"*.h\"" 13 shift;; 14 *) echo "$O: incorrect argument" >&2 15 echo "usage: $O [-c|-h] string [file ...] >&2 16 exit 1;; 17 esac 18 fi 19 done 21 case $# in 22 0) echo "$O: argument error" >&2 23 echo "usage: $O [-c|-h] string [dir ...]" >&2 24 exit 2 25 ;; 26 1) while read FILE 27 do 28 grep -y "$1" $FILE /dev/nul 29 done 30 ;; 31 *) STRING=$1; shift 32 eval find "$@" -type f $OPT -print | sort | while read FILE 33 do 34 grep -y "$STRING" $FILE /dev/null 35 done 36 ;; 37 esac   FILE OPT find STRING ,  tgrep? , - . , - , , - . - , - . , ( ). , UNIX "" - . grep , . grep. , - . , , , - . , , . ? - . , - , , - - . , , - . tgrep? tgrep - grep. , grep, . grep UNIX , . - tgrep , , . - find , - . - , find. tgrep . , , . , . , , -c -h. -c UNIX find - *.c. , -h *.h. , 4. , , . - , - , . - thead, tgrep .  1. $ tgrep unix $HOME unix - . 2. $ tgrep -c "^sleep()$" $HOME/src ( , , ) ( -c). 3. # find /usr/src -name "*.c" -print | tgrep "ioctl" ioctl -, /usr/src. ( , . , , , , - "#".) 4. $ tgrep "| more" `find . -type f -print` (|), - more, , find. Find - , - . 5. $ tgrep trap /bin /usr/bin /etc (trap) - shell, .  4 OPT, - find, . 6-18 . , "-". , . -c -h. - , - . - , shift - . , $@ - . $@ $ *, . - . OPT 10. , , , find. - , . \, - . - . , (*) 10 - OPT, , - . , , \. . - shell . , . - - , , . - case ( 21-37), . , . grep, , . , - . , - , .. - . while ( 26-29) grep . -y grep - . . grep 28 34. , /dev/null. ? . - grep. Grep , - . , . , , , . - , - , . , , grep. - , . , , . grep /dev/null, grep , . - , /dev/null , . case ( 31-36) - . - , . - , - . : " ", ( STRING - . .) shift. $@. , , - $OPT find. , tgrep -c. OPT, c "*.c" , , shell (.. , ) . , $OPT find, OPT *.c, , *.c. eval. find eval shell - . "*.c" - *.c, , . $@ find, . , find , . - , , $* . find . shell' -x ( ) . , - , . , , - $* "$1 $2 ...", $@ "$1" "$2" (.. ). , $* find . find , . $@, find - . find, . !   ? grep "$1" `find "$2" -print` find "$2" -print | while read F do grep "$1" $F done , - . - grep. - , find. find - , . , , - , grep. - . - . grep , . , - , , . - . 2.1.4. paths - , ------------------------------------------------------------ : paths ------------------------------------------------------------ paths  , , - (setuid bit files) - .   paths [-l] [-s] file [file ...]   $ paths -l ed ex vi , - ed, ex vi   1 : 2 # @(#) paths v1.0 Path locator with special options Author: Russ Sage 2 4 FORMAT="path" 6 for ARG in $@ 7 do 8 if [ '`echo $ARG | cut -c1`" = "-" ] 9 then case $ARG in 10 -l) FORMAT="ls" 11 shift;; 12 -s) FORMAT="set" 13 set "1";; 14 *) echo $0: arg error" >&2 15 echo "usage: $0 [-l] [-s] file [file ...]" >&2 16 exit 1;; 17 esac 18 fi 19 done 21 IFS="${IFS}:" 23 for FILE in $@ 24 do 25 for DIR in $PATH 26 do 27 case $FORMAT in 28 path) if [ -f $DIR/$FILE ] 29 then echo $DIR/$FILE 30 fi;; 31 ls) if [ -f $DIR/$FILE ] 32 then ls -l $DIR/$FILE 33 fi;; 34 set) echo "\n:::::::::::::::::::" 35 echo "$DIR" 36 echo "::::::::::::::::::::" 37 ls -al $DIR | grep "^[^ ]*s[^ ]*";; 38 esac 39 done 40 done   ARG DIR PATH FILE FORMAT IFS shell', PATH shell',  paths? shell PATH - , (:). , shell', shell, , - PATH, , - . , . , shell - , PATH, , . , : ------------------------- | | $ whatchamacallit | sh: whatchamacallit: not found | | , , . , - . , , , . - . more, ls, file cd UNIX. , . , , , - UNIX Systev V. , AT&T - where. UNIX Berkeley which ( -shell') whereis ( ). Whereis - , ( /usr/src). , - , - - . , path, , paths. - : IFS="${IFS}:" for FILE in $@ do for DIR in $PATH do if [ -f $DIR/$FILE ] then echo $DIR/$FILE fi done done . (:) . , (, , ), , - -. : - , PATH. for. , . - , - PATH. , . - ( ). shell- test , - . PATH : PATH=.:/bin:/usr/bin:/etc/:$HOME/bin : ., /bin, /usr/bin, /etc , , $HOME/bin. "path ll" , , - : --------------------------------------------- | | /usr/bin/ll | /usr/russ/bin/ll | | , ll . paths? , , path, - paths. Paths . path, , . . - (setuid bit files), . (. 8, setuid.) . ls, : paths [-l] file [file ...] , , "paths ls who date" "paths -l ll". (setuid files) .