CH02 shell程序的设计.ppt

  1. 1、本文档共73页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
CH02 shell程序的设计

第2章 Shell 程序设计 主要内容 Shell Overview What is Shell? Why Shell? 创建和执行Shell程序 Shell程序设计的语法 变量、条件测试、条件语句、重复语句、命令表和语句块、函数… 实例 基本命令(1) 文件操作 列出目录内容: ls 创建特殊文件: mkdir, mknod, mkfifo 文件操作: cp, mv, rm 修改文件属性: chmod, chown, chgrp 查找文件: find 字符串匹配: grep 其它: pwd, cd, file, more, less, head, tail, cat, gzip,zip,tar 基本命令(2) 进程操作 ps, kill 用户和组账号操作 useradd, userdel, groupdel,passwd 网络命令 ifconfig, ping, netstat,telnet 其他 who, whoami, su, sudo,uname, … man mount unmount du,df 文件权限 文件权限 (续) a file you create 目录权限 a directory you create 目录权限 (续) 目录权限 读 – 可以列出存储在该目录下的文件 写 – 允许从目录中删除或添加新的文件 执行 – 允许在目录中查找,并能用cd命令将工作目录改到该目录: chmod: 改变文件或目录的存取权限 chmod命令 (续) chmod a+r, u+w file1.txt chmod a=r file1.txt chmod u=rwx file1.txt chmod命令 (续) 用8进制数表示 读权限 - 4 写权限 - 2 可执行权限 - 1 chmod命令 (续) 改变多个文件的权限 chmod 755 file1 file2 file3 递归操作 (-R) chmod -R 700 emails chmod -R 700 . umask的作用 思路扩展…… 1. Shell Overview Shell 用户和操作系统之间的接口 作为核外程序而存在 Shell: 作为核外程序而存在 Shell 的双重角色 命令解释程序 Linux的开机启动过程;进程树 Shell的工作步骤 打印提示符;得到命令行;解析命令;查找文件;准备参数;执行命令 独立的程序设计语言解释器(reusable tools) 各种不同的Shell UNIX’s Philosophy (Examples) Redirection Use “echo” to create a file? Pipe Get the count of files in a directory? 重定向输出 系统定义三个标准文件:标准输入(stdin)、标准输出(stdout)、标准错误输出(stderr),对应的文件描述符为0,1,2。 用“>”改变输出,用“2>”改变错误输出,用“>>”来追加到已有的文件中 。 重定向输出示例 $ls –l > lsoutput.txt $ls –l 1 > lsoutput.txt $ps >> lsoutput.txt $kill –HUP 1234 > killout.txt 2>killerr.txt $kill –l 1234 > killout.txt 2>&1 (把标准输出和错误输出都放入同一个文件) $ cat bar 2> /dev/null (you see nothing) 重定向输入 标准输入有3种来源: the keyboard (default), a file, and a pipe wc < newfile the shell opens the file newfile wc newfile the command opens the file newfile wc < newfile > result (wc counts the number of lines, words, and characters in a file) 管道(pipe) 可以用管道操作符|来连接进程。 允许连接的进程数目是没有限制的。 前一个命令的输出是后一个命令的输入。 管道(pipe)(续) ls -l /etc | sort -r | more sort -r sorts the listing in reverse order more displays the contents of a text file on the terminal, one screenful at

您可能关注的文档

文档评论(0)

bokegood + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档