Linux and Unix Shell -- 基础概念
No.1 Security --------------------------------- chmod g-w file_name //改变同组用户的写权限 chmod 644 file_name //用绝对值来修改权限 umask 022 //设置初始值权限(文件:644,目录:755) No.2 Find ---------------------------------- find . -name "*old*" -print //在当前路径下查询包含“old”关键字的文件 find . -name "[A-Z]*" -print //在当前目录下查询包含以大写字母开头的文件 find ~ -name "*.txt" -print //在$HOME 中查询文件名符合*.txt 格式的文件 find / -name "*" -print //查询根目录下的所有文件 find . -name "[a-z][a-z][0-9][0-9]" -print //在当前目录下查询以两个小写字母开头跟着两个数字的文件 find . -perm 755 -print //在当前目录下查询权限位为755的文件,即文件属主可以读写执行,其它用户可以读执行的文件 find . -user user_name -print //在当前目录下以文件属主名字来查询文件 find . -group group_name -print //在当前目录下以文件用户组来查询文件 find . -mtime -1 -print //在当前目录下查询更改时间子啊一日内的文件 find . -newer file_name // 在当前目录下查询比file_name更改时间新的文件 find . -type f -print // 在当前目录下查询 文件类型的文件 find . -name "con.file" -depth -print //查询名字为con.file的文件,首先匹配所有的文件,然后再进入子目录中查询 find . -type f -exec ls -l { } \ ; //在当前目录下查询文件类型的文件,然后执行ls -l 命令显示相应文件的信息 find . -type f -mtime +5 -ok rm { } \ ; //在当前目录下查询文件类型,并且更新时间超过5天的文件,然后在允许的条件下删除这些文件 find . type f -print | xargs chmod o-w //在当前目录下查询文件类型的所有文件,并收回other用户的写权限(xargs 和 exec区别在于,xargs对于find命令所匹配的文件,每次只获取一部分,而不是全部,逐批执行。而exec对参数长度有限制) No.3 Running on Background --------------------------------------------- 在$HOME目录下.profile文件添加一行:EDITOR=vi; export EDITOR 0,15,30,45 09-17 * * 1-5 /bin/echo 'date' >> /scratch/ziwzhang/Documents/time_log.txt // 分 时 日 月 星期 要运行的命令, 周一到周五,9点到17点,每隔15分钟在time_log.txt文件中添加一条时间记录。 crontab -l //显示当前crontab文件中的内容 crontab -e //编辑crontab文件 crontab -r //删除crontab文件 <command> >out.file 2>&1 & //后台执行该<command>,将输出重定向到out.file 中,错误也输入到out.file中。 <command> 2 > &1 > out. file //将标准输出重定向到out.file中,错误显示在终端。 ps -ef | grep 28305 // 查看关于28305的进程 kill 28305 /kill -9 28305 //杀死进程号为28305的进程 nohup <command> //退出账户仍执行<command> No.4 文件名置换 __________________________ ls app* //匹配文件名以app开头,后面跟随任何字符串的文件 ls conf??.log //匹配文件名以conf开头,中间是任意两个字符,最后以.log结尾的文件 ls [io]* //匹配文件名以i或者o开头的文件 ls log[0-9] //匹配文件以log开头,后面跟着一个数字的文件 ls LPS[!0-9] //匹配文件以LPS开头,后面跟着一个非数字的文件 No.5 Shell input and output __________________________ cd /bin ./sh read name //将把所有的输入赋予给name变量 echo "What is your name: " $ name //将What is your name: Wayne 这句话输出 cat file_name //显示文件中的内容 cat > file_name //文字编辑器,并将编辑好的文字保存到设置的file中。<crtl + D> 结束输入。 ls | grep *log* //管道,检索所有文件后进行进一步筛选。 date | tee -a files //在终端显示当前时间日期,并且把该时间日期保存到file中,-a:追加 ls >> res.out //重定向输出 cat < time_log.txt >> Test_file_1201 //以time_log.txt 的内容作为输入,重定向输出到Test_file_1201中。 cat >> file_name <<MAYDAY //一个分界符到下一个分界符之间的内容重定向到file中。 No.6 命令执行顺序 __________________________ mv /apps/bin /apps/dev/bin && rm -r /apps/bin //将/apps/bin文件夹复制到 /apps/dev/bin,如果成功,将原文件夹删除。 cp file1.txt file2.txt || echo "if you are seeing this cp failed." //如果copy失败,就会执行echo命令。 comet month_end || (echo "Comet did not work" | mail dave; exit) //如果comet执行不成功,发邮件给dave,然后退出。 No.7 正则表达式 __________________________ Ignore No.8 grep文本过滤 __________________________ cat > cat_test_file_120814 48 Dec 3BC1997 LPSX 68.00 LVX2A 138 483 Sep 5AP1996 USP 56.00 LVX2C 189 47 Oct 3ZL1998 LPSX 43.00 KVM9D 512 219 DeC 2CC1999 CAD 23.00 PLV2C 68 484 Nov 7PL1996 CAD 49.00 PLV2C 234 483 May 5PA1998 USP 37.00 KVM9D 644 216 Sep 3ZL1998 USP 86.00 KVM9E 234 grep -c "48" cat_test_file_120814 //输出匹配的行数 4 grep "48" cat_test_file_120814 //输出匹配的行 48 Dec 3BC1997 LPSX 68.00 LVX2A 138 483 Sep 5AP1996 USP 56.00 LVX2C 189 484 Nov 7PL1996 CAD 49.00 PLV2C 234 483 May 5PA1998 USP 37.00 KVM9D 644 grep -n "48" cat_test_file_120814 //输出匹配的行和行号 1:48 Dec 3BC1997 LPSX 68.00 LVX2A 138 2:483 Sep 5AP1996 USP 56.00 LVX2C 189 5:484 Nov 7PL1996 CAD 49.00 PLV2C 234 6:483 May 5PA1998 USP 37.00 KVM9D 644 grep -v "48" cat_test_file_120814 //输出不匹配的行 47 Oct 3ZL1998 LPSX 43.00 KVM9D 512 219 DeC 2CC1999 CAD 23.00 PLV2C 68 216 Sep 3ZL1998 USP 86.00 KVM9E 234 grep "48\>" cat_test_file_120814 //输出精确匹配的行 48 Dec 3BC1997 LPSX 68.00 LVX2A 138 grep -i "nov" cat_test_file_120814 //忽略大小写,输出匹配的行 484 Nov 7PL1996 CAD 49.00 PLV2C 234 grep -i "cad" cat_test_file_120814 //忽略大小写,输出匹配的行 219 DeC 2CC1999 CAD 23.00 PLV2C 68 484 Nov 7PL1996 CAD 49.00 PLV2C 234 grep '48[34]' cat_test_file_120814 //正则,单引号,输出483或者484匹配的行 483 Sep 5AP1996 USP 56.00 LVX2C 189 484 Nov 7PL1996 CAD 49.00 PLV2C 234 483 May 5PA1998 USP 37.00 KVM9D 644 grep '^48' cat_test_file_120814 //正则,输出行首为48的匹配行 48 Dec 3BC1997 LPSX 68.00 LVX2A 138 483 Sep 5AP1996 USP 56.00 LVX2C 189 484 Nov 7PL1996 CAD 49.00 PLV2C 234 483 May 5PA1998 USP 37.00 KVM9D 644 grep '^[^48]' cat_test_file_120814 //正则,输出行首不为48的匹配行 219 DeC 2CC1999 CAD 23.00 PLV2C 68 216 Sep 3ZL1998 USP 86.00 KVM9E 234 grep '[Ss]ep' cat_test_file_120814 //正则,输出Sep或者sep匹配行 483 Sep 5AP1996 USP 56.00 LVX2C 189 216 Sep 3ZL1998 USP 86.00 KVM9E 234 grep '[Ss]ep' cat_test_file_120814 | grep "483" //正则,管道,输出Sep或者sep,并且含有484的匹配行 483 Sep 5AP1996 USP 56.00 LVX2C 189 grep 'K...D' cat_test_file_120814 //正则,输出K...D匹配行 47 Oct 3ZL1998 LPSX 43.00 KVM9D 512 483 May 5PA1998 USP 37.00 KVM9D 644 grep '[A-Z][A-Z]..C' cat_test_file_120814 //正则,输出开头两个大写字母,末尾为C,并包含5个字符的匹配行 483 Sep 5AP1996 USP 56.00 LVX2C 189 219 DeC 2CC1999 CAD 23.00 PLV2C 68 484 Nov 7PL1996 CAD 49.00 PLV2C 234 grep '5..199[6,8]' cat_test_file_120814 //正则,输出5..199[6,8]的匹配行 483 Sep 5AP1996 USP 56.00 LVX2C 189 483 May 5PA1998 USP 37.00 KVM9D 644 grep '[0-9][0-5][0-6]' cat_test_file_120814 47 Oct 3ZL1998 LPSX 43.00 KVM9D 512 484 Nov 7PL1996 CAD 49.00 PLV2C 234 483 May 5PA1998 USP 37.00 KVM9D 644 216 Sep 3ZL1998 USP 86.00 KVM9E 234 grep '^[0-9][0-5][0-6]' cat_test_file_120814 216 Sep 3ZL1998 USP 86.00 KVM9E 234 grep '4\{2,\}' cat_test_file_120814 //正则,至少重复出现2次4的匹配行 483 May 5PA1998 USP 37.00 KVM9D 644 grep -E '219|216' cat_test_file_120814 //正则,出现219或者216的匹配行 219 DeC 2CC1999 CAD 23.00 PLV2C 68 216 Sep 3ZL1998 USP 86.00 KVM9E 234 grep '^$' cat_test_file_120814 //正则,匹配空行 grep '12$' cat_test_file_120814 //正则,输出以12 为行尾的匹配行 47 Oct 3ZL1998 LPSX 43.00 KVM9D 512 sh-4.1$ read str //匹配字符串变量 Mary Joe Peter Pauline sh-4.1$ echo $str | grep "Mary" Mary Joe Peter Pauline ps ax | grep "named" //匹配进程 6623 pts/2 S+ 0:00 grep named No.9 awk从文本文件和字符串中抽取信息 -------------------------------------------------------------------------- cat awk_test_file_120914 M.Tansley 05/99 48311 Green 8 40 44 J.Lulu 06/99 48317 green 9 24 26 P.Bunny 02/99 48 Yellow 12 35 28 J.Troll 07/99 4842 Brown-3 12 26 26 L.Tansley 05/99 4712 Brown-2 12 30 28 awk '{print $0}' awk_test_file_120914 //打印所有记录 awk '{print $1,$4}' awk_test_file_120914 //打印域1和域4的内容 awk 'BEGIN{print "NAME BELT\n--------------"}{print$1,$4}END{print "end of report"}' awk_test_file_120914 //打印信息头尾 awk '{if($4~/Brown/) print $0}' awk_test_file_120914 //正则,如果域4匹配Brown模式,打印符合条件的信息 awk '{if($3==48) print $0}' awk_test_file_120914 //精确匹配 awk '{if($4!~/Brown/)print $0}' awk_test_file_120914 //不匹配 awk '{if($6<$7) print $1 "try better at the next comp"}' awk_test_file_120914 //变量与字符串对接 awk '/[Gg]reen/' awk_test_file_120914 //正则,打印匹配Green或green的行信息 awk '$0~/(Yellow|Brown)/' awk_test_file_120914 //正则,打印匹配Yellow或者Brown的行 awk '{if($1=="P.Bunny"&&$4=="Yellow")print $0}' awk_test_file_120914 //并 awk 'END {print NR}' awk_test_file_120914 //输出已读记录数 awk 'END{print NF}' awk_test_file_120914 //输出浏览记录的域个数 awk '{name=$1;belts=$4;if(belts~/Yellow/)print name "is belt "belts}' awk_test_file_120914 //设置域变量名 awk '{if($1=="M.Tansley"){ $6=$6-1; print $1,$6,$7}}' awk_test_file_120914 //赋值运算,只显示被修改的记录 awk 'BEGIN{print "NAME\t DIFF"}{if($6<$7){$8=$7-$6;print $1,$8}}' awk_test_file_120914 //显示创建新的输出域 awk 'total+=$6; END{print "CLUB STUDENT TOTAL POINTS; " total}' awk_test_file_120914 //显示增加列值,并显示全部记录 awk '{total+=$6;} END{print "CLUB STUDENT TOTAL POINTS; " total}' awk_test_file_120914 //只输出增加列值 awk 'gsub(/4842/,4899){print $0}' awk_test_file_120914 //在整个记录中替换一个字符串为另一个 awk 'BEGIN{print length("THIS IS A TEST!")}' //显示字符串的长度 awk 'BEGIN{print match("ABCD","C")}' //显示首位置匹配的字符数 awk 'BEGIN{print split("123#456#789",myarray,"#")}' //显示数组myarray的下表数 awk '$1=="L.Tansley" {print substr($1,1,5)}' awk_test_file_120914 No.10 sed文本编辑 ---------------------------------------------------------------------- cat sed_test_file_121614 The honeysuckle band played all night long for only $90. It was an evening of splendid music and company. Too bad the disco floor fell through at 23:10. The local nurse Miss P.Neave was in attendance. sed -n '2p' sed_test_file_121614 //只显示第二行 It was an evening of splendid music and company. sed -n '1,3p' sed_test_file_121614 //显示一到三行 The honeysuckle band played all night long for only $90. It was an evening of splendid music and company. Too bad the disco floor fell through at 23:10. sed -n '/Neave/p' sed_test_file_121614 // 只显示匹配的行 The local nurse Miss P.Neave was in attendance. sed -n '4, /The/p' sed_test_file_121614 // 只在第四行查询匹配并显示 The local nurse Miss P.Neave was in attendance. sed -n '/\$/p' sed_test_file_121614 //反斜杠屏蔽其特殊含义 The honeysuckle band played all night long for only $90. sed -n '1,$p' sed_test_file_121614 //显示整个文件 The honeysuckle band played all night long for only $90. It was an evening of splendid music and company. Too bad the disco floor fell through at 23:10. The local nurse Miss P.Neave was in attendance. sed -n '/music/=' sed_test_file_121614 //只显示匹配的行号 2 sed -n -e '/music/p' -e '/music/=' sed_test_file_121614 //显示匹配行和行号 It was an evening of splendid music and company. 2 sed '/company/a\Then suddenly it happened.' sed_test_file_121614 > sed.out //在匹配行后下一行附加文本,并将输出结果输入到sed.out The honeysuckle band played all night long for only $90. It was an evening of splendid music and company. Then suddenly it happened. Too bad the disco floor fell through at 23:10. The local nurse Miss P.Neave was in attendance. sed '/attendance/i\utter confusion followed.' sed_test_file_121614 //在匹配行前一行插入文本。 The honeysuckle band played all night long for only $90. It was an evening of splendid music and company. Too bad the disco floor fell through at 23:10. utter confusion followed. The local nurse Miss P.Neave was in attendance. sed '/honeysuckle/c\The Office Dibble band played well' sed_test_file_121614 //替换匹配行 The Office Dibble band played well It was an evening of splendid music and company. Too bad the disco floor fell through at 23:10. The local nurse Miss P.Neave was in attendance. sed '1d' sed_test_file_121614 // 删除第一行 It was an evening of splendid music and company. Too bad the disco floor fell through at 23:10. The local nurse Miss P.Neave was in attendance. sed 's/night/Night/' sed_test_file_121614 //替换文本 The honeysuckle band played all Night long for only $90. It was an evening of splendid music and company. Too bad the disco floor fell through at 23:10. The local nurse Miss P.Neave was in attendance. sed 's/The/Wow/g' sed_test_file_121614 // 全局替换 Wow honeysuckle band played all Night long for only $90. It was an evening of splendid music and company. Too bad the disco floor fell through at 23:10. Wow local nurse Miss P.Neave was in attendance. sed 's/splendid/Splendid/w sed.out' sed_test_file_121614 //将替换行输入到sed.out 文件中 It was an evening of Splendid music and company. sed -n 's/nurse/"Hello" &/p' sed_test_file_121614 // 在匹配文本之前附加“Hello” The local "Hello" nurse Miss P.Neave was in attendance. sed -n 's/company/& place/p' sed_test_file_121614 //在匹配文本之后附加place It was an evening of splendid music and company place. sed '/company/r sed.out' sed_test_file_121614 //从文件中读文本,并附加到匹配行后下一行 The honeysuckle band played all night long for only $90. It was an evening of splendid music and company. This is test ! Too bad the disco floor fell through at 23:10. The local nurse Miss P.Neave was in attendance. No.11 合并与分割 ------------------------------------------------------- cat sort_test_file_121814 Boys in Company C:HK:192:2192 Alien:HK:119:1982 The Hill:KL:63:2972 Aliens:HK:532:4892 Star Wars:HK:301:4102 A Few Good Men:KL:445:5851 Toy Story:HK:239:3972 Alien:HK:119:1982 sort -t: sort_test_file_121814 //-t: 分隔符,按第一域分类 A Few Good Men:KL:445:5851 Alien:HK:119:1982 Alien:HK:119:1982 Aliens:HK:532:4892 Boys in Company C:HK:192:2192 Star Wars:HK:301:4102 The Hill:KL:63:2972 Toy Story:HK:239:3972 sort -t: -r sort_test_file_121814 // 按第一域逆向排序 Toy Story:HK:239:3972 The Hill:KL:63:2972 Star Wars:HK:301:4102 Boys in Company C:HK:192:2192 Aliens:HK:532:4892 Alien:HK:119:1982 Alien:HK:119:1982 A Few Good Men:KL:445:5851 sort -t: -k3 sort_test_file_121814 //按第三域排序,只看第三域第一个数字大小。 Alien:HK:119:1982 Alien:HK:119:1982 Boys in Company C:HK:192:2192 Toy Story:HK:239:3972 Star Wars:HK:301:4102 A Few Good Men:KL:445:5851 Aliens:HK:532:4892 The Hill:KL:63:2972 sort -t: -k3 -n sort_test_file_121814 //按第三域数值大小排列 The Hill:KL:63:2972 Alien:HK:119:1982 Alien:HK:119:1982 Boys in Company C:HK:192:2192 Toy Story:HK:239:3972 Star Wars:HK:301:4102 A Few Good Men:KL:445:5851 Aliens:HK:532:4892 sort -u sort_test_file_121814 //去除重复行 A Few Good Men:KL:445:5851 Alien:HK:119:1982 Aliens:HK:532:4892 Boys in Company C:HK:192:2192 Star Wars:HK:301:4102 The Hill:KL:63:2972 Toy Story:HK:239:3972 sort -t: -k1.2 sort_test_file_121814 //按第一域第二个字符排序 A Few Good Men:KL:445:5851 The Hill:KL:63:2972 Alien:HK:119:1982 Alien:HK:119:1982 Aliens:HK:532:4892 Toy Story:HK:239:3972 Boys in Company C:HK:192:2192 Star Wars:HK:301:4102 sort -t: -r -k4 sort_test_file_121814 | head -1 //显示按第四域逆排序最大值 A Few Good Men:KL:445:5851 sort -t: -r -k4 sort_test_file_121814 | tail -1 //显示按第四域逆排序最小值 Alien:HK:119:1982 cat sort2 May Day May Day May Day Jan Day Jan Day May Day uniq -u sort2 //只显示不重复行 May Day uniq -d sort2 //只显示有重复行 May Day Jan Day uniq -c sort2 //打印显示重复行数目 3 May Day 2 Jan Day 1 May Day cat join_test1 M.Golls 12 Hidd Rd P.Heller The Acre P.Willey 132 The Grove T.Norms 84 Connaught Rd K.Fletch 12 Woodlea cat join_test2 M.Golls Norwich NRD P.Willey Galashiels GDD T.Norms Brandon BSL K.Fletch Mildenhall MAF join join_test1 join_test2 //连接两个文件 K.Fletch 12 Woodlea Mildenhall MAF M.Golls 12 Hidd Rd Norwich NRD P.Willey 132 The Grove Galashiels GDD T.Norms 84 Connaught Rd Brandon BSL join -a1 -a2 join_test1 join_test2 //不匹配连接 K.Fletch 12 Woodlea Mildenhall MAF M.Golls 12 Hidd Rd Norwich NRD P.Heller The Acre P.Willey 132 The Grove Galashiels GDD T.Norms 84 Connaught Rd Brandon BSL join -o 1.1,2.2 join_test1 join_test2 //显示第一个文件第一域和第二个文件第二个域 K.Fletch Mildenhall M.Golls Norwich P.Willey Galashiels T.Norms Brandon cut -d: -f1-3 sort_test_file_121814 //剪切第1-3域的内容 Boys in Company C:HK:192 Alien:HK:119 The Hill:KL:63 Aliens:HK:532 Star Wars:HK:301 A Few Good Men:KL:445 Toy Story:HK:239 Alien:HK:119 cut -c1-6 sort2 //剪切1-6的字符 May Da May Da May Da Jan Da Jan Da May Da cut -c1,6 sort2 //剪切1和6的字符 Ma Ma Ma Ja Ja Ma No.12 tr字符替换和删除 _______________________________ cat oops.txt And the cowwwwws went homeeeeeeeee or did theyyyy tr -s "[a-z]" <oops.txt //去除重复字母,使用-s And the cows went home or did they cat plane.txt 987932 Spitfire 190993 Lancaster 238991 Typhoon tr -s "[\n]" < plane.txt //去除空行 987932 Spitfire 190993 Lancaster 238991 Typhoon echo "May Day, May Day, Going Down.." | tr "[a-z]" "[A-Z]" //大写替换小写 MAY DAY, MAY DAY, GOING DOWN.. No.13 登录环境 _______________________________ Ignore No.14 Shell 变量 _______________________________ 本地变量: sh-4.1$ set //显示所有本地shell变量 FULLNAME="WAYNE GRANGE" //设置变量FULLNAME,并显示 sh-4.1$ echo ${FULLNAME} WAYNE GRANGE unset FULLNAME sh-4.1$ echo "My name is ${FULLNAME:-Wayne Granger}" //如果未设置变量FULLNAME值,设置其值,但不存储 My name is Wayne Granger echo "The file is ${FILES:?}" //测试变量是否取值 sh: FILES: parameter null or not set readonly //查看所有只读变量 readonly FULLNAME //将变量设置为只读变量 环境变量: env //可以查看所有的环境变量 CONSOLE=tty1; export CONSOLE //设置环境变量并显示 echo $CONSOLE tty1 位置变量: cat > plane.txt #!/bin/sh # allparams echo "This is the script name :$0" echo "This is the first parameter :$1" echo "This is the second parameter :$2" echo "This is the third parameter :$3" echo "This is the fourth parameter :$4" echo "This is the fifth parameter :$5" echo "This is the sixth parameter :$6" echo "This is the seventh parameter :$7" echo "The number of arguments passed :$#" echo "Show all arguments :$*" echo "Show me my process ID :$$" echo "Did my script go with any errors :$?" ./plane.txt Merry Chirstmas Mr Lawrence This is the script name :./plane.txt This is the first parameter :Merry This is the second parameter :Chirstmas This is the third parameter :Mr This is the fourth parameter :Lawrence This is the fifth parameter : This is the sixth parameter : This is the seventh parameter : The number of arguments passed :4 Show all arguments :Merry Chirstmas Mr Lawrence Show me my process ID :13387 Did my script go with any errors :0 No.15 引号 ----------------------------------------------------------- expr 12 \* 12 // \屏蔽特殊含义 144 echo `date` // 反引号用于设置系统命令的输出 Tue Dec 23 21:51:46 PST 2014 No.16 Shell Script —————————————————— ignore No.17 条件测试 __________________________________ test -w plane.txt //测试文件是否可写 echo $? 0 test -x sort2 //测试文件是否可执行 echo $? 1 test -f shfis -o -x plane.txt //测试是否存在文件shfis或者文件plane是否可执行,两者之一为真,结果为真 echo $? 0 test -f shfis -a -x plane.txt //与 echo $? 1 test "shift" = "shisFt" echo $? //测试两个字符串是否相等 1 sh-4.1$ Number=130 //测试两个数值是否相等 sh-4.1$ test $Number -eq "130" sh-4.1$ echo $? 0 sh-4.1$ expr 10 + 10 //数值计算 20 No.18 控制流结构 ________________________________ if then else ex. 3Paras.src create_file.src findname.src show_name.src copy_file.src case ex. weeklyreport.src for ex. filecounter.src while ex. while_read.src No.19 Shell 函数 ________________________________ 查看字符串长度的函数 check_length 将文件内容修改为大写的函数 file_to_upper 只允许字符名字输入的函数 name_fuc 给文件标出行号的函数 number_file 将字符串修改为大写的函数 str_to_upper No.20 向脚本传递参数 ________________________________ How to use shift to pass parameters to script: shift_case No.21 创建屏幕输出 坐标函数 cup_case 使用颜色,坐标,居中等函数的屏幕输出: output_screen No.22 ————————————————— Ignore No.23 调试脚本 ________________________________ set -x //可以辅助脚本调试 set +x //关闭脚本调试 No.24 Shell嵌套命令 _________________________________ 嵌入命令实在实际的shell里创建的而不是存在于/bin目录里。嵌入命令比相同的系统命令快的多。 No.25 <<的作用 _________________________________ 快速创建一个文件 cat >> myfile << MAYDAY ***** MAYDAY //分隔符的作用 快速创建打印文档 自动ftp传输 ftp 传输: ftp -i -n slc03qdi user aime1 PASSWORD: ******* lcd /scratch/user/Documents/ get remotefiles exit No.26 Shell工具 —————————————————— date +%d%m%y //以年月日的形式输出日期 120115 date +%A //输出星期 Monday date +%e //输出日 12 date +%R //输出时间 19:11 date +%p //输出上下午 PM date +%T //输出完整时间 19:14:00 注意:如果希望在日期和时间的显示中包含空格,要使用双引号 捕获信号并采取行动 trap “commands” 2 //trap_signal.src Myfile="cat /scratch/ziwzhang/Documents/File_Test/eval_test" echo $Myfile cat /scratch/ziwzhang/Documents/File_Test/eval_test eval $Myfile //两次扫描变量 May Day, May Day Going Down No.27 脚本案例 __________________________________ pingall //ping 文本上所有的主机地址 No.28 运行级别脚本 __________________________________ Ignore No.29 cgi脚本 __________________________________ ignore
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。