Приемы профессиональной работы в UNIX

       

ТЕКСТ ПРОГРАММЫ


1 : 2 # @(#) tree v1.0 Visual display of a file tree Author: Russ Sage 2а вывод на экран структуры файлового дерева

4 if [ "$#" -gt 1 ] 5 then echo "tree: wrong arg count">&2 6 echo "usage: tree [dir]" >&2 7 exit 2 8 fi 9 if [ "$#" -eq 1 ] 10 then if [ ! -d $1 ] 11 then echo "$0: $1 not a directory">&2 12 echo "usage: tree [dir]" >&2 13 exit 2 14 fi 15 fi

17 find ${1:-.} -print | sort | sed -e "1p" -e "1d" \ 18 -e "s|[^/]*/| /|g" \ 19 -e "s|[^ */|/|" \ 20 -e "s|/\([^/]*\)$|\1|"


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




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






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




1 : 2 # @(#) lc v1.0 List files in a column Author: Russ Sage 2а Выводит список файлов в колоночном виде

4 if [ "$1" = "-m" ] 5 then MORE="| /usr/bin/more" 6 shift 7 else MORE="" 8 fi

10 eval "/bin/ls -a $@ | /bin/pr -5t" $MORE # pre System V 11 eval /bin/ls -aCF $@ $MORE # System V




1 : 2 # @(#) ll v1.0 Long listing of files Author: Russ Sage 2а Выводит список файлов в длинном формате

4 if [ "$1" = "-m" ] 5 then MORE="| /usr/bin/more" 6 shift 7 else MORE="" 8 fi

10 eval /bin/ls -al $@ MORE




1 : 2 # @(#) kind v1.0 Prints files of the same kind Author: Russ Sage 2а Выводит список файлов определенного вида

4 if [ $# -gt 0 ] 5 then if [ `echo $1 | cut -c1` = "-" ] 6 then case #1 in 7 -a) KIND='archive' 8 shift;; 9 -d) KIND='data' 10 shift;; 11 -t) KIND='text' 12 shift;; 13 -x) KIND='executable' 14 shift;; 15 *) echo "kind: arg error" >&2 16 echo "usage: kind [-a] [-d] [-t] [-x] [file...]" >&2 17 echo " -a archive" >&2 18 echo " -d data" >&2 19 echo " -t text, default" >&2 20 echo " -x executable" >&2 21 echo " if no args, reads stdin" >&2 22 exit 1;; 23 esac 24 fi 25 fi

27 : ${KIND:='text'} 29 case $# in 30 0) while read FILE 31 do 32 file $FILE | fgrep $KIND | cut -d: -f1 33 done;; 34 *) file $@ | fgrep $KIND | cut -d: -f1;; 35 esac



Содержание раздела