2022年Shell经典实例 .pdf





《2022年Shell经典实例 .pdf》由会员分享,可在线阅读,更多相关《2022年Shell经典实例 .pdf(20页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Shell ?- ? y.txt21o?a?1?- 1y? ? Do?1?D?D? o ? ?1?y?3? D? ? D?a?2?Thizlinux ? 3?3 Shell ?-? y -Milo ?- ?D?shell 1 D? ?shell ?o ?#!/bin/sh ?# dtree: Usage: dtree any directory ?dir=$1:-. ?(cd $dir; pwd) find $dir -type d -print | sort -f | sed -e s,$1, -e /$/d -e s,/*/(/*)$,-1, -e s,/*/,| ,g 2 while?D
2、 1?read (file?t) cat file | while read line do echo $line echo : Please input any key(s):c str4read= while true do chr4read=dd if=/dev/tty bs=1 count=1 2/dev/null str4read=$str4read$chr4read 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 20 页 - - - - - - - - -
3、if $chr4read = ;then break; fi done echo : |$str4read| done 3 ? ?a? sed s/ */ /g ?1?tab12 ? ? sed -e s/:space:space:*/ /g filename 4? ?t #!/bin/bash if $# -ne 2 ; then echo Usage: split file size(in bytes) exit fi file=$1 size=$2 if ! -f $file ; then echo $file doesnt exist exit 名师资料总结 - - -精品资料欢迎下载
4、 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 20 页 - - - - - - - - - fi #TODO: test if $size is a valid integer filesize=/bin/ls -l $file | awk print $5 echo filesize: $filesize let pieces=$filesize/$size let remain=$filesize-$pieces*$size if $remain -gt 0 ; then let pieces=$piec
5、es+1 fi echo pieces: $pieces i=0 while $i -lt $pieces ; do echo split: $file.$i: dd if=$file of=$file.$i bs=$size count=1 skip=$i let i=$i+1 done 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 20 页 - - - - - - - - - echo #!/bin/bash merge echo i=0 merge echo wh
6、ile $i -lt $pieces ; merge echo do merge echo echo merge: $file.$i merge echo if ! -f $file.$i ; then merge echo echo merge: $file.$i missed merge echo rm -f $file.merged merge echo exit merge echo fi merge echo dd if=$file.$i of=$file.merged bs=$size count=1 seek=$i merge echo let i=$i+1 merge echo
7、 done merge chmod u+x merge 5? ? ?aYYYYMMDD get_lastday_of_lastmonth() yy=date +%Y mm=date +%m-1|bc 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 20 页 - - - - - - - - - $mm -lt 1 & mm=12;yy=expr $yy - 1 aaa=cal $mm $yy dd=echo $aaa|awk print $NF echo $yy$mm$dd
8、 print $NF ?$NF? ?o ?D? ?aawk?NF ?D? y?$NF? ?o ?D 6 ?backup?tar? ? ?Y D a 3? ?D?t ? ? 1?2? ?112? 1y1 ?taro backup? ?2?D a?D?archive ? ? ?1? ? (cd /source & tar cf - .) |(cd /dest & tar zxfp -) ?D backup ? ? tar ?1 ? ? tar -cf - dir1 | ( cd dir2; tar -xvf - ) ? more aaa.sh #?D? #date1,date2:yyyymmdd
9、#Usage:command date1 date2 str=$1 yy1=echo $str|cut -c 1-4 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 20 页 - - - - - - - - - mm1=echo $str|cut -c 5-6 dd1=echo $str|cut -c 7-8 str=$2 yy2=echo $str|cut -c 1-4 mm2=echo $str|cut -c 5-6 dd2=echo $str|cut -c 7-8
10、count_day=expr $dd2 - $dd1 while $yy2 -ne $yy1 -o $mm2 -ne $mm1 do mm2=expr $mm2 - 1 $mm2 -eq 0 & mm2=12 & yy2=expr $yy2 - 1 aaa=cal $mm2 $yy2 bbb=echo $aaa|awk print $NF count_day=expr $count_day + $bbb done echo $count_day 7 D ?D ?DDtelnet ?shell ?a? ? ?2 DD?a ?unxi? ? ?1 ? ?o ?shell? ? ?1?telnet?
11、 ?2?D ? cd?ls ? ? ?3 ?1 ? ?shell2? ? .profile?D? ?o read addr telnet $addr 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 20 页 - - - - - - - - - exit 8 ?D?t ? ?T?2?600 ls -l filename | awk if($1 -rw-) . ls -l filename | grep -rw- -c #!/usr/bin/bash #showmod $#
12、-eq 0 & echo Usage: $0 filelist . ; exit ; show() -d $1 & ls -ld $1 ; -f $1 & ls -la $1 ; | awk umask=0 umask_= for(i=1;i %s ,$9,$1,umask_); ; for file_dir in $* do show $file_dir done 9 ? ? maxcount=$1; count=1; if $# -eq 1 then while $count -le $maxcount do echo $count ? $count ? , expr $count * 2
13、?|,expr $count * 4 ? ; count=expr $count + 1; done; else 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 20 页 - - - - - - - - - echo usage: sendos count fi 10 ? SHELL3 D?D ? ?a?D? ?D ?SHELL3 D ? ?a?READ? ? ?D? ?3?2? ?D a?a ? ? ?TD? ?3?D2?o? ? #!/bin/sh get_char(
14、) SAVEDSTTY=stty -g stty -echo stty raw dd if=/dev/tty bs=1 count=1 2 /dev/null stty -raw stty echo stty $SAVEDSTTY echo Press any key to continue. char=get_char ?1? ?2?stty raw? ?o y?D?|3? ?raw?3cbreak? 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 20 页 - - -
15、 - - - - - - 11 ? linux? ?3? ?anumlock ? 3? ? ?aNumLock ? ?/etc/rc.d/rc.local?D? ? Yo ?for t in 1 2 3 4 5 6 7 8 ?do ? setleds +num ? $t/dev/null ?done 12 ? shell ?o?T?3? ?y ? ? ? ?8?1?3?1y?8?1a ? ?1? ? ?2?D? y?3?a?o D?SHELL ? ? ? ?1?3?3?1a ? ? ?o ? ?D?D? 1?y?D?y ? ? ?32?3?1y8? ?6?o?3 ?2? ? a? 8? ?32
16、? ? ? ?t?: input.sh ? oinput.sh ?T?3? yoinput.sh 8 ?T?8? #?/bin/ksh # Program Name : input.sh trap 1 2 3 5 7 9 15 13 getcon() stty raw -echo conchar=dd if=/dev/tty bs=1 count=1 2/dev/null 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 20 页 - - - - - - - - - st
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年Shell经典实例 2022 Shell 经典 实例

限制150内