




已阅读5页,还剩20页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.0 4.1 Unit 8 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 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 Copyright IBM Corporation 2008 The Shell lKorn (ksh) or Bourne (bsh) or C (csh) lUser interface to AIX lCommand interpreter lEnables multiple tasks lComprehensive programming language Copyright IBM Corporation 2008 Metacharacters and Wildcards lMetacharacters are characters that the shell interprets as having a special meaning. Examples: | ; ! * ? $ “ lWildcards are a subset of metacharacters that are used to search for and match file patterns. Examples: * ? ! - Copyright IBM Corporation 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 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 net new nest few File Name Substitution (2 of 2) Copyright IBM Corporation 2008 standard in (0) standard error (2)standard out (1) cmd The Standard Files Copyright IBM Corporation 2008 Standard in:1 Standard error:22 File Descriptors Three descriptors are assigned by the shell when the program starts: Copyright IBM Corporation 2008 Input Redirection lDefault standard input $ mail team01 Subject: Letter This is a letter. Cc: $ lRedirect input from a file: $ ls ls.out $ lRedirecting and appending output to a file: $ who whos.there $ Copyright IBM Corporation 2008 Creating a File with cat lWhile normally used to list the contents of files, 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. $ lUsing redirection: $ cat newfile This is line 1 of the file. This is the 2nd line. And the last. $ ls letter acctfile file1 newfile Copyright IBM Corporation 2008 Activity: Review Shell Basics 1 Which files are listed when the following commands are executed? $ ls /home/team01/*.? $ ls /tmp/a-zA-Z*.0-9 2 True or False: The command “ls *“ lists all files in a directory. 3 Write down the file descriptors for the following command: $ wc -l /tmp/lines Standard input: Standard output: Standard error: 4 You want to append file testfile1 to file report99. Which command is correct? ocat report99 report99 ocat testfile1 report99 ocat testfile1 report99 Copyright IBM Corporation 2008 Error Redirection lDefault standard error: $ cat filea fileb This is output from filea. cat: cannot open fileb lRedirecting error output to a file: 2 (To append: 2) $ cat filea fileb 2 errfile This is output from filea $ cat errfile cat: cannot open fileb $ cat filea fileb 2 /dev/null This is output from filea Copyright IBM Corporation 2008 Combined Redirection lCombined redirects: $ command outfile 2 errfile appendfile 2 errfile outfile 2“: $ ls -R outfile ; exit is equivalent to entering: $ ls -R outfile $ exit 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/mydir/mysubdir/mydata /home/yourdir/yoursubdir/yourdata 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, standard output and standard error will go. $ cat file1 standard input (0): standard output (1): standard error (2): $ mail tim newprofile 21 standard input (0): standard output (1): standard error (2): 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. Place the output of the command in fileb and associate any errors with the output in fileb. Place the output in fileb and discard any error messages. (Do not display or store error messages.) Copyright IBM Corporation 2008 Checkpoint Solutions (2 of 2) $ cat .profile newprofile 21 standard input (0): keyboard standard output (1): newprofile 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 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 Copyright IBM Corporation 2008 Exercise: 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 ? but 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 desti
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高项成本补偿合同模板(3篇)
- 高速公路护坡施工合同(3篇)
- 高速服务区施工合同(3篇)
- 安福县协管员招聘面试题及答案
- 无人机展览现场搭建与无人机飞行表演培训合同
- 产业链上下游企业股权整合及供应链优化合同
- 餐饮店铺转租与经营许可捆绑合同
- 房地产公司挂靠合作项目转让合同范本
- 人教部编版八年级道德与法治-下册-第三单元-人民当家作主-单元练习
- 经贸专业的面试题及答案
- 档案专业人员职业能力竞赛考试题库(含答案)
- 同种异体骨软骨移植与软骨修复
- 故障分析实验报告
- 行为生活方式与健康智慧树知到期末考试答案章节答案2024年杭州师范大学
- JTS-165-6-2008滚装码头设计规范-PDF解密
- 铸造企业安全生产标准化管理体系方案资料汇编(2022-2023新标准实施模板)
- 设备维修与保养(课件)
- 浅谈国内外深基坑支护技术的现状及进展
- 网络舆情应对及处置
- 工业数据采集技术及应用 -配置能源采集仪表参数
- 《应急救援知识》课件
评论
0/150
提交评论