Presentation is loading. Please wait.

Presentation is loading. Please wait.

UNIX 操作系统 鲁强 计算机系: 年3月16日6时11分

Similar presentations


Presentation on theme: "UNIX 操作系统 鲁强 计算机系: 年3月16日6时11分"— Presentation transcript:

1 UNIX 操作系统 鲁强 luqiangtony@gmail.com 计算机系:604 2017年3月16日6时11分
© 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

2 课程安排及要求 32学时(10学时上机,周四, 11,12,13,14,15) 考核 上机安排- 上课形式-讲授和提问 平时成绩(10%)
2017年3月16日6时11分 课程安排及要求 32学时(10学时上机,周四, 11,12,13,14,15) 上机安排- 上课形式-讲授和提问 考核 平时成绩(10%) 课堂回答 随堂作业 实验课:操作,实验报告,上机表现(20%) 考试(70%) © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

3 教材 UNIX 教程 2nd, Sarwar, Koresky,张玉洁等译,机械工业出版社,2006.
UNIX编程艺术, ERIC.S.RAYMAN, 姜宏,电子工业出版社

4 课程目标 熟悉操作系统中的基本概念和原理 掌握UNIX系统的基本命令 掌握UNIX系统的文件系统
2017年3月16日6时11分 课程目标 熟悉操作系统中的基本概念和原理 掌握UNIX系统的基本命令 掌握UNIX系统的文件系统 掌握UNIX系统的基本Shell命令及其编程 掌握UNIX系统的基本网络功能 掌握UNIX系统下常用的开发工具 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

5 UNIX操作系统简介 什么是操作系统 UNIX历史 UNIX系统结构 UNIX特点 2017年3月16日6时11分
© 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

6 什么是操作系统 当今流行的操作系统 操作系统概念 操作系统是一个为用户管理计算机硬件和软件的程序 应用软件与系统软件 操作系统功能
2017年3月16日6时11分 什么是操作系统 当今流行的操作系统 Windows,Linux,Unix,Solaris等 操作系统概念 操作系统是一个为用户管理计算机硬件和软件的程序 应用软件与系统软件 操作系统功能 进程管理 文件管理 存储管理 设备管理 让同学举例 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

7 UNIX操作系统简介 历史 诞生1969-1971 CSTT MULTICS 失败 Space Travel UNIX
2017年3月16日6时11分 UNIX操作系统简介 历史 诞生1969-1971 CSTT MULTICS 失败 Space Travel 1965 CSTT-》Compatible Time-Sharing System 属于MIT,可以连接160个终端,让30个终端同时享有主机资源 MIT联合通用和贝尔实验室开发MULTICS -企图连接 1000 部终端机,支持 300 位使用者同时上线的分时计算机系统 Ken Thompson、Dennis Ritchie Digital Equipment Corporation PDP-7 UNiplexed Information and Computing System,缩写为 UNICS,之后大家取谐音便叫她为 "UNIX“ 1971,PDP-11/20 下使用此系统开发出nroff(1) 字处理程序,使得UNIX走向前台 UNIX © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

8 UNIX Time-Sharing System
2017年3月16日6时11分 成名1971-1980 1974 UNIX Time-Sharing System 1973 UNIX V5 1975 UNIX V6 1979 UNIX V7 V5完全用C语言进行编写 1974 Unix Time-sharing System on the communications of the ACM, V6 be send in university, research lab, with source code…. Bell lab had been forbidden from entering the computer business, so that could be happen V7版本包含 Fortran 77compiler、Shell(只有Bourne Shell)、文件处理工具(nroff/troff、roff、MS mocro等)、UNIX-to-UNIX-file-Copy(用来支持两台 UNIX 机器间的档案传输)、数据处理工具(AWK、SED 等强悍的工具)、除错工具(ADB)、程序发展工具(MAKE)、Lexical analyzer generator(LEX、YACC 等)、简单的绘图工具、并支持 C 语言及 LINT verifier. The first Unix company (the Santa Cruz Operation, SCO) began operations in 1978, and the first commercial C compiler (Whitesmiths) sold that same year. 1977 Berkley 1st BSD © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

9 Richard M. Stallman发表GNU宣言
2017年3月16日6时11分 发展与战争(1980-今) 1985 POSIX Richard M. Stallman发表GNU宣言 1983 BSD 4.2 1984 肢解AT&T SVR2 1991 Linux0.1 1994 Linux1.0 1982 Bill Joy加入Sun,SunOS.10 1992 BSD Net2 版权战争开始 BSD4.2 足以应付 CAD/CAM 影像处理与 AI 研究的高速的档案系统及扩展强化的虚拟内存功能;提供能分散处理的解译沟通机制;支持56-Kbit 的 ARPA Internet 网络连结(TCP/IP),以及 10-Mbit/s Ethernet 的局域网络;还有经过重组架构已模块化的kernel code ,提供更有效率的计算机平台移植。 Bill Joy 完成BSD1.0,VI等工具是BSD和UNIX发展的主要贡献者,后加入SUN Richard M.Stallman从MIT的人工智能实验室辞职,1985开发出emacs 1990 年 11 月,发表 SunOS 版同时冠上 Solaris 1.0 时,SUN 才算开始向 System V 版本靠拢。SunOS 可算是以 BSD 为主体再附加System V 工具的 UNIX 混血儿。 1985 POSIX(Portable Operating System Interface for computer Environments)by the IEEE 1992 BSD NET2版本正式发布,完全使用重新编写的UNIX内核,进行带源代码的销售,从此引起AT&T之间的法律诉讼,到1994年庭外和解。 UNIX 源代码的数度易手: 1993 AT&T 将UNIX源码及版权卖给NOVELL 掌握 UNIX source code 以及 UNIX 商标的 Novell,将 UNIX 商标交给X/open 管理,自己则发展了一套命名为 UNIXWave 的操作系统。推出后市场的反应并不热络。不久,Novell 与 SCO 接头,在 SCO 保证继续支持UNIXWare 的条件下,UNIX 在 1995 年二次易主,新主人是 SCO。 2001 年 5 月 4 日,Caldera International, Inc. 正式并购了 SCO 的服务器软件部及SCO专业服务部这两个部门,新的控股公司名为 Caldera, Inc 1996年Linux2.0发布,Torvalds 本人指定一只“企鹅”作为 Linux 的标志。同时也开始支持对称式多重处理器 (Symmetric Multi-Processing,简称 SMP)架构的计算机。 1987 SUN与AT&T组成战略联盟,遭到IBM、HP等公司反对 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

10 2017年3月16日6时11分 伟大的人物 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

11 各种操作系统

12 不同版本 SGI SCO irix6.5 Open sever 2017年3月16日6时11分
© 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

13 特点 开放、开源 高可移植性 良好的用户界面 树型分级的文件目录 字符流式文件 丰富的核外系统程序 秉承“小而完美”的设计理念 管道文件连通
2017年3月16日6时11分 特点 开放、开源 高可移植性 良好的用户界面 树型分级的文件目录 字符流式文件 丰富的核外系统程序 秉承“小而完美”的设计理念 管道文件连通 简单而统一的I/O设备接口 提供电子邮件和对网络通讯的有利支持 系统安全 在开放、开源的发展过程中许多大学科研单位和黑客为它的发展作出贡献 UNIX 另一个很突出的特点就是它简单而统一的I/O 设备接口。UNIX 将所有的设备都用文件表示,用户可以使用与处理文件相同的命令和系统调用集访问设备。开发者写程序完成I/O操作时不必考虑这个操作是对文件的,还是对用户终端,打印机,或其他设备进行的。这一特性与shell 中的I/O 重定向一起提供了一个简单而强大的I/O 接口。 作业管理包括任务管理、界面管理、人机交互、图形界面、语音控制和虚拟现实等。  计算机系统的软硬件资源是由前述四种管理功能负责,建立起操作系统与计算机系统的联系。那么,用户怎样通过操作系统来使用计算机系统,以便完成自己的任务呢?也就是用户程序和数据如何提交系统,系统又如何执行用户的计划?为此,操作系统还必须提供自身与用户间的接口,这部分工作就由作业管理来承担。 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

14 UNIX系统结构 用户 实用程序 SHELL 内核 硬件 2017年3月16日6时11分
© 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

15 UNIX哲学 模块原则:使用简洁的接口拼合简单的部件 清晰原则:清晰胜于机巧 组合原则:设计时考虑拼接组合
分离原则:策略同机制分离,接口同引擎分离 简洁原则:设计要简洁,复杂度能低就低 吝啬原则:除非确无它法,不要编写庞大的程序 透明原则:设计要可见,以便审查和调试 健壮原则:健壮源于透明与简洁 表示原则:把知识叠入数据以求逻辑质朴和健壮

16 K.I.S.S Keep It Simple, Stupid 通俗原则:设计接口避免标新立异 缄默原则:如果一个程序没有什么好说的,就沉默
补救原则:出现异常时,马上退出并给出足够的错误信息 经济原则:宁花机器一分钱,不花程序员一秒钟 生成原则:避免手工hack,尽量编写程序去生成程序 K.I.S.S Keep It Simple, Stupid

17 你所知道的操作系统有哪些,它们有什么特点,适用环境是什么?

18 第二章 UNIX常用命令 准备 UNIX登陆和注销 简单常用命令 文件操作命令 目录操作命令 有关磁盘的使用命令 进程命令
2017年3月16日6时11分 第二章 UNIX常用命令 准备 UNIX登陆和注销 简单常用命令 文件操作命令 目录操作命令 有关磁盘的使用命令 进程命令 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

19 工具准备 Linux、Open Solaris、SCO UNIX Cygwin、Virtual PC、VMware

20

21

22

23 命令准备 提示符和系统版本 键盘和终端 UNIX命令格式 UNIX版本BSD、SVR、Solaris…
2017年3月16日6时11分 提示符和系统版本 UNIX版本BSD、SVR、Solaris… Shell版本:Bourne Shell、C-Shell、Kron Shell $ ls > Bourne Shell、Kron Shell、Bourne Again Shell % ls > C-Shell 登陆时显示的Shell有管理员来决定 键盘和终端 VT-100 UNIX命令格式 命令名称 [选项 ] [选项参数] [命令参数] ls -l /usr/mens lpr –n 3 proposal.ps UNIX命令行的一般格式是: 命令名称 [选项][选项] [参数] 其中,命令名是命令的名称,它总是出现在命令行的开头位置。 选择项是一种标志,常用来扩展命令的特性或功能。[选择项]中的方框号表示语法上选择项可有可无。选择项往往是一个个英文字母,在字母前面有一个连字符"-",例如:ls -l。 有时也可以把几种表示不同含义的选项字母组合在一起对命令发生作用,例如:ls—ls。 参数表示命令的自变量,如文件名、参数值等。参数也是可有可无,可多可少,依据具体命令的要求而定,例如:ls -l /usr/mens 在命令行中,命令名、选择项和参数被此之间都需要用空格(通常是这样)或制表符隔开,否则可能出现错误。 选项和选项参数之间的空格可以忽略 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

24 UNIX登陆和注销 登陆 输入系统名、用户名和密码 登陆成功,选择终端 Request: garnet Login: chris
2017年3月16日6时11分 UNIX登陆和注销 登陆 输入系统名、用户名和密码 Request: garnet Login: chris Password: 登陆成功,选择终端 如果在输入登录名中敲错的话,可以用backspace或Ctrl-h键删除字符。然而,一些老系统在这个时候不允许修改。如果是这种情况,则必须重启登录进程。Backspace键看起来管用,但实际上它只是在登录名中加了一些backspace字符。 在成功地输入了密码以后,系统会提示输入终端名。终端名提示符是:TERM:。通常会在提示符后面的括号中显示缺省的终端名,如TERM =(tvi925)。直接按回车则选用这个缺省终端,将出现shell提示符 Request: garnet Login: chris Password: Term=(tvi925) w50 $ Request: garnet Login: chris Password: $Term=w50 $export Term Request: garnet Login: chris Password: % setenv Term w50 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

25 UNIX登陆和注销 更改密码 passwd还有什么功能? $ passwd Old password: New password:
2017年3月16日6时11分 UNIX登陆和注销 更改密码 $ passwd Old password: New password: Retype new password: Passwd [选项] 帐号名称 Passwd –l :锁定账户 Passwd –u :解除锁定 Passwd -x :最大密码使用天数 Passwd -n :最小密码使用天数 Passwd –d :删除使用者密码 passwd还有什么功能? © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

26 UNIX登陆和注销 注销 结束此次登陆会话,不同的shell有不同的命令 $ exit Bourne和Korn shell注销命令
2017年3月16日6时11分 UNIX登陆和注销 注销 结束此次登陆会话,不同的shell有不同的命令 $ exit Bourne和Korn shell注销命令 % logout C-shell注销命令 $ ^D Ctrl-d可以从Bourne shell、Korn shell和C-shell中注销。 Request: garnet Login: chris Password: Term=(tvi925) w50 $ exit bye Request: garnet Login: chris Password: Term=(tvi925) w50 % logout bye © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

27 UNIX登陆和注销 关机 haltsys reboot shutdown shutdown –g[hh:]mm –f “mesg”
2017年3月16日6时11分 UNIX登陆和注销 关机 haltsys reboot shutdown shutdown –g[hh:]mm –f “mesg” shutdown –g4 –f “mesg” 1、 用haltsys命令关机 haltsys命令一发出,就会立即把系统关闭掉。其优点是系统响应快,强迫性强,因此,该命令只适合于系统上只有一个用户的情况。如果系统上有多个用户在工作,一发出命令,这些用户就被迫退出系统,他们的进程也丢失了。操作方法是:以超级用户登录,输入haltsys,回车,系统显示关机信息时,关掉电源。 2、 用reboot命令关机 reboot命令是由系统管理员执行的停机程序,reboot实质上是和haltsys命令链接在一起的。reboot和haltsys的唯一区别是它在正常停机后不用按任意键,马上自动引导,重新启动系统。reboot特别适合系统管理员调试机器用。 3、 用shutdown命令关机 shutdown命令是一个用shell语言编写的程序,驻留在/etc目录中。它由超级用户在前台运行,自动执行wall命令,通知正在系统中工作的所有用户,系统将在指定的时间内停机,请做好准备工作,然后从系统中注销。当所有用户已从系统中注销或指定时间已到时,shutdown就执行kill命令把系统中除主控台外的所有进程都终止,接着执行haltsys命令使系统正常停机。使用格式:shutdown -g[hh:]mm -f"Mesg",其中[hh:]mm是系统指定关机时间,“Mesg"是系统向各终端用户发送的信息。在网络用户中推荐使用shutdown命令来关机。 4、 用bye命令关机 bye命令是以shutdown为核心,用vi编辑生成的关机命令,主要优点是简单易记。bye文件内容为:shutdown -y -g0(参数可根据实际需要设置),编辑后的bye权限为-rw-r-r-,此时bye不能直接使用,将其权限放开,# chmod u+x bye,bye才可行使shutdown职能。 5、 创建关机用户bye 用超级用户来关机,不利于系统的管理,存在一定的安全隐患,因此有必要建立自动关机用户。下面以sysadmsh命令来创建关机用户bye。 (1)创建bye用户。用超级用户登录到UNIX,键入sysadmsh,选择Account->User->Create,在Username中输入:bye,其他缺省。 (2) 在Account->User->Examine中,输入bye后选择Privilege->Subsystem->Specify输入shutdown,保存修改信息并退出sysadmsh。 (3) 用bye注册到UNIX,编辑当前目录下的.profile文件。该文件内容为: trap exit 2,3 /tcb/bin/asroot shutdown -y -g0 (4)在Login:状态下,只要键入bye就会自动关闭UNIX操作系统。 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

28 UNIX常用命令 date命令 该命令用于显示系统日期 ?如果更改系统日期和时间 $ date
2017年3月16日6时11分 UNIX常用命令 date命令 该命令用于显示系统日期 $ date Sun July 5 10:30:21 PST 2006 Date –s “yyyy-mm-dd hh:mm:ss” Date –s 04/22/2009 Date –s 10:16:00 Date MMDDHHMM ?如果更改系统日期和时间 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

29 UNIX常用命令 who命令 该命令用于显示当前登陆的所有用户列表。 who [-H][-q][-u][-s] -H 在每一列显示一个表头。
2017年3月16日6时11分 UNIX常用命令 who命令 该命令用于显示当前登陆的所有用户列表。 who [-H][-q][-u][-s] -H 在每一列显示一个表头。 -q 输出当前登录的用户个数。 -u 列出每个用户的更加详细的信息。写信息包括空闲时间、用户进程i d以及其他一些信息。空闲时间指的是自从该账号上一次动作以来有多长的时间,一个点代表空闲时间少于一分钟。进程id是在系统中使用的特殊的标识数字。 -s 等同与who的缺省命令 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

30 终端名 登陆时间 $ who 登陆名 $ who –q 3 $ who -H NAME LINE TIME $ who –Hu
2017年3月16日6时11分 终端名 登陆时间 $ who larisa tty July 5 8:30 aleina tty10 July :30 chris tty32 July :30 登陆名 $ who –q 3 $ who -H NAME LINE TIME larisa tty July 5 8:30 aleina tty10 July :30 chris tty32 July :30 $ who –Hu NAME LINE TIME IDLE PID larisa tty July 5 8: aleina tty10 July : chris tty32 July : $ who -u larisa tty July 5 8: aleina tty10 July : chris tty32 July : © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

31 UNIX常用命令 finger命令 显示本机或远程主机中的用户信息 $ finger
2017年3月16日6时11分 UNIX常用命令 finger命令 显示本机或远程主机中的用户信息 $ finger Login Name TTY Idle When Office larisa Larisa Petersen Mon 8: Lab aleina Aleina Skate Tues11:30 Hall chris Charis Neal Mon 14:30 PRO2 $ finger chris Login name: chris In Real Life: Chris Neal Directory: /home/chris Shell: /bin/sh Last Login: Mon July 5 14:30 on tty14 $ finger $ finger © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

32 pwd命令 echo命令 ls命令 列出/usr/mengqc目录下的文件 $echo How are you! How are you!
2017年3月16日6时11分 pwd命令 $ pwd /usr/mengqc echo命令 $echo How are you! How are you! ls命令 列出/usr/mengqc目录下的文件 $ls a.out C++1.C C++2.C m1.c m2.c © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

33 man命令 章节号 内容 man [-s section] command-list man –K keyword-list
man –s3 fopen,fread man –K read 章节号 内容 1 用户命令 2 系统调用 3 语言的函数调用 4 设备和网络接口 5 文件格式 6 游戏和演示 7 系统环境 8 系统维护相关命令

34 man命令 $ man who WHO(1) UNIX Programmer’s Manual WHO(1)
2017年3月16日6时11分 man命令 $ man who WHO(1) UNIX Programmer’s Manual WHO(1) NAME WHO –who is on the system SYNOPSIS WHO [qHu][amiI] DESCRIPTION Who, without any argument Lists the Login name, terminal name, and Login time for each user currently. Logged into the system. OPTIONS -q Displays only the number of user logger in -H Display headers for each column in usr List -u Display complete information about users FILES /etc/utmp SEE ALSO getuid(2), utmp(5) 其中五个公共的部分是:大纲、描述、选项、文件及该 命令的交叉引用。大纲部分是介绍该命令的语法,并列出可能的选项和参数。对该命令的描述 部分则准确地描述其在系统中是如何工作的,选项部分会列出该命令的不同选项,文件部分则 列出该命令所用到的系统文件。在交叉引用部分提供其他的相关命令及帮助条目,下面是w h o命 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

35 help命令 $ help help: UNIX System On-Line Help choices description
2017年3月16日6时11分 help命令 $ help help: UNIX System On-Line Help choices description s starter: general information l locate: Find a command with keywords u usage: information about commands g glossary: definitions of terms r Redirect to a file or a command q quit Enter choice > q © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

36 cal命令 uname命令 显示所用操作系统名称 -m 显示机器硬件名称 -r 显示操作系统发行版本 -s 显示操作系统名称
-v 显示操作系统版本 -X 显示以下信号:系统名称、节点名称、操作系统发行号、核心ID号、处理器类型、总线类型、序列号…

37 logname命令 env命令 $logname mengqc $env EDITOR=/usr/ucb/vi
HOME = /usr/meng HZ = 100 LOGNAME= mengqc PATH=/bin:/ect:/usr/bin:/tcb/bin SHELL = /bin/sh TERM = ansi TZ = CST – 8

38 文件操作命令 文件及其分类 显示文件命令 正则表达式 匹配、排序及显示指定内容 文件内容比较命令 文件的复制、删除和移动
2017年3月16日6时11分 文件操作命令 文件及其分类 显示文件命令 正则表达式 匹配、排序及显示指定内容 文件内容比较命令 文件的复制、删除和移动 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

39 文件及其分类 文件:是unix用来存储信息的基本结构。 文件名往往带有后缀(或扩展名) 。例如 a.c, b.h, s.o UNIX文件类型
普通文件:普通文件的类型标志是“-“。 特殊的”.”文件,完成配置目的,例如.profile 目录文件:目录的类型标志是“d”。 特别文件:或称为设备文件,分为块特别文件(如磁盘、磁带、CD-ROM等)和字符特别文件(如终端、打印机等) ,其类型标志分别是“b”和“c”。 连接文件:“l” 命名管道:“p” 套接字: “s” 文件存取控制 UNIX上的三种用户:文件所有者(user)、同组用户(group)和其它用户(other)。 9位二进制,表示三组用户对此文件读(r)、写(w)和执行(x)的权限。 例如:rwxrw---- 2017年3月16日6时11分 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

40 文件显示命令 file命令 用来测试文件类型 $file test.c test.c: ASCII C Programe Text
$file /bin /bin: directory

41 文件显示命令 cat命令 用来连接并显示文件。 cat [options] [file-list]
2017年3月16日6时11分 文件显示命令 cat命令 用来连接并显示文件。 cat [options] [file-list] -n 在显示的行上加上行号 -v 显示非打印字符(制表符、换行和换页除外) -t 制表符显示为^t,换页符显示为^L . 如果没有使用-v选项,则这个选项链忽略。 -e 在每行的结尾(换行符之前)显示一个"$"字符。如果没有使用-v选项,则这个选项被忽略。 $ cat m1.c $ cat m1.c m2.c > m3.c $ cat m3.c © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

42 more命令 逐屏浏览一屏文件 more [options] [file-list] +/str 在第一个包含str行之前的两行开始显示
2017年3月16日6时11分 more命令 逐屏浏览一屏文件 more [options] [file-list] +/str 在第一个包含str行之前的两行开始显示 -nN 每页/屏显示N行 +N 从第N行开始显示文件内容 Abc Aaaa --More--(10%) 要向前移动文本,敲‘b’键;敲‘q’键退出。 $ls –l | more $more +/Bit /usr/include/sys/param.h © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

43 2017年3月16日6时11分 © 2004 Microsoft Corporation. All rights reserved.
This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

44 head命令 tail命令 显示文件的前面几行。 head [options] [file-list] -N 显示最开始的N行
2017年3月16日6时11分 head命令 显示文件的前面几行。 head [options] [file-list] -N 显示最开始的N行 例如:$head -5 f1 tail命令 显示文件的尾部内容。 tail [options] [file-list] -f 在显示文件的最后一行后继续增加文件的内容,并将文件的新增内容显示出来 +n 显示从文件开始第n行到文件尾部的内容 -n 显示文件倒数n行的内容 -r 以相反的顺序(最后一行在最前)显示 例如:$tail -5 /usr/include/sys/param.h $ tail -5r /usr/include/sys/param.h © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

45 根据选项将文件按页格式化,并在标准输出上显示。 pr[options] [file-list]
2017年3月16日6时11分 pr命令 根据选项将文件按页格式化,并在标准输出上显示。 pr[options] [file-list] + ‘page’ 从格式化后的输入中的页码“page”处开始输出 - ‘column’ 产生”column”栏的多栏输出 -a 修改-”column”项的效果,这样各栏以循环 次序填满页面 -d 产生两倍行距的输出 -f 分页时使用换页符 -h ‘header’ 在页头部使用字符串“header”代替“file”的内容 -l ‘lines’ 重设每页的行数 -m 合并文件,pr命令写到标准输出中的格式为每行都有每个“file”所指定的文件的内容。 -n[char][width]提供”width”位数的行号,如果给出了”char”(非数字字符),它将被添加在行号后,将其与其后的内容分开。 -o ‘offset’ 输出的每行开始都要偏移“offset”个空格 例如: $pr -2dh “file list” f1 f2 $ © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

46 正则表达式 名称 操作符 示例 含义 支持工具 或 | X|Y|Z X、Y或Z awk,egrep 任意字符 . .com
Acom, Bcom 所有 行首 ^ ^x 以x开始的一行 连接 xyz 行尾 $ x$ 以x结尾的一行 转义序列 \ \* * ed,sed,vi 定界符 / /L..e/ Love ,Live, Lose ed, sed, vi 分组 ()或\(\) (xy)+ xy, xyxy, xyxyxy 选项 xy? x, xy awk, egrep 重复(0或多) xy* x,xy,xyy,xyyy 重复(1或多) + xy+ xy,xyy,xyyy 集合 [ ] /[Hh]ello/ Hello, hello 匹配不在括号中的任意字符 [^] /[^A-KM-Z]ove/ Love

47 匹配、排序及显示指定内容 grep命令 在输入文件中查找匹配模式的行 grep [options] pattern [file-list]
2017年3月16日6时11分 匹配、排序及显示指定内容 grep命令 在输入文件中查找匹配模式的行 grep [options] pattern [file-list] egrep [options] pattern [file-list] fgrep [options] [expression] [file-list] -c 仅打印匹配行的数量 -i 在匹配过程中忽略大小写 -l 仅打印匹配行所在的文件名 -n 随匹配行打印出行号 -v 打印出非匹配行 -w 将给定模式作为一个字符串进行搜索 Egrep 命令检索扩展的正则表达式(包括表达式组和可选项) Fgrep命令检索固定字符串,它不识别正则表达式。 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

48 表达式 出现$ * [ ^ | ( 和 \ 等shell中特殊字符,应把整个表达式或字符串参数用单引号括起来 正则表达式
2017年3月16日6时11分 表达式 出现$ * [ ^ | ( 和 \ 等shell中特殊字符,应把整个表达式或字符串参数用单引号括起来 例如:$grep '[Ss]ample' ff 正则表达式 + 、 ? 、| 、()。 例如: grep -E '([Ss]ome|[Aa]ny)one' ff 正则表达式中各运算符的优先级从高到低依次为:[],* ? + ,串链,带换行的反斜线(\)或者竖线(|) 。 ?下面命令完成什么功能? grep [A-H] students grep [A,H] students ? 给出一条命令,显示在目录~/course/ece446下包含单词“UNIX”的所有文件的名字 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

49 John Johnse john.johnsen@tp.com 503.555.1111
2017年3月16日6时11分 $cat students John Johnse Hassaan Sarwar David Kendall John Johnshn Kelly Kimberly Maham Sarwar Jamie Davidson Nabeel Sarwar $grep –n sarwar students 2:Hassaan Sarwar 6:Maham Sarwar 8:Nabeel Sarwar $grep ‘^[A-H]’ students $grep ‘[a-z]\{8\}’ students $grep ‘^Ke’ students $egrep –v ‘Kimberly|Nabeel’ students grep ‘[a-z]\{8\}’ students 显示至少连续8个小写字母的行 grep ‘\<Ke’ students 显示以Ke开头的字所在的行 ?字结尾用什么表示 \> ‘net\>’表示 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

50 2017年3月16日6时11分 sort命令 对文件进行排序与合并。 排序比较是依据从输入文件的每一行中提取的一个或多个排序关键字进行的排序。关键字定义了用来排序的最小的字符序列。 sort [options] [file-list] -b 忽略字段前的空格 -d 根据常用的字母顺序排序:忽略除字母、数字和空格之外的所有字符 -f 小写字母和大写字母等价 +n1[-n2] 从+n1开始到-n2结束,指定某个字段作为排序关键字,字段号从0开始 -r 按相反的顺序进行排序 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

51 John Johnse john.johnsen@tp.com 503.555.1111
$cat students John Johnse Hassaan Sarwar David Kendall John Johnshn Kelly Kimberly Maham Sarwar Jamie Davidson Nabeel Sarwar $sort students John Johnse

52 $ sort +3 –r –b students Maham Sarwar msarwar@k12.st.or 713.888.0000
Kelly Kimberly Jamie Davidson John Johnse Hassaan Sarwar Nabeel Sarwar John Johnshn David Kendall

53 uniq命令 uniq [options] [input-file] [output-file]
2017年3月16日6时11分 uniq命令 uniq [options] [input-file] [output-file] 删除排序文件input-file中重复出现的行,并将唯一行(不重复的行)送到output-file中。 -c 在每个输出行之前加上它出现的次数 -d 显示重复的行 -u 显示不重复的行 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

54 This is a test file for the uniq command
2017年3月16日6时11分 $cat sample This is a test file for the uniq command It contains some repeated and some nonrepeated lines Some of the repeated lines are consecutive,like this. Some of the repeated lines are consecutive,like this. And , Some are not consecuteive, like the following Some of the repeated lines are consecutive,like this. $ uniq example © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

55 文件比较命令 comm命令 对两个已经排序的文件进行比较。 comm [-123] file1 file2
2017年3月16日6时11分 文件比较命令 comm命令 对两个已经排序的文件进行比较。 comm [-123] file1 file2 其中file1和file2是已排序的文件。comm读取这两个文件然后生成三列输出:仅在file1中出现的行;仅在file2出现的行;在两个文件中都有的行。文件名“-”表示标准输入。 标志1,2,或3抑制相应的列显示。这样comm -12就只显示两个文件共有的行;comm -23只显示在第一个文件中出现而末在第二个文件中的行;comm-123就什么也不做。 例如,comm -12 f1 f2 就只显示文件f1和f2中共有的行。 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

56 $ comm Fall_ON Spring_ON $cat Spring_ON Office Hours for Spring 2004
$ cat Fall_ON Office Hours for Fall 2003 ooooo Monday 9: :00 A.M. 3:00 - 4:00 P.M. Tuesday 10: :00 A.M. Wednesday Thursday 11:00 A.M. -12:00 P.M. 2:00 - 3:00 P.M. 4:00 - 4:30 P.M. $ comm Fall_ON Spring_ON Office Hours for Fall 2003 Office Hours for Spring 2004 ooooo Monday 9: :00 A.M. 3:00 - 4:00 P.M. Tuesday 10: :00 A.M. 1:00 - 2:00 P.M. Wednesday Thursday 11:00 A.M. -12:00 P.M. 2:00 - 3:00 P.M. 4:00 - 4:30 P.M. $cat Spring_ON Office Hours for Spring 2004 oooooo Monday 9: :00 A.M. 3:00 - 4:00 P.M. Tuesday 10: :00 A.M. 1:00 - 2:00 P.M. Wednesday Thursday 11:00 A.M. -12:00 P.M.

57 diff命令 为逐行比较两个文本文件,用一系列命令显示它们的区 别,这些命令可用于将file1转换成file2。
2017年3月16日6时11分 diff命令 为逐行比较两个文本文件,用一系列命令显示它们的区 别,这些命令可用于将file1转换成file2。 diff [options] [file1] [file2] -b 忽略行尾的多余空格(或值表符),将它们与空白符的字符串都视为等价 -e 为ed编辑器产生和显示脚本,ed编辑器用来将文件file1转换为file2 -h 快速比较(此时不能用-e) © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

58 L1aL2, L3 >lines L2 through L3 将文件file2中的L2到L3的行追加到文件file1中L1行之后 L1,L2cL3,L4 < lines L1 through L2 in file1 --- >lines L3 through L4 in file2 将文件file1中从L1到L2的行转换成文件file2中从L3到L4的行 L1,L2dL3 从文件file1中删除从L1到L2的所有行

59 Office Hours for Spring 2004 Monday 9:00 - 10:00 A.M. 3:00 - 4:00 P.M.
2017年3月16日6时11分 $ cat Fall_ON Office Hours for Fall 2003 Monday 9: :00 A.M. 3:00 - 4:00 P.M. Tuesday 10: :00 A.M. Wednesday Thursday 11:00 A.M. -12:00 P.M. 2:00 - 3:00 P.M. 4:00 - 4:30 P.M. $cat Spring_ON Office Hours for Spring 2004 Monday 9: :00 A.M. 3:00 - 4:00 P.M. Tuesday 10: :00 A.M. 1:00 - 2:00 P.M. Wednesday Thursday 11:00 A.M. -12:00 P.M. $ diff Fall_ON Spring_ON 1c1 < Office Hours for Fall 2003 --- > Office Hours for Spring 2004 7a8 > 1:00 - 2:00 P.M. 10d10 < 3:00 - 4:00 P.M. 13,14d12 < 2:00 - 3:00 P.M. < 4:00 - 4:30 P.M. ?查阅ed命令的使用方式,说明怎样通过ed与diff的结合使用来使得file1中的内容与file2中的内容相同 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

60 cmp命令 cmp 文件名1 文件名2 cmp可比较两个文件,并定位它们的第一个不同之处 $cmp example1 example
2017年3月16日6时11分 cmp命令 cmp可比较两个文件,并定位它们的第一个不同之处 cmp 文件名1 文件名2 $cmp example1 example example1 example differ: char 16, line 2 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

61 文件的复制、移动和删除 cp命令 cp [options] file1 file2
2017年3月16日6时11分 cp命令 cp [options] file1 file2 将文件file1复制到file2.如果file2是一个目录,则在该 目录下创建file1副本 -f 如果对目标文件没有写权限,强制拷贝 -I 如果目标文件已存在,在覆盖之前提示用户 -p 保留文件属性(所有者ID、组ID、权限,以及修 改时间) -r 递归地复制文件和子目录 $cp –f /usr/mengqc/* /usr/liu $cp -r /usr/mengqc /usr/liu © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

62 mv命令 mv [options] file1 file2 mv [options] file-list directory
2017年3月16日6时11分 mv命令 mv [options] file1 file2 mv [options] file-list directory 为文件或目录改名或将文件由一个目录移入另一 个目录中 -f 忽略目的文件的权限,强行移动 -i 在覆盖目的文件之前提示用户 $ mv /usr/xu/ * . $ mv wch.txt wjz.doc © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

63 rm命令 rm [options] file-list 从文件结构(和磁盘)中删除file-list中的文件
2017年3月16日6时11分 rm命令 rm [options] file-list 从文件结构(和磁盘)中删除file-list中的文件 -f 强行删除file-list中的文件,忽略对file-list中文件的访问权限。 -i 在删除文件之前提示用户 -r 如果命令参数是一个目录,则递归地删除该目录下的文件(包括子目录)。 $ rm - i test example Remove test ?n Remove example ?y © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

64 目录操作命令 UNIX目录 目录的创建与删除 目录的显示、复制和改变 有关口令、权限的命令 文件查找命令 统计文件命令
2017年3月16日6时11分 目录操作命令 UNIX目录 目录的创建与删除 目录的显示、复制和改变 有关口令、权限的命令 文件查找命令 统计文件命令 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

65 UNIX目录 根目录 主目录 当前工作目录 绝对路径 相对路径 /root/home/larisa/stories/rumors
2017年3月16日6时11分 UNIX目录 根目录 主目录 当前工作目录 绝对路径 /root/home/larisa/stories/rumors 相对路径 stories/rumors © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

66 2017年3月16日6时11分 系统目录 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

67 目录的创建与删除 mkdir命令 创建一个目录 mkdir [options] dirname -m 创建一个目录并使它具有指定的访问权限
2017年3月16日6时11分 目录的创建与删除 mkdir命令 创建一个目录 mkdir [options] dirname -m 创建一个目录并使它具有指定的访问权限 -p 创建父目录,该父目录并不存在于dirname 所指定的路径中 $ mkdir - p - m 700 ./inin/mail/ © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

68 rmdir命令 删除目录 rmdir [options] dirname -p 同时删除父目录 此命令执行时需要此目录为空目录
$ rmdir - p /usr/xu/txt

69 目录的显示、复制和改变工作目录 ls命令 列出目录中的内容 ls [options] [dirname|filename]
2017年3月16日6时11分 目录的显示、复制和改变工作目录 ls命令 列出目录中的内容 ls [options] [dirname|filename] -a 列出所有条目,包括以点(.)开头的文件 -A 列出所有条目,包括以点(.)开头的文件,除了当前工作目录(.)和上一级目录(..) -c 使用索引节点的最后修改时间 -d 如果目录是参数,仅列出其名称 -F -i 对每个文件,在报告的第一栏显示索引节点号 -l 以长格式列出每个文件给定的模式 -L 如果参数是一个符号链接,列出链接指向的文件和目录,而不是链接本身 -n 同-l选项,但显示属主的UID和组的GID,而不是与其关联的字符串 -R 递归地列出遇到的所有子目录 -s 列出每个条目所占的块数 -t 以时间戳排序 -u 使用最后访问时间代替最后修改时间进行排序 • 文件类型(第一个字母)。 • 文件的访问权限(后9个字母)。 • 到文件的连接数目。 • 文件所有者的名称(一般为创建该文件的用户)。 • 可以访问该文件的组的名称。 • 以字符个数计算的文件大小(字节)。 • 文件所创建或上一次所修改的时间和日期。 • 文件名。 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

70 文件的连接数量 文件类型: 普通文件;d 目录;l符号链接;b 块设备文件;c 字符设备文件;s 信号量;m 共享数据(内存)文件;l链接;p命名管道。

71 ./ ../ .bash_profile* example text
2017年3月16日6时11分 $ ls – aF ./ ../ .bash_profile* example text © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

72 cd命令 改变工作目录。 cd [directory]
2017年3月16日6时11分 cd命令 改变工作目录。 cd [directory] 例如:假设用户当前目录是:/home/xu,现需要更换到/home/xu/pro目录中,   $ cd pro 此时,用户可以执行pwd命令来显示工作目录。 $ pwd /home/xu/pro © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

73 有关口令和权限的命令 passwd命令 普通用户利用这个命令可以: 另外,系统管理员可以利用这个命令: ·更改或则除他们自己的注册口令;
2017年3月16日6时11分 有关口令和权限的命令 passwd命令 普通用户利用这个命令可以: ·更改或则除他们自己的注册口令; ·列出对他们帐户起作用的某些属性。 另外,系统管理员可以利用这个命令: ·更改或则除任何用户的注册口令; ·更改或删除modern(拨号shell)口令; ·封钡或解封任何用户帐户; ·使拨号shell口令无效(封锁); ·列出全部用户或任何单个用户的某些同性; ·改变任何用户的某些属性。 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

74 例如:passwd –l qlu passwd [options] [name] -d 删除口令。仅当用户没有口令时才能删除口令
2017年3月16日6时11分 passwd [options] [name] -d 删除口令。仅当用户没有口令时才能删除口令 -f 迫使用户在下次注册时改变他们的口令 -l 管理员把用户锁定 -u 取消对用户的锁定 -n mininum 设置两次口令改变之间的期限 -x expiration 设置口令到期时限(天数) -r retries 用户为选择新口令可至多试retries次 -s 报告用户口令属性。格式:名称、状态、mm/dd/yy、最小时限。状态:PS用户有口令;LK用户被锁定,mm/dd/yy表示口令最后修改的日期 例如:passwd –l qlu © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

75 - 表示shell的运行环境为name实际注册 时所建立的环境 name 表示用户名 args: -c string 由su命令建立起来的
变更为其它使用者的身份 su [-][name[args]] - 表示shell的运行环境为name实际注册 时所建立的环境 name 表示用户名 args: -c string 由su命令建立起来的 shell执行string所表示的命令 -r 由su建立起来的shell是一个受限 的shell 例如:变更账号为超级用户,并在执行df命令后还原使用者。 $su root -c df 2017年3月16日6时11分 受限的shell—在受限模式下,用户不能改变自己的目录,不能修改PATH变量,不能使用绝对路径名执行命令,不能重定向等 sudo?在ubuntu系统下是什么含义? © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

76 chmod命令 用于改变文件或目录的访问权限。 chmod [options] symbolic-mode file-list
2017年3月16日6时11分 chmod命令 用于改变文件或目录的访问权限。 chmod [options] symbolic-mode file-list chmod [options] octal-mod filelist -R 递归地为目录中的文件和子目录修改或设置访问权限 -f 强制指定文件访问权限 文字设定法 chmod [who] [+ | - | =] [mode] 文件名 操作对象who可是下述字母中的任一个或者它们的组合:u、 g、 o 、a 。其中u表示用户,g表示组用户,a表示所有用户,o表示其他用户。 操作符号可以是: + 、-、 =,分别表示添加权限、取消权限和赋予给定的权限。 设置mode所表示的权限可用下述字母的任意组合:r、w、x、s 、t、u 、 g 、o。r表示读位,w写位,x执行/搜索位,u文件所有者的当前权限,g组成员的当前权限,o其他用户的当前权限,s设置user和group的ID模式位,t粘着位 例如: $chmod g+r,o+r example © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

77 r w x 数值 意义 无 1 执行 2 写 3 写、执行 4 读 5 读、执行 6 读、写 7 所有
2017年3月16日6时11分 数字设定法 chmod [mode] 文件名 $chmod [7] aaa r w x 数值 意义 1 执行 2 3 写、执行 4 5 读、执行 6 读、写 7 所有 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

78 ?对于目录来说,它的读、写、执行权限分别意味着什么
2017年3月16日6时11分 $ chmod a+x text $ chmod ug+w, o-w text $ chmod u+s a.out $ chmod a–x mm.txt $ chmod –x mm.txt $ chmod ugo–x mm.txt $ chmod 644 mm.txt $ chmod 750 wch.txt 目录的读权限表示用户可以读该目录的内容;写权限表示用户可以在该目录中创建新的子目录或者从该目录中删除已有的子目录;目录的执行权限表示用户可以搜索该目录。如果没有对目录的搜索权限,则读写变的没有意义。 ?对于目录来说,它的读、写、执行权限分别意味着什么 ?在当前目录下创建文件test1,设置对它的访问权限,对于你是可读可写,对组用户是可读,对其他用户是没有任何权限,你将使用哪条命令来设置这些权限?请给出另一条用于完成同样操作的命令。 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

79 默认的文件访问权限 特殊访问位 umask umask [mask] mask为八进制数表示的位掩码 文件的访问权限=777 – mask
2017年3月16日6时11分 默认的文件访问权限 umask umask [mask] mask为八进制数表示的位掩码 文件的访问权限=777 – mask umask命令通常放在系统启动文件中~/.profile(System V Unix)或~/.login(BSD UNIX) 特殊访问位 设置用户ID(SUID)位 chmod 4XXX file-list或chmod u+s file-list 设置组ID(SGID)位 chmod 2XXX file-list或chmod g+s file-list 粘着位 chmod 1XXX file-list或chmod +t file-list SUID 设置用户ID,当一个程序一旦设置了该标记以后,运行该程序的进程将拥有该程序所有者的权限 SGID 使用者在执行该文件时,都绑定了文件所有组的权限。 粘着位,当对某个目录设置该位时,非授权用户不能删除或重命名这个目录中其他用户的文件。设置粘着位的程序在执行完被保存在内容中或交换空间中,这种机制的优点是适合于频繁启动的应用程序。 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

80 $ls –l cp.new -rwx--x cp.new faculty 12 May 08 20:00 cp.new $chmod 4710 cp.new -rws--x cp.new faculty 12 May 08 20:00 cp.new $chmod u-s cp.new $chmod u-x cp.new $chmod u+s cp.new -rwS--x cp.new faculty 12 May 08 20:00 $chmod g+s cp.new $chmod 2710 cp.new -rwx--s cp.new faculty 12 May 08 20:00 $chmod 1710 cp.new 或 chmod +t cp.new -rwx--s--t 1 cp.new faculty 12 May 08 20:00

81 chgrp命令 chown 命令 改变与文件或目录相关联的组(属主) chgrp [option] group filename
2017年3月16日6时11分 chgrp命令 改变与文件或目录相关联的组(属主) chgrp [option] group filename -f 强制执行不报错 -h 如果文件是符号链接,更改符号链接的组。(默认为改变符号链接引用文件的组) -R 递归操作目录与子目录 group可以是用户组ID,也可以是/etc/group文 件中用户组的组名 例如:$ chgrp - R book /opt/local /book chown 命令 更改一个或多个文件的所有权(属主) chown [-fhR] ‘owner’[: ‘group’] file-list 例如:$ chown wang shiyan.c $ chown - R wang:users /his © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

82 文件查找命令 find命令 在目录结构中搜索文件,并执行指定的操作。 find 起始目录 寻找条件 操作
2017年3月16日6时11分 文件查找命令 find命令 在目录结构中搜索文件,并执行指定的操作。 find 起始目录 寻找条件 操作 寻找条件可以是一个用逻辑运算符and、or、 not组成的复合条件。 and、or、not分别对应为a, o, ! $ find –name ‘tmp’ –name ‘mina*’ $ find ! –name ‘tmp’ $ find \(–name ‘tmp’ –o type c –o -user ‘inin’ \)  说明:find命令从指定的起始目录开始,递归地搜索其各个子目录,查找满足寻找条件的文件并对之采取相关的操作。 在以前旧的系统当中,如果一个程序文件一旦设置了粘着位,那么当该程序中止的时候他的所有指令段将被保 存到系统的交换分区当中,再次运行时可以更快的调入系统.不过现在的操作系统已经不再使用这种功能了.但这 并不表示这功能已经完全被废弃. 当一个目录被设置为"粘着位",则该目录下的文件只能由 一、超级管理员删除 二、该目录的所有者删除 三、该文件的所有者删除 也就是说,即便该目录是任何人都可以写,但也只有文件的属主才可以删除文件 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

83 查找方式 n值可以有三种输入方式 :+n, -n, n。 例如:+20表示 21, 22, 23, 24… 以文件名和文件属性查找
2017年3月16日6时11分 n值可以有三种输入方式 :+n, -n, n。 例如:+20表示 21, 22, 23, 24… 查找方式 以文件名和文件属性查找 -name ‘字串’ 查找文件名匹配所给字串的所有文件,支持用通配符*?[] -lname ‘字串’ 查找文件名匹配所给字串的所有符号链接文件 -gid n -uid n -group ‘字串’ -user ‘字串’ -empty查找大小为0的目录或文件 -path ‘字串’ 查找路径名匹配所给字串的所有文件 -perm 权限 -size n[bckw] -type x © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

84 - ok 命令名称 {}:对符合条件的文件执行所给的Unix 命令,与exec不同的是,它会询问用户是否需要执行该命令。
2017年3月16日6时11分 以时间为条件查找 - amin n 查找n分钟以前被访问过的所有文件 - atime n 查找n天以前被访问过的所有文件 - cmin n 查找n分钟以前文件状态被修改过的所有文件 - ctime n查找n天以前文件状态被修改过的所有文件。 - mmin n 查找n分钟以前文件内容被修改过的所有文件。 - mtime n查找n天以前文件内容被修改过的所有文件。 可执行的操作  - exec 命令名称 {} :对符合条件的文件执行所给的Unix 命令,而不询问用户是否需要执行该命令。{}表示命令的参数即为所找到的文件;命令的末尾必须以“ \;”结束。  - ok 命令名称 {}:对符合条件的文件执行所给的Unix 命令,与exec不同的是,它会询问用户是否需要执行该命令。 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

85 $ find . - name ‘main*’ - exec more {}\ ;
2017年3月16日6时11分 $ find . - name ‘main*’ - exec more {}\ ; $ find . (- name a.out - o - name ‘*.o’) - atime +7 - exec rm {} \; © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

86 2017年3月16日6时11分 locate命令 locate命令用于查找文件,它比find命令的搜索速度快,它需要一个数据库,这个数据库由每天的例行工作(crontab)程序来建立 locate 相关字 $ locate issue /etc/issue /etc/issue.net  /usr/man/man5/issue.5  /usr/man/man5/issue.net.5 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

87 统计文件命令 wc命令 统计指定文件中的字节数、字数、行数, 并将统计结果显示输出。 wc [options] filelist
2017年3月16日6时11分 统计文件命令 wc命令 统计指定文件中的字节数、字数、行数, 并将统计结果显示输出。 wc [options] filelist -c 仅显示字符数 -l 仅显示行数 -w 仅显示字数 行数 字数 字节数 $ wc file1 file2 file1 file2 total © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

88 有关磁盘的命令 format命令 格式化指定的磁盘设备 format [options] -n 抑制交互特性 -device
2017年3月16日6时11分 有关磁盘的命令 format命令 格式化指定的磁盘设备 format [options] -n 抑制交互特性 -device /dev/hda1 … /dev/sda1 … /dev/rdf0135ds18 文件/etc/default/format用来指定进行格式化的默认的设备和是否每张软盘都要检验。 这两项的格式必须DEVICE=device和VERIFY=[yYnN] 例如: VERIFY=y DEVICE=/dev/rfd096ds15 Sda SCSI接口 Hba 硬盘接口 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

89 $format /dev/rfd0135ds18 $format 2017年3月16日6时11分
© 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

90 diskcp命令 例如 $diskcp 用来进行软盘文件的拷贝 diskcp -f 在拷贝进行前,先把目标盘格式化。
2017年3月16日6时11分 diskcp命令 用来进行软盘文件的拷贝 diskcp -f 在拷贝进行前,先把目标盘格式化。 -d 如果有两个软盘驱动器,就直接把源盘内容拷贝到目标盘。 -s 使用sum命令比较源盘和目标盘上的内容。如果不一样,则给出出错信息 -r 使用第二个软盘驱动器作为源盘驱动器 例如 $diskcp 这个命令可以把源软盘上的文件完全拷贝到目标软盘上。如果机器上只有一个软驱动器,那么这个命令就把源盘上的内容临时放到硬盘上,当目标盘插入驱动器后,再从硬盘往目标盘上写。如果机器上有两个软盘驱动器,这个命令就直接把原盘内容映像到目标盘上 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

91 dd命令 转换并复制文件 dd [‘operand’=‘value’ …] 参数: if=filename 指定输入文件名:默认为标准输入
2017年3月16日6时11分 dd命令 转换并复制文件 dd [‘operand’=‘value’ …] 参数: if=filename 指定输入文件名:默认为标准输入 of=filename 指定输出文件名 conv=‘value’[,‘value’…] ascii 将EBCDIC转换为ASCII ebcdic 将ASCII转换为EBCDIC lcase 将字母转换为小写 ucase 将字母转换为大写 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

92 $dd if=file.dd of=/dev/rfd0135ds18 $dd if=file1 of =file2 conv=ascii
2017年3月16日6时11分 $dd if=file.dd of=/dev/rfd0135ds18 $dd if=file1 of =file2 conv=ascii © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

93 tar命令 可以为文件和目录创建档案 ,利用tar命令,可以把一大堆的文件和目录全部打包成一个文件 tar [主选项+辅选项] 文件或者目录
2017年3月16日6时11分 tar命令 可以为文件和目录创建档案 ,利用tar命令,可以把一大堆的文件和目录全部打包成一个文件 tar [主选项+辅选项] 文件或者目录 主选项: -c 创建新的档案文件。 -r 把要存档的文件追加到档案文件的未尾。 -t 列出档案文件的内容 -u 更新文件 -x 从档案文件中释放文件 辅选项: -f 使用档案文件或设备 -k 保存已经存在的文件 -m 在还原文件时,把所有文件的修改时间设定为现在 -M 创建多卷的档案文件,以便在几个磁盘中存放。 -v 详细报告tar处理的文件信息 -w 每一步都要求确认 -z 用gzip来压缩/解压缩文件 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

94 $ tar cvf usr.tar /home $ tar czvf usr.tar.gz /home $ tar xzvf usr.tar.gz $ tar tvf usr.tar | more $ tar cMf /dev/fd0 /home $ tar xMf /dev/fd0

95 df命令 检查文件系统的磁盘空间占用情况 df [options] -a 显示所有文件系统的磁盘使用情况 -k 以k字节为单位显示
2017年3月16日6时11分 df命令 检查文件系统的磁盘空间占用情况 df [options] -a 显示所有文件系统的磁盘使用情况 -k 以k字节为单位显示 -I 显示i节点信息,而不是磁盘块。 -t 显示各指定类型的文件系统的磁盘空间使用情况。 -T 显示文件系统类型。 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

96 $ df Filesystem 1 K-blocks Used Available Use% Mounted on /dev/hda % / $ df -T Filesystem Type 1K-blocks Used Available use% Mounted on /dev/hda2 ext % /

97 du命令 统计目录(或文件)所占磁盘空间的大小。 du [options] Names… -s 对每个Names参数只给出占用的数据块总数。
2017年3月16日6时11分 du命令 统计目录(或文件)所占磁盘空间的大小。 du [options] Names… -s 对每个Names参数只给出占用的数据块总数。 -a 递归地显示指定目录中各文件及子孙目录中各文件占用的数据块数。若既不指定-s,也不指定-a,则只显示Names中的每一个目录及其中的各子目录所占的磁盘块数。 -b 以字节为单位列出磁盘空间使用情况(系统缺省以k字节为单位)。 -k 以1024字节为单位列出磁盘空间使用情况。 -c 最后再加上一个总计(系统缺省设置)。 -l 计算所有的文件大小,对硬链接文件,则计算多次。 -x 跳过在不同文件系统上的目录不予统计。 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

98 $ du l . /dev 38 . /var 48 . $ du -ab   8 ./dev/cdrom   l032 ./dev    /var/rawrite. exe    /var   6229 ./s1ack   1l0 ./aa   l0 ./wei   

99 文件系统挂载与卸载命令 mount命令 本地或远程文件资源被接到根文件层次,看起来就象是一个单一的文件系统。 “挂接 ”与“挂接点”
2017年3月16日6时11分 文件系统挂载与卸载命令 mount命令 本地或远程文件资源被接到根文件层次,看起来就象是一个单一的文件系统。 “挂接 ”与“挂接点” mount [-t vfstype] [-o options] device dir 文件系统的类型,iso9660;msdos;vfat;ntfs;smbfs;nfs 挂接方式:loop;ro;rw;iocharset 挂载方式: loop:用来把一个文件当成硬盘分区挂载上系统 ro:采用只读方式挂接设备 rw:采用读写方式挂接设备 Iocharset:指定访问文件系统所用字符集 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

100 1、从光盘制作光盘镜像文件。将光盘放入光驱,执行下面的命令 #cp /dev/cdrom /home/sunky/mydisk.iso 或
2017年3月16日6时11分 挂接光盘镜像文件 1、从光盘制作光盘镜像文件。将光盘放入光驱,执行下面的命令   #cp /dev/cdrom /home/sunky/mydisk.iso 或  #dd if=/dev/cdrom of=/home/sunky/mydisk.iso    2、将文件和目录制作成光盘镜像文件,执行下面的命令 #mkisofs -r -J -V mydisk -o /home/sunky/mydisk.iso /home/sunky/ mydir  3、光盘镜像文件的挂接(mount)   #mkdir /mnt/vcdrom #mount -o loop -t iso9660 /home/sunky/mydisk.iso /mnt/vcdrom © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

101 挂接移动硬盘或优盘 挂接光驱 ? 挂接UNIX系统NFS文件共享
2017年3月16日6时11分 挂接移动硬盘或优盘 在插入移动硬盘之前,和之后,应用fdisk –l 或 more /proc/partitions查看系统的硬盘和硬盘分区情况。 根据硬盘分区的前后变化,可以得到新加入硬盘设备号 创建挂接点 进行挂接 挂接光驱 ? 挂接UNIX系统NFS文件共享 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

102 Disk /dev/sda: 73 dot 4 GB, 73407820800 bytes
2017年3月16日6时11分 移动硬盘或优盘插入之前 # fdisk -l Disk /dev/sda: 73 dot 4 GB, bytes 255 heads, 63 sectors/track, 8924 cylinders Units = cylinders of * 512 = bytes Device Boot Start End Blocks Id System /dev/sda de Dell Utility /dev/sda2 * HPFS/NTFS /dev/sda Linux /dev/sda f Win95 Ext'd (LBA) /dev/sda Linux swap © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

103 Disk /dev/sda: 73 dot 4 GB, 73407820800 bytes
移动硬盘或优盘插入之后 2017年3月16日6时11分 # fdisk -l Disk /dev/sda: 73 dot 4 GB, bytes 255 heads, 63 sectors/track, 8924 cylinders Units = cylinders of * 512 = bytes Device Boot Start End Blocks Id System /dev/sda de Dell Utility /dev/sda2 * HPFS/NTFS /dev/sda Linux /dev/sda f Win95 Ext'd (LBA) /dev/sda Linux swap Disk /dev/sdc: 40.0 GB, bytes 255 heads, 63 sectors/track, 4864 cylinders /dev/sdc HPFS/NTFS /dev/sdc f Win95 Ext'd (LBA) /dev/sdc b Win95 FAT32 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

104 unmount命令 卸载装载的文件系统 unmount 挂载点 $mkdir -p /mnt/usbhd1
2017年3月16日6时11分 $mkdir -p /mnt/usbhd1 $mkdir -p /mnt/usbhd2 $mount -t ntfs /dev/sdc1 /mnt/usbhd1 $mount -t vfat /dev/sdc5 /mnt/usbhd2 $unmount /mnt/usbhd1 $unmount /mnt/usbhd2 unmount命令 卸载装载的文件系统 unmount 挂载点 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

105 进程命令 w命令 w [options] [user] -h 不显示标题。 -u 当列出当前进程和CPU时间时忽略用户名
2017年3月16日6时11分 进程命令 w命令 用于显示登录到系统的用户情况,但是与who不同的是,w命令功能更加强大,它不但可以显示有谁登录到系统,还可以显示出这些用户当前正在进行的工作, w [options] [user] -h 不显示标题。 -u 当列出当前进程和CPU时间时忽略用户名 -s 使用短模式。不显示登录时间、JCPU和 PCPU时间。 -f 切换显示FROM项,也就是远程主机名项。 默认值是不显示远程主机名,当然系统管理 员可以对源文件作一些修改使得显示该项成 为默认值。 -V 显示版本信息。 JCPU 终端使用CPU时间 PCPU 当前进程使用CPU时间 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

106 2:50pm up 2 min, 4 users, load average:0.22,0.16,0.06
2017年3月16日6时11分 $ w 2:50pm up 2 min, 4 users, load average:0.22,0.16,0.06 USER TTY FROM IDLE JCPU PCPU WHAT root tty :49pm 0:00s 0.56s 0.10s w foxy tty :49pm 1: s 0.42s bash root tty :49pm s 0.67s 0.25s telnet bbs ttyp0 river.net 2:49pm s 0.49s 0.49s bbs h river.net 此命令可以显示系统当前时间,系统启动到现在的时间,登录用户数,系统在最近1秒、5秒和15秒的平均负载。 JCPU指的是该终端连接的所有进程占用的时间。这个时间里并不包括过去的后台作业时间,但却包括当前正在运行的后台作业所占用的时间。而PCPU指当前进程(WHAT项中显示的进程)所占用的时间 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

107 ps命令 使用该命令可以确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵死、哪些进程占用了过多的资源等等。
2017年3月16日6时11分 ps命令 使用该命令可以确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵死、哪些进程占用了过多的资源等等。 ps [options] -a 显示当前终端上除登录shell之外的所有进程信息 -e 显示所有运行在系统中进程的信息 -l 显示进程状态的详细列表 -u uidlist 显示uid所指定的用户进程信息 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

108 $ ps PID TTY TIME COMMAND 5800 ttyp0 00:00:00 bash
2017年3月16日6时11分 $ ps PID TTY TIME COMMAND 5800 ttyp0 00:00:00 bash 5835 ttyp0 00:00:00 ps $ ps –u 147 UID PID TTY TIME CMD pts/1 0: ps pts/1 0: ksh pts/1 0: vi © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

109 top命令 提供了实时的对系统处理器的状态监视。 top [options] 交互命令 n 数字 显示指定数量的进程数 k pid 终止进程
2017年3月16日6时11分 top命令 提供了实时的对系统处理器的状态监视。 top [options] -d 指定每两次屏幕信息刷新之间的时间间隔。(5秒) -i 使top不显示任何闲置或者僵死进程。 -c 显示整个命令行而不只是显示命令名 交互命令 n 数字 显示指定数量的进程数 k pid 终止进程 h 显示各种交互命令 显示的各项目为: uptime 该项显示的是系统启动时间、已经运行的时间和三个平均负载值(最近1秒,5秒,15秒的负载值)。 processes 自最近一次刷新以来的运行进程总数。当然这些进程被分为正在运行的,休眠的,停止的等很多种类。进程和状态显示可以通过交互命令t来实现。   CPU states 显示用户模式,系统模式,优先级进程(只有优先级为负的列入考虑)和闲置等各种情况所占用CPU时间的百分比。优先级进程所消耗的时间也被列入到用户和系统的时间中,所以总的百分比将大于100%。   Mem 内存使用情况统计,其中包括总的可用内存,空闲内存,已用内存,共享内存和缓存所占内存的情况。   Swap 交换空间统计,其中包括总的交换空间,可用交换空间,已用交换空间。   PID 每个进程的ID。   PPID 每个进程的父进程ID。   UID 每个进程所有者的UID 。   USER 每个进程所有者的用户名。   PRI 每个进程的优先级别。   NI 该进程的优先级值。   SIZE 该进程的代码大小加上数据大小再加上堆栈空间大小的总数。单位是KB。   TSIZE 该进程的代码大小。对于内核进程这是一个很奇怪的值。   DSIZE 数据和堆栈的大小。   TRS 文本驻留大小。   D 被标记为“不干净”的页项目。   LIB 使用的库页的大小。对于ELF进程没有作用。   RSS 该进程占用的物理内存的总数量,单位是KB。   SHARE 该进程使用共享内存的数量。   STAT 该进程的状态。   其中S代表休眠状态;   D代表不可中断的休眠状态;   R代表运行状态;   Z代表僵死状态;   T代表停止或跟踪状态。   TIME 该进程自启动以来所占用的总CPU时间。如果进入的是累计模式,那么该时间还包括这个进程子进程所占用的时间。且标题会变成CTIME。   %CPU 该进程自最近一次刷新以来所占用的CPU时间和总时间的百分比。   %MEM 该进程占用的物理内存占总内存的百分比。   COMMAND 该进程的命令名称,如果一行显示不下,则会进行截取。内存中的进程会有一个完整的命令行。 下面介绍在top命令执行过程中可以使用的一些交互命令。从使用角度来看,熟练的掌握这些命令比掌握选项还重要一些。这些命令都是单字母的,如果在命令行选项中使用了s选项,则可能其中一些命令会被屏蔽掉。   <空格> 立即刷新显示   Ctrl+L 擦除并且重写屏幕。   h或者? 显示帮助画面,给出一些简短的命令总结说明。   k 终止一个进程。系统将提示用户输入需要终止的进程PID,以及需要发送给该进程什么样的信号。一般的终止进程可以使用15信号;如果不能正常结束那就使用信号9强制结束该进程。默认值是信号15。在安全模式中此命令被屏蔽。   i 忽略闲置和僵死进程。这是一个开关式命令。   q 退出程序。   r 重新安排一个进程的优先级别。系统提示用户输入需要改变的进程PID以及需要设置的进程优先级值。输入一个正值将使优先级降低,反之则可以使该进程拥有更高的优先权。默认值是10。   S 切换到累计模式。   s 改变两次刷新之间的延迟时间。系统将提示用户输入新的时间,单位为s。如果有小数,就换算成m s。输入0值则系统将不断刷新,默认值是5 s。需要注意的是如果设置太小的时间,很可能会引起不断刷新,从而根本来不及看清显示的情况,而且系统负载也会大大增加。   f或者F 从当前显示中添加或者删除项目。   o或者O 改变显示项目的顺序。   l 切换显示平均负载和启动时间信息。   m 切换显示内存信息。   t 切换显示进程和CPU状态信息。   c 切换显示命令名称和完整命令行。   M 根据驻留内存大小进行排序。   P 根据CPU使用百分比大小进行排序。   T 根据时间/累计时间进行排序。   W 将当前设置写入~/.toprc文件中。这是写top配置文件的推荐方法。 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

110 $ top 1:55pm up 7 min, 4 user, load average:0.07,0.09, processes:28 sleeping, 1 running, 0 zombie, 0 stopped CPU states: 4.5% user, 3.6% system, 0.0% nice, 91.9% idle Mem: 38916K av, 18564K used, 20352K free, 11660K shrd, 1220K buff Swap: 33228K av, 0K used, 33228K free, 11820K cached PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND 363 root R :00 top 1 root S :03 init 2 root SW :00 kflushd 3 root SW< :00 kswapd   ….

111 kill命令 kill [-signal_number] proc-list kill -l 常用的signal_number 1 挂起
2 中断 3 退出 9 杀死进程信号 15 软件终止信息(默认) kill kill

112 nohup命令 nohup command [args] 运行“command”, 并忽略挂起信号。用于在结束当前会话后,仍然能够运行。 $nohup find / -name foo

113 ln命令 创建文件的链接 ln[options] existing-file new-file
2017年3月16日6时11分 ln命令 创建文件的链接 ln[options] existing-file new-file ln[options] existing-file-list directory -f 强行创建链接,即使new-file已经存在 -n 如果newfile已经存在,则不创建链接 -s 创建符号链接 硬链接不能用于创建目录链接和在不同文件系统间创建文件的链接 符号文件可以跨越多个文件系统,并且可以创建目录间的链接,初始文件不能被移动 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

114 $ln Chapter3 Chapter3.hard $ls -il
13059 –rwx sarwar faculty Mar 11 14:20 Chapter1 17488 –rwx sarwar faculty 5983 Jan 17 11:57 Chapter2 52473 –rwx sarwar faculty 9352 Mar 28 23:09 Chapter3 $ln Chapter3 Chapter3.hard $ls -il 52473 –rwx sarwar faculty 9352 Mar 28 23:09 Chapter3 52473 –rwx sarwar faculty 9352 Mar 28 23:09 Chapter3.hard $rm Chapter3 $ls il 52473 –rwx sarwar faculty 9352 Mar 28 23:09 Chapter3.hard $ ln –f ~/unixbook/example/* ~/book/example

115 $ ln –s Chapter3 Chapter3.soft $ls –il
2017年3月16日6时11分 $ ls –il 13059 –rwx sarwar faculty Mar 11 14:20 Chapter1 17488 –rwx sarwar faculty 5983 Jan 17 11:57 Chapter2 52473 –rwx sarwar faculty 9352 Mar 28 23:09 Chapter3 $ ln –s Chapter3 Chapter3.soft $ls –il 52479 –rwx sarwar faculty Mar 30 12:19 Chapter3.soft $ ln –sf ~/unixbook/example/* /user/john/unixbook/examples $mv Chapter3 $cat Chapter3.soft Chapter3.soft: No such file or directory 硬链接,不能在不同文件系统下创建硬链接,只有超级用户能够创建硬链接, 执行权限和执行 执行和写权限 ?链接分为几种类型,它们之间有什么区别?1 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

116 重定向和管道 标准文件 输入重定向 输出重定向 标准输入、标准输出和标准错误 command < input-file
grep “John” < Phones grep “John” Phones 输出重定向 command > output-file

117 合并输入和输出重定向 不覆盖文件内容的重定向(追加) 管道 command < input-file > output-file
command > output-file < input-file $cat < lab1 > lab2 不覆盖文件内容的重定向(追加) command >> output-file 管道 command1|command2|…|command3 过滤器-通过管道链接起来的命令 cmd1 cmd2 cmdN 管道

118 实验2 练习学过的所有命令 练习vi命令


Download ppt "UNIX 操作系统 鲁强 计算机系: 年3月16日6时11分"

Similar presentations


Ads by Google