------------------------------------------------------------ : otod --------------------------------------------------------------------- otod : . : OCT="octal_number"; DEC = '.otod' $OCT="777" ; $DEC='.ot $echo $DECod' OCT , , . otod 1 : 2 # @(#) otod v1.0 shell-- : Russ Sage - 9 - bc < idfile ls shell, (). shell , & . id , shell, . - ! - - : $ kill -9 'cat idfile' id, kill, cat, id, . "kill self", id, . watch, 6 . vi , . Sed , . Sed . ed. ed d . , stdin - 12 - . d , . , . . . , shell - , $. , - . ed file << -! 1, \$s/^ *// w q ! "file" . " , , , , "". ." . a.out , . , , , . ( PC). a.out shell. , more, . $ (a.out < text > input > lines > ! ) | more . , , , shell PS2 !, . , , - , . C shell shell - - . , shell, . , . , shell, . , . $ cat archive - 13 - # # 1, 2 3 # echo " 1" cat > text1.sh << ! # # 1 # who | sort ! echo " 2" cat > text2 << ! . , . , , shell , . text2, .. . ! echo " 1" cat > text3.c << ! /* 3, */ main() { printf("hello world"); } ! # # # cat. - cat text1.sh ( shell), text2 ( ) text3.c (-). , "archive". , . - , . , , , - . , , . , . , , . 10-1 while "". , shell - (0) . 10-1 "" +--------------+----------------------------------------+ | | "" | - 14 - +--------------+----------------------------------------+ |while true |True - /bin, -| | | 0 | |while[1 -eq 1]| , | | | 0 | |while : | | | |shell', 0 | +--------------+----------------------------------------+ . . - , , . . ? , . , , ls. ls? . "ls file", . "echo file | ls", ls , , ls , . , - . , . , . , , , - . , , . . UNIX wc - . "wc file1 file2 file3", . , : "ls file1 file2 file3 | wc" ? Wc , ls. file1, file2, file3 - 15 . , wc? , wc: cat file1 file2 file3 | w , wc, wc , . . awk. "awk file", , "cat file | awk", . "ls file | awk", .. awk "file". / shell shell. , . shell . 1 : 2 # @(#) , 3 4 N=1 5 echo " N = $N" 6 7 echo "1\n2\n3" | while read LINE 8 do 9 N=2 10 echo " N = $N" 11 done 12 13 echo " N = $N" , , - shell, . 4 N 1. N 5 . 5. "1 2 3" - while. , . - , shell, while. while N - . N. 2 , 1, . . $ redir N = 1 N = 2 N = 2 N = 2 N = 1 , shell, shell - . shell , ? . , , . : 1 : 2 # @(#) 3 4 echo " : \" 5 read CMD 6 7 eval $CMD 8 echo "\$? = $?" 9 10 if [ $? -eq 0 ] 11 then echo - $? 12 else echo - $? 13 fi , 4 . , 7 . , , - - "echo $HOME". eval , - 16 - $HOME. eval $HOME. eval . , $?. . 10 , . , . , , . $ status : ls -z ls : illegal option --z usage : -1ACFRabcdfglmnopqrstux [files] $? = 2 - 0 , ls . Ls 2. $? 0 . 8 ? . Vi UNIX - , shell. UNIX . , - . shell shell - vi. , , , .. - - . . vi ex. Vi - ex. , shell . - sh, ex. : sh vi "sh", ex. shell, sh. shell ? shell. shell - /bin/sh, - /bin/shV, , ":set sh=/bin/shV" vi - : :!sh "sh" shell (/bin/sh). , . shell ( :!), shell (:!sh). , , shell, , shell. ps, - 17 - UID PID PPID C STIME TTY TIME COMMAND russ 35 1 0 Jul 5 co 0:50 -shv russ 1233 35 0 04:30:15 co 0:57 vi file russ 1237 1233 0 04:43:13 co 0:01 sh -c sh russ 1238 1237 0 04:43:15 co 0:02 sh . vi shell - shell . shell! ":sh", . Escape , vi Esc, . , . - ":!cmd", . (1). - ":!!". (:!) shell. , : ":!ls", ":!!", :ls . ! - . - ":!%". (:!) , (%). , % - , . - : $ vi tool . . . edit . . . :w vi , vi "tool" . - , , . "tool" . "tool", , . - , , , , %, , , :!!, escape, :!% . , :!!. . , "cg" ( ) vi: F = 'echo $ 1 | sed -e "s/^\(.*\).c$/\1"' cc $1 -o $F : $ vi test.c ...edit... :!cg % - 18 - : !cg test.c "test". vi, , - . , , . , , . : i s/^[^ ]*/ [^ ]*/ "add @a , . ESC, . " , , , ". "add", "" a dd . . @a vi. , :!ps -ef . , @a, shell ps. a-z. - map. ex : vi. map : :map lhs rhs . : :map w :!who^M , w, ex, who, , . . , . Vi #0 -#9. . : :map #1 :!ps -ef^ , F1, - 19 - ps -ef. "One-Liners" - , - , , . , , UNIX . , , , . , , , , , , . , UNIX, - , . ACCTCOM * , . acctcom -b -u$LOGNAME * , , acctcom -u# -l'tty' BANNER * banner "line 1" "line2" "line3" * , banner "'date|cut -d' ' -f1,3'" "'date|cut -d''-f4'" * banner "" "" > /dev/tty01 BASENAME * echo " 'basename\'tty\' ' '' BC * bc, PROD PROD = 'echo $NUM1 * $NUM2 | bc' CAT - 20 - * cat > file ( ^D ) * " " cat << -! , ! CC * cc file1.c & cc file2 & cc file3.c & CD * , cd ' \' \'' * , DESTINATION="/usr/bin" cd $DESTINATION * , cd 'cat dest_file' CHMOD * chmod +x file * chmod 4755 file * sticky chmod 1755 file CHOWN * chown $LOGMAME files * chown 'who am i| cut -d' '-f1' files * - 21 - cd dest find . -print | sort | while read FILE do chown russ $FILE done CP * /tmp cp */*/* /tmp * cp 'find . -type f -print' /tmp * cp -z CPIO * cd $SRC find .-print | sort | cpio -pdv $DEST * cd $HOME find .-print | sort | cpio -ocBv > /dev/rfd0 * cd $DEST cpio -icBvt < /dev/rfd0 * "ls -l" cpio -icBvt < /dev/rfd0 CRON * 6:00 a.m. 0 6 * * 4 /usr/russ/bin/status_msg * chmod * * * * * /bin/su root -c "chmod 777 /etc/passwd" CU * 1200 cu -ltty00 dir * 9600 cu -ltty00 -s9600 dir * , dial/modem cu -acua0 555-1212 - 22 - CUT * passwd cut -d: -f1 /etc/passwd * who who | cut -d' ' -f1 who | awk '{print $1} DD * dd if = /dev/fd0 of=/dev/fd1 DOS * DOS doscp * a: * DOS dosls a: > /tmp/dosf for FILE in 'cat /tmp/dosf' do doscp a:$FILE done DU * / du -s /* * echo "total bytes: 'expr\'du -s $1\' \* 512'" ECHO * shell' echo $PATH $CDPATH * echo " $LOGNAME 'logname' 'who am i|cut -d' ' -f1'" * echo "\n\t " echo \\n\\t * - 23 - echo -n "prompt: " echo "prompt: \c" ED * ed " " ed /etc/passwd <<-! 1,$p g/root/s//noroot w q ! EXPR * expr 512 \* 1024 * x = 0; INC = 5 X='expr $X + $INC' FILE * file * | fgrep text * file * | fgrep text | cut -d: -f1 * more more 'file * | fgrep text | cut -d: -f1' FIND * find / -print | sort * long find / -exec ls -ld {} \; * find / -type f print * find / -type d print | while read DIR do echo "listing $DIR" ls $DIR done * , 24 long find / -atime -0 -exec ls -ld {} \; - 24 - * setuid setgid find / -perm -4000 -o -perm -2000 -exec ls -ld {} \; FINGER * , finger 'who | cut -d' ' -f1' * passwd cut -d: -f1 /etc/passwd | while read NAME do finger $NAME done GREP * od -x datafile | grep 'A3F09' * find / -type f print | while read FILE do grep "russ" $FILE /dev/null done HEAD * file * | fgrep text | cut -d: -f1 | while read FILE do echo "--------" echo "$FILE" echo "--------" head "$FILE" ID * , if [ "'id'" = "uid=0(root) gid=0(root)" ] then echo "you are root" fi * if id | fgrep root > /dev/null then echo "you are root" fi KILL * () kill -9 0 kill -9 $$ * kill -1 1 * , kill -9 $! - 25 - * , kill -9 'cat idfile' LINE * LINE='line < /dev/tty' * cat datafile | while LINE = 'line' do echo $LINE done LOGIN * login ??? login: ^d login: * ( strings - BSD) strings /bin/login | more LOGNAME * grep '^'logname ':' /etc/passwd * ps -fu 'logname' LS * ls -ad .* * ls -l file * ls -s file * ls -li 'who |sed "s/^[^ ]* *\([^ ]*\) .*$/\/dev\/\1/p"' * ls -z * ls -al |grep "^d" MAIL * - 26 - cut -d: -f1 |while read USER do echo "mailing to $USER" mail $USER done * mail russ < /etc/passwd * echo " " | mail russ MORE * more * * 10 more -10 file cat file | more -10 MKDIR * while : do mkdir x cd x done * PATH="x" while : do mkdir $PATH PATH="$PATH/x" done NCHECK * , vi ls -li /bin/vi 40 -rwwx--x--t 1109344 Feb 14 1985 /bin/vi ncheck -i 40 /dev/root * ncheck -s NM * nonstripped nm 'file *| grep "not stripped"|sed "s/^\(.*\):.*$/\1/" OD * - 27 - od -c . * , , ... od -cb ( ) ^d ( ) ( - ) ^d ( ) ^d ( od) * od -c /dev/rfd0 * od -c /dev/root PASSWD * # passwd russ Changing password for russ ( russ) Enter new password (minimum of 5 characters) ( ( 5 )) Please use combination of upper, lowercase letters and numbers ( ) New password: junk ( : junk) Re-enter new password: junk ( : junk) # * $ passwd russ Changing password for russ ( russ) Enter new password (minimum of 5 characters) ( ( 5 )) Please use combination of upper, lowercase letters and numbers ( ) New password: junk ( : junk) Too short. Password unchanged. ( . ) $ PR * ls $@ | pr -5t * - 28 - pr 'find . -name "*.c" -print | sort' PS * ps -aef * , ps -f * , tty00 ps -ft00 * , russ ps -furuss * BSD ps -aux * BSD , ps -xut00 PWD * PWD='pwd' * cd $PWD RM * , rm * * rmdir dirs * , rm -r dirs * , rm -rf * * rm -rf / SH * for ELEMENT in 'cat /etc/motd' do - 29 - echo $ELEMENT done * cat /etc/motd | while read LINE do echo $LINE done * - (while-forever) while : do echo $PS1 read CMD case $CMD in "") break;; esac done * while read CMD while [ "$CMD" != ""] do case $CMD in user-cmd) do_it;; esac echo $PS1 read CMD done * trap "echo trapping; kill $$" 2 3 15 * shell exit eof character (usually control -d) kill -9 0 kill -9 $$ STTY * stty -a * stty -a < /dev/tty01 * stty 300 < /dev/tty01 * control-A stty intr ^a * - stty -echo - 30 - SU * awk '{FS =":"; print $1,$5} '/etc/passwd|while read N C do echo "\n$N\t$C" su $N done TAIL * (logfile) uucp tail -f /usr/spool/uucp/LOGFILE * tail -1 file * 10 echo "$VAR" | tail -10c TAR * home- ,