第5章Shell基础.ppt

上传人:本田雅阁 文档编号:2577888 上传时间:2019-04-11 格式:PPT 页数:23 大小:300.51KB
返回 下载 相关 举报
第5章Shell基础.ppt_第1页
第1页 / 共23页
第5章Shell基础.ppt_第2页
第2页 / 共23页
第5章Shell基础.ppt_第3页
第3页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《第5章Shell基础.ppt》由会员分享,可在线阅读,更多相关《第5章Shell基础.ppt(23页珍藏版)》请在三一文库上搜索。

1、第5章 Shell基础,内容概要,使用 通配符 编译相似名称的文件 使用 重定向符 和 管道符 控制进程的 输入输出 使用 行继续符 使命令生效看到命令行 使用组命令控制其执行,关于Shell,Korn (ksh) 或 Bourne (bsh) 或 C (csh) 用户与 AIX的交互页面 翻译命令 可以多线任务 全面的编程语言,特殊符号和通配符,特殊符号是那些在shell编译中有着特殊含义的符号 例: | ; ! * ? $ “ 通配符是一组用来搜索和匹配文件类型的特殊符号 例: * ? ! - ,文件名替换,通配符: * ? 单字符替换: $ ls ne? net new $ rm ?e?

2、 few net new 多字符比较: $ cp n* /tmp ne net new nest $ qprt *w new few $ echo test1* test1 test1.2 test1.3,文件名替换,内含的替换: ! - $ ls nestw net new $ rm fghjdnetw few net new $ ls *1-5 test1 test1.2 test1.3 $ qprt !tn* myfile few $ cat ?!y*2-5 test1.2 test1.3,标准文件,标准输入(0) 标准输出(1) 错误输出(2),cmd,文件描述符,当开始运行共有三种文

3、件描述符 标准输入: 1 标准错误: 2 2,输入重定向,默认标准输入 $ mail team01 Subject: Letter This is a letter. Cc: $ 从一个文件重定向输入: $ mail team01 letter $,输出重定向,默认标准输出: $ ls file1 file2 file3 从一个文件重定向输出: $ ls ls.out $ 向一个文件增添更改重定向输出: $ who whos.there $,使用 cat创建文件,普通方式使用cat来列出文件目录,配合重定向符可以创建文件: 使用重定向符 $ cat newfile This is line 1

4、 of the file. This is the 2nd line. And the last. $ ls letter acctfile file1 newfile,$ ls letter acctfile file1 $ cat file1 This is a test file. The file has 2 lines $,小测试,下列命令执行后,将列出哪些文件? $ ls /home/team01/*.? $ ls /tmp/a-zA-Z*.0-9 T或F:命令“ ls * ”列出当前目录中所有文件 写出下列命令的文件描述符 $ wc -l /tmp/lines 标准输入: 标准输

5、出: 标准错误: 想要把添加 testfile1 到 report99 后面.哪条命令是正确的? cat report99 report99 cat testfile1 report99 cat testfile1 report99,错误重定向,默认标准错误: $ cat filea fileb This is output from filea. cat: cannot open fileb 重定向错误输出到一个文件: 2 (若要追加: 2) $ cat filea fileb 2 errfile This is output from filea $ cat errfile cat: ca

6、nnot open fileb $ cat filea fileb 2 /dev/null This is output from filea,组合重定向,组合重定向: $ command outfile 2 errfile appendfile 2 errfile outfile 2&1 注意:下例与上面不同 $ command 2&1 outfile,管道,使用 “|”将一组命令顺序分割,”|” 叫做管道符. 前一条命令的标准输出变成了下一条命令的标准输入: $ who | wc -l 4 下面的例子也是这样: $ who tempfile $ wc -l tempfile 4 tempf

7、ile $ rm tempfile,过滤器,过滤器是读取标准输入,用某种方式将输入转化然后进行输出的命令 例: ls -l | grep “d“ | wc l,Long listing of all files: -rwxr-xr-x . file1 drwxr-xr- . dir1 -rwxr-r- . file2,Find all lines that begin with a “d“: drwxr-xr- . dir1,Count all lines (directories),“T”型输出,tee 命令读取标准输入并将数据同时发送到标准输出和文件中 ls | tee /tmp/ls.s

8、ave | wc -l,cow fox ox,/tmp/ls.save,3,cow fox ox,tee,ls,wc -l,命令分组,多个命令可以在同一行运行,使用 “;“ : $ ls -R outfile ; exit 等同于换行输入: $ ls -R outfile $ exit,续行符,反斜线()后接一个新行字符可以用来在另一航继续命令 Shell将发出一个次级提示符“” 来声明行的延续 $ cat /home/mydir/mysubdir/mydata /home/yourdir/yoursubdir/yourdata,课堂练习,下列命令将会匹配什么? $ ls ?!a-z*0-9t

9、 对于问题2-4,分别声明标准输入,标准输出和标准错误将发送到哪里. $ cat file1 标准输入 (0): 标准输出 (1): 标准错误 (2): $ mail tim letter 标准输入 (0): 标准输出 (1): 标准错误 (2):,$ cat .profile newprofile 21 standard input (0): standard output (1): standard error (2): 对于问题567,创建命令行cat来显示filea的概括然后执行下列操作: 把命令的标准输出放到 fileb 把错误放到 filec. 把命令的标准输出放到 fileb a

10、nd 若存在错误则一同放到 fileb. 把标准输出放到fileb并抛弃错误. (不显示或保存错误信息。),课堂练习,课堂练习答案,下列命令将会匹配什么? $ ls ?!a-z*0-9t This will list all the files that match the following criteria: the first three characters can be anything the fourth character must not be from the range a to z zero or more characters can follow the secon

11、d-last character must be from the range 0 to 9 the last character must be a t. 对于问题2-4,分别声明标准输入,标准输出和标准错误将发送到哪里. $ cat file1 标准输入 (0):keyboard 标准输出 (1):screen 标准错误 (2):screen $ mail tim letter 标准输入 (0):letter 标准输出 (1):screen 标准错误 (2):screen,$ cat .profile newprofile 21 standard input (0):keyboard standard output (1):newprofile standard error (2): a file named 1 对于问题567,创建命令行cat来显示filea的概括然后执行下列操作: 把命令的标准输出放到 fileb 把错误放到 filec. $ cat filea fileb 2 filec 把命令的标准输出放到 fileb and 若存在错误则一同放到 fileb. $ cat filea fileb 2&1 把标准输出放到fileb并抛弃错误. (不显示或保存错误信息。) $ cat filea fileb 2 /dev/null,课堂练习答案,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1