《aix系统应用基础》08 shell basics.ppt

上传人:京东小超市 文档编号:5839145 上传时间:2020-08-11 格式:PPT 页数:25 大小:309KB
返回 下载 相关 举报
《aix系统应用基础》08 shell basics.ppt_第1页
第1页 / 共25页
《aix系统应用基础》08 shell basics.ppt_第2页
第2页 / 共25页
亲,该文档总共25页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《《aix系统应用基础》08 shell basics.ppt》由会员分享,可在线阅读,更多相关《《aix系统应用基础》08 shell basics.ppt(25页珍藏版)》请在三一文库上搜索。

1、 Copyright IBM Corporation 2008,Unit 8 Shell Basics,更侍蚜车钦舶就熏懦筏锤艳豺海蔷逆寞浴礁刊喊秆猴犁匝胜优曲担利肠珊aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Unit Objectives,After completing this unit, you should be able to: Use wildcards to access files with similar names Use redirection and

2、 pipes to control the input and output of processes Use line continuation to enter commands that span the command line Group commands in order to control their execution,崩实祁匣校硒笨康滦揣释椰汽铱讶驳霹馒凡法湍柜容造刹淖照日靡少炙僚aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,The Shell,Korn (k

3、sh) or Bourne (bsh) or C (csh) User interface to AIX Command interpreter Enables multiple tasks Comprehensive programming language,衷开姨焙渐交埂镍钵诉晕稽荐罗抛椿诊缨轨直捣呼沽纪颁启侮猛荷嚣芭嚏aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Metacharacters and Wildcards,Metacharacters are characte

4、rs that the shell interprets as having a special meaning. Examples: | ; ! * ? $ “ Wildcards are a subset of metacharacters that are used to search for and match file patterns. Examples: * ? ! - ,榨角词烁囱倪蛊忘屈娠岸寞救许阿剁男直蚌矩苯瞎喉跪隧剑昔外懦册沈躬aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporati

5、on 2008,/ home team01 test1 test1.2 test1.3 myfile ne net new nest few,File Name Substitution (1 of 2),Wildcards: * ? One character compare: $ ls ne? net new $ rm ?e? few net new Multiple character compare: $ cp n* /tmp ne net new nest $ qprt *w new few $ echo test1* test1 test1.2 test1.3,介舵琳肘趣袖鹿釉幅荡

6、虱棕瞎伸亦织赤韵氏垃艳厘场够夹免停恋弦植园养aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Inclusive Lists: ! - $ 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,/ home team01 test1 test1.2 test1.3 myfile ne

7、 net new nest few,File Name Substitution (2 of 2),齿申脚逾摹荆坦砰奥牧犯昆横坍哦膏形墒咎睁褥锋是难撞墩饰惋关呸淑都aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,standard in (0),standard error (2),standard out (1),cmd,The Standard Files,嗅付瑟空镭团册筐反独草翱碗搁栈贵婶正坊芋腺掸温斡膏峦秋腐鼠蔑榆犬aix系统应用基础08 shell basicsaix系统应

8、用基础08 shell basics, Copyright IBM Corporation 2008,Standard in: 1 Standard error: 2 2,File Descriptors,Three descriptors are assigned by the shell when the program starts:,抉尾纹术蓟盘涅颇编乒虚混书季膝装座条茸享敝到荤叔吉械裁阶弃狞忱春aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Input Redirecti

9、on,Default standard input $ mail team01 Subject: Letter This is a letter. Cc: $ Redirect input from a file: $ mail team01 letter $,幻醚高嗡渔狗三啮醋扳硅弛虱睫岔歪买镑寒妮铰嚼氮肿临倚角庇候药将咖aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Output Redirection,Default standard output: $ ls file1 f

10、ile2 file3 Redirect output from a file: $ ls ls.out $ Redirecting and appending output to a file: $ who whos.there $,坝午渍牲猜爵黎迷疯柑侄茎淹势蝗嫉趾劫酱邱煮咙伯葱拷灾曾搓峰孕崭宿aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Creating a File with cat,While normally used to list the contents of f

11、iles, using cat with redirection can be used to create a file: $ ls letter acctfile file1 $ cat file1 This is a test file. The file has 2 lines. $ Using redirection: $ cat newfile This is line 1 of the file. This is the 2nd line. And the last. $ ls letter acctfile file1 newfile,碑辕留果堵魔夏邹井包逆激对蕾哗这逢睁耕残躇

12、涝沥阻偷惦逛稻洋尊论失aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Activity: Review Shell Basics,Which files are listed when the following commands are executed? $ ls /home/team01/*.? $ ls /tmp/a-zA-Z*.0-9 True or False: The command “ls *“ lists all files in a directory. Wri

13、te down the file descriptors for the following command: $ wc -l /tmp/lines Standard input: Standard output: Standard error: You want to append file testfile1 to file report99. Which command is correct? cat report99 report99 cat testfile1 report99 cat testfile1 report99,领英篓虑蚕又奸拳期舀窄峦邵沉直彼毫篡洱睫玩嚏兄爪厚金呜醇角撅

14、赚刘aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Error Redirection,Default standard error: $ cat filea fileb This is output from filea. cat: cannot open fileb Redirecting error output to a file: 2 (To append: 2) $ cat filea fileb 2 errfile This is output from filea

15、$ cat errfile cat: cannot open fileb $ cat filea fileb 2 /dev/null This is output from filea,率键数子旱酱棱失桑搏巡肃割绘妊售柬荒孩阑娱怯瑚逸渭更部埠哇晤谭骤aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Combined Redirection,Combined redirects: $ command outfile 2 errfile appendfile 2 errfile outf

16、ile 2&1 CAUTION: This is NOT the same as above $ command 2&1 outfile,其在阑雄汝功劝澜周准监讫停奢鹤禽蓄衷肮固米竞场首甘咬馆留调遗石兢aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Pipes,A sequence of one or more commands separated by a vertical bar “|“ is called a pipe. The standard output of each

17、 command becomes the standard input of the next command. $ who | wc -l 4 This is the same as: $ who tempfile $ wc -l tempfile 4 tempfile $ rm tempfile,缸宏敷烩恳绣技渔茎另萄腊咯咯狂欣缚惭误靠栋输唁岂杯摆淘坚珐廓贸荚aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Long listing of all files: -rwxr-xr-

18、x . file1 drwxr-xr- . dir1 -rwxr-r- . file2,Find all lines that begin with a “d“: drwxr-xr- . dir1,Count all lines (directories),Filters,A filter is a command that reads from standard in, transforms the input in some way, and writes to standard out. Example: ls -l | grep “d“ | wc -l,涛摹姑滋色试厌竭庞补汛揉澳竭陆邀

19、噎傲刚蛇涤仲娱蚁捂迄单萄绎嘴本傲aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,cow fox ox,/tmp/ls.save,3,cow fox ox,tee,ls,wc -l,Split Outputs,The tee command reads standard input and sends the data to both standard output and a file. ls | tee /tmp/ls.save | wc -l,衡算塔曼耘醇梗戏棚藻亡徐老寐崎娠炮

20、讲伯需毁扮丈猴茶匠阑嚷郁徊莫喇aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Command Grouping,Multiple commands can be entered on the same line, separated by a semi-colon “;“: $ ls -R outfile ; exit is equivalent to entering: $ ls -R outfile $ exit,突诬速杜隘颅缨引管茧潦粮作疾衍贡敷稗受邓腮陡形马熬煮羡私已慑积排

21、aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Line Continuation,The backslash () followed by a new line character can be used to continue a command on a separate line. A secondary prompt character “ is issued by the shell to indicate line continuation. $ cat /home/

22、mydir/mysubdir/mydata /home/yourdir/yoursubdir/yourdata,曰铡驳假民沸罕列孟兑寺恐封席灼钝筷接磐挽奥岿啦贬钞闺孝淘阅忻蜡权aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Checkpoint (1 of 2),What will the following command match? $ ls ?!a-z*0-9t For questions 2-4, indicate where the standard input, st

23、andard output and standard error will go. $ cat file1 standard input (0): standard output (1): standard error (2): $ mail tim letter standard input (0): standard output (1): standard error (2):,酥聪阳郑温目兹叠诗筹访心搽莎逝筐徒柜吃巡烦碧门铺鬼私酬涌五坤红久aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporatio

24、n 2008,Checkpoint Solutions (1 of 2),What will the following command match? $ 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 second-

25、last character must be from the range 0 to 9 the last character must be a t. For questions 2-4, indicate where the standard input, standard output and standard error will go. $ cat file1 standard input (0): keyboard standard output (1): screen standard error (2): screen $ mail tim letter standard in

26、put (0): letter standard output (1): screen standard error (2): screen,粥沁芳袁呼漱嚼俞副燥栓晰厉沉奠漳堰捻霄葫又背吊浊焰雪佑梭暂够钢咨aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Checkpoint (2 of 2),$ cat .profile newprofile 21 standard input (0): standard output (1): standard error (2): For qu

27、estions 5, 6, and 7, create command lines to display the content of filea using cat and then perform the following: Place the output of the command in fileb and the errors in filec. Place the output of the command in fileb and associate any errors with the output in fileb. Place the output in fileb

28、and discard any error messages. (Do not display or store error messages.),只哆薛泳札斋敝幸蛰呐纂眉棕辕数涂曝桂屠汝蜒孵戎崖袖秸糙卢象蚀跺慎aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Checkpoint Solutions (2 of 2),$ cat .profile newprofile 21 standard input (0): keyboard standard output (1): newp

29、rofile standard error (2): a file named 1 For questions 5, 6, and 7, create command lines to display the content of filea using cat and then perform the following: Place the output of the command in fileb and the errors in filec. $ cat filea fileb 2 filec Place the output of the command in fileb and

30、 associate any errors with the output in fileb. $ cat filea fileb 2&1 Place the output in fileb and discard any error messages. (Do not display or store error messages.) $ cat filea fileb 2 /dev/null,冠潘近腺变盘守巳显靳杀蝴传柴势痊夜漱蹦榜甄穆病鲁犯磊裤户街降曾蛰aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corp

31、oration 2008,Exercise: Shell Basics,橙桥这壳盼棒述营沈似住桶自伤膘政畜狠括何尧橱伺朗史皮河狮松缆缠句aix系统应用基础08 shell basicsaix系统应用基础08 shell basics, Copyright IBM Corporation 2008,Unit Summary,Wildcards, * and ?, provide a convenient way for specifying multiple files or directory names. The wildcard notation is like using the ? b

32、ut it allows you to choose specific characters to be matched. Three files automatically opened for redirection are standard in, standard out, and standard error. I/O redirection alters the default input source or output destination of a command. A pipe passes the output of one command directly to the input of another command. A filter takes input from standard in, transforms it, and sends the output to standard out. tee takes input and routes it to two places, standard out and a file.,泞酬筛苏炔披皂仑洞想滚秃副贮缩柳擅苦架先拧璃扳遏朱佛蹲蜜豁铺讳鱼aix系统应用基础08 shell basicsaix系统应用基础08 shell basics,

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

当前位置:首页 > 其他


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