|
UNIX Essentials Featuring the Solaris9 Operating Environment
Preface
#uname –s –r;date Written by 绯瞳 a.k.a. Jo 欢迎转po,请保留作者信息 Mar.27th.2004
Module1 Using the Desktop in the Solaris9 Operation Environment
the History and Schools of UNIX Operating System
在介绍Sun Microsystem公司的Solaris9操作环境(Operation Environment,OE)之前先开看看UNIX操作系统的发展历史:
UNIX操作系统诞生于1969年.目前为止,UNIX有两大分支: 1.AT&T发布的UNIX操作系统System V 2.美国加州大学伯克利分校发布的UNIX版BSD(Berkeley Software Distribution) 注意,我们常说的SVR4是两大分支融合后的产物
现在几种主要的UNIX版本: 1.AIX:IBM的UNIX 2.FreeBSD 3.HP-UX:HP的UNIX 4.Linux(x86) 5.SCO UNIX 6.SunOS:源于4.3BSD,包含许多来自System V的东西.现在演变为Solaris 7.Ultrix:DEC的UNIX 8.Xenix:Intel硬件平台上的UNIX,微软推出
Introducing the Main Components of a Computer
计算机通常是由硬件和软件组成,来协同工作的.硬件比如有CPU(Central Processing Unit,RAM(Random Access Memory),硬盘(Hard Disk)等等;软件,或者说的操作系统,是指引和调整硬件活动的程序和文件组
Hardware Overview
硬件的主要组成部分,如下图:
 SunOS 5.x是1种使用虚拟内存技术的操作系统,这个技术使得你可以把硬盘上的空间临时当作内存开弥补物理内存的不足
The Solaris Operating Environment
Solaris9 OE由SunOS5.9,开放式网络计算(Open Network Computing,ONC+)软件和Solaris的图形化用户接口(graphic user interface,GUI)CDE组成.SunOS5.9操作系统用来管理系统资源和系统任务调度;ONC+提供网络服务比如网络文件系统(Network File System,NFS);CDE是图形化界面的用户接口
Introducing the SunOS Operating System
SunOS 5.9是由以下几个组件组成的: 1.内核(kernel) 2.外壳(Shell) 3.目录层次(directory hierarchy)
the kernel
kernel是SunOS5.9操作系统的核心.它管理包括以下几个方面的物理资源: 1.文件系统和结构 2.设备的管理 3.处理器的管理或CPU的运作 4.内存管理 kernel在整个SunOS5.9操作系统里的角色如下图:

the Shell
Shell是用户和kernel之间的接口,是命令的解释器,Shell接收你所输入的命令,然后解释它们,再把它们传递给kernel去进行执行.Shell的角色图如下:

Solaris9 OE中的3种默认的Shell: 1.Bourne Shell 2.C Shell 3.Korn Shell
Bourne Shell是最原始的UNIX系统的Shell,是root用户默认的Shell.root用户是最高权限的管理用户(类似Microsoft Windows中的administrator用户).普通用户的Shell提示符的$;root用户的Shell的提示符是#
C Shell拥有一些Bourne Shell所没有的特性,比如支持命令行历史,缩写,任务控制等.普通用户的Shell提示符是%;root用户的Shell提示符是#
Korn Shell是Bourne Shell和C Shell的扩展集.普通用户的Shell提示符的$;root用户的Shell的提示符是#
一些其他可选的Shell: 1.Bash:GNU Project的Bourne-Again Shell,相当好用 2.Z Shell:类似Korn Shell但是有很多增强功能 3.TC Shell:C Shell的完全兼容版本,有许多额外的增强功能
the Directory Hierarchy
Solaris9 OE的文件和目录存放方式是层次化的,如下图:

Logging in to the System
来看下Solaris9 CDE的登陆界面,如图:

Changing the Password
密码是用来防止未经过授权的用户登陆系统所设定的.在Solaris9 OE中,用户的密码必须满足以下几个条件: 1.必须是6到8个字符长 2.至少要包含2个英文字母,并且至少要有1个数字字符或者特殊字符比如分号 3.必须和登陆名(login name)不同 4.假如你现在是修改密码为新密码,那新旧密码的差异至少要有3个字符 5.密码设置可以包含空格键 6.不能是登陆名的反序组合.比如登陆名是RedNoco1,密码就不能是1ocoNdeR 但是以上这些密码规则不适用于root用户和由root用户创建的普通用户
在命令行模式下修改密码,使用passwd命令,如下: $ passwd passwd: Changing password for user1 Enter existing login password: New password: Re-enter new passwd: passwd: passwd successfully changed for user1 $
Something about the CDE
来看看CDE下的文件管理器,如图:

作为1个UNIX系统的系统管理员,应该熟悉命令行模式下的管理而非CDE下的管理 Module2 Using Command-Line Features and Help Resources
Introducing Command-Line Syntax
我们来看下命令行模式下命令的语法: command option(s) argument(s) 1.命令(command):定义系统如何去执行某样任务 2.选项(option):定义命令如何去执行,以符号-打头 3.参数(argument):定义了受到命令所影响的目标,比如文件,目录
Using Commands
我们先用uname,date和cal命令来举例: 使用uname显示系统信息,如下: $ uname SunOS 使用date命令显示系统时间和日期,如下: $ date Sat March 27 14:31:55 MDT 2004 使用cal命令显示今年和本月的日历,如下: $ cal May 2002 S M Tu W Th F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 清除终端窗口所有输出内容,使用clear命令,如下: $ clear
再来看看命令结合选项的使用方法: 使用uname命令结合-a选项,用途是列出当前有效系统信息,如下: $ uname -a SunOS host1 5.9 Generic sun4u sparc SUNW,Ultra-5_10 使用uname命令结合-s选项,用途是列出操作系统名;-r悬想用来告诉当前版本.如下: $ uname -s SunOS $ uname -r 5.9 可以在命令后跟多个选项,如下: $ uname -s -r SunOS 5.9 也可以只用1个-符号来连接多个选项,如下: $ uname -rs SunOS 5.9
再来看看命令结合参数的使用方法: 要列出2002年12月的日历,如下: $ cal 12 2002 December 2002 S M Tu W Th F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
如果要在命令行同时输入多个命令,使用符号;来分割不同的命令,具体格式为: command option(s) argument(s); command option(s) argument(s) 实例如下: $ date;uname Sat March 27 14:31:55 MDT 2004 SunOS
Control Characters
一些快捷键: 1.Ctrl+C:终止当前运行的命令 2.Ctrl+D:退出或指出文件的末尾 3.Ctrl+U:擦除整行命令 4.Ctrl+W:擦除命令行的最后1个单词 5.Ctrl+S:停止屏幕滚动.假如你使用1条命令后,产生了大量的输出内容,如果你不想让输出内容一直滚动下去,就用Ctrl+S停止滚动 6.Ctrl+Q:恢复屏幕滚动
Using Online Documentation
在线UNIX参考手册(man pages),用来描述系统命令和解释它们的使用方法.使用man命令来显示man pages.命令格式为: man command man option command man option filename 来看1个实例,假如我们要查看关于uname命令的相关信息,如下: $ man uname Reformatting page. Please Wait... done User Commands uname(1) NAME uname - print name of current system SYNOPSIS uname [ -aimnprsvX ] uname [ -S system_name ] DESCRIPTION (略)
在man pages进行输出的时候,可以: 1.使用空格键来显示下1屏的输出 2.可以使用回车讲显示下1行的输出(1行行的输出) 3.b键:后退1个满屏 4./(keyword):按关键字搜索 5.n键:使用了/(keyword)以后,按n键跳到下1个符合关键子的输出内容上(类似Microsoft Windows中记事本中的<查找下1个>功能) 6.h键:显示各种在滚动man pages输出内容的帮助 7.q键:退出man命令
Searching the Man Pages
使用man –l command/filename来查看和这些命令或文件相关的man pages,如下: $ man -l passwd passwd (1) -M /usr/man passwd (4) -M /usr/man
假如你想搜索man pages中的某1部分(section),可以使用-s选项.(关于section的信息可以使用man intro命令)格式为: man –s section-number command man –s section-number filename 根据上面查看关于passwd的例子,查看section 4的man pages,如下: $ man -s 4 passwd Reformatting page. Please Wait... done File Formats passwd(4) NAME passwd - password file SYNOPSIS /etc/passwd DESCRIPTION The file /etc/passwd is a local source of information about users’accounts. The password file can be used in conjunction with other password sources, including the NIS maps passwd.byname and passwd.bygid and the NIS+ table passwd. Programs use the getpwnam(3C) routines to access this information. (略)
假如我们要查看包含某个关键字的man pages时,可以使用man –k keyword命令,如下: $ man -k calendar (略) cal cal (1)- display a calendar calendarcalendar (1)- reminder service difftimedifftime (3c)- computes the difference between two calendar times mktimemktime (3c)- converts a tm structure to a calendar time $ 默认情况下,man pages的关键字查询功能是被禁用了的.要开启这一功能,使用root帐户执行以下命令: #catman –w #catman –w –M /usr/dt/man #catman –w –M /usr/openwin/share/man 假如在没启用man pages的关键字查询功能的情况下输入了man –k calendar命令.将会收到提示信息:No such file or directory
Module3 Viewing Directories and Files
Working with Directories
pwd:确定你当前所在的路径.如下: $ pwd /export/home/user1
ls:显示目录的内容,如下: $ ls dante dir2 dir5 file.2 file3 fruit2 dante_1 dir3 file.1 file2 file4 practice dir1 dir4 file1 file.3 fruit tutor.vi ls命令的具体格式是: ls –options pathname 如下,是显示当前路径的特定目录dir1的内容: $ ls dir1 coffees fruit trees 显示非当前路径的某个目录的内容,如下: $ ls /var/mail :saved user1
当你使用ls命令显示目录内容的时候,一些隐藏文件是不会被显示出来的.隐藏文件通常是以符号.开头. 可以使用ls命令加上-a选项来显示所有的内容包括隐藏内容,如下: $ ls -a . dir2 .dtprofile file.3 practice .. dir3 file.1 file3 .sh_history dante dir4 file1 file4 .solregis dante_1 dir5 file.2 fruit .TTauthority dir1 .dt file2 fruit2 tutor.vi
想以长列表的方式查看详细内容,使用ls命令加上-l选项,如下: $ ls -l total 90 -rw-rw---- 1 user1 staff 1319 Mar 14 10:12 dante -rw-rw---- 1 user1 staff 368 Mar 14 10:12 dante_1 drwxr-xr-x 5 user1 staff 512 Mar 14 10:12 dir1 drwxr-xr-x 4 user1 staff 512 Mar 14 10:12 dir2 drwxr-xr-x 3 user1 staff 512 Mar 14 10:12 dir3 drwxr-xr-x 2 user1 staff 512 Mar 14 10:12 dir4 drwxr-xr-x 2 user1 staff 512 Mar 14 10:12 dir5 -rw-rw---- 1 user1 staff 0 Mar 14 10:12 file.1 -rw-rw---- 1 user1 staff 1610 Mar 14 10:12 file1 -rw-rw---- 1 user1 staff 0 Mar 14 10:12 file.2 -rw-rw---- 1 user1 staff 105 Mar 14 10:12 file2 -rw-rw---- 1 user1 staff 0 Mar 14 10:12 file.3 -rw-rw---- 1 user1 staff 218 Mar 14 10:12 file3 -rw-rw---- 1 user1 staff 137 Mar 14 10:12 file4 -rw-rw---- 1 user1 staff 57 Mar 14 10:12 fruit -rw-rw---- 1 user1 staff 57 Mar 14 10:12 fruit2 drwxr-xr-x 2 user1 staff 512 Mar 14 10:12 practice -rwx--x--x 1 user1 staff 28738 Mar 14 10:12 tutor.vi 我们来解释下上面输出内容代表的含义,如下图:

可以使用ls命令和-ld选项来只显示详细的目录信息而非目录内容,如下: $ ls -ld dir1 drwxr-xr-x 5 user1 staff 512 Feb 22 14:51 dir1 $
可以使用ls命令和-R选项来递归显示目录内容和其子目录内容,如下: $ ls -R dir1 dir1: coffees fruit trees dir1/coffees: beans brands nuts dir1/coffees/beans: beans dir1/fruit: dir1/trees:
Displaying File Types
ls命令虽然可以显示当前目录内容,但是你如何去判断输出的内容里,哪个是文件,哪个是目录呢?这就得依靠-F选项来显示目录和文件类型.如下: $ ls -F dante dir2/ dir5/ file.2 file3 fruit2 dante_1 dir3/ file.1 file2 file4 practice/ dir1/ dir4/ file1 file.3 fruit tutor.vi* $ 注意输出内容的末尾的符号: 1./:代表是目录 2.*:代表是可执行文件 3.无符号:文本文件或者是ASCII文件 4.@:代表是symbolic link symbolic link是指向其他文件或目录的特殊的文件类型(类似Microsoft Windows里的快捷方式)
Using the file Command
可以使用file命令来判定某个文件的文件类型,好让你知道应该用何种程序去执行这个文件.一般的,file命令的输出有以下几种: 1.文本(text):包括包含ASCII的文本,英文文本,命令文本,可执行的Shell脚本等 2.数据(data):由某种程序创建的数据文件 3.可执行文件或2进制文件
file命令的格式为: file filename(s) 来看1个实例,如下: $ file dante dante: English text
Changing Directories
可以使用cd命令切换路径,命令格式为: cd directory 来看1个例子: $ pwd /export/home/user1 $ cd dir1 $ pwd /export/home/user1/dir1
可以通过使用路径缩写来切换路径,如下:
 一般目录都包含到父目录(..)和当前目录本身(.)的链接
用路径缩写来切换路径,如下是返回到上1级目录: $ pwd /export/home/user1/dir1 $ cd .. $ pwd /export/home/user1
假如想切换到根目录(/),每返回到1个父目录,就跟1个斜线符号/,如下: $ cd ../../.. $ pwd / $
Returning to Your Home Directory
用户主目录(home directory)是专门为某个普通用户提供存放和他相关的文件的目录,一般来说用户住目录是/home/(用户名)或者是/export/home/(用户名).比如你的登陆名是user1,那你的用户主目录就是/home/user1或者/export/home/user1
要切换到你的用户主目录,可以使用不加任何参数的cd命令,如下: $ cd $ pwd /export/home/user1
也可以使用波浪号~来代替绝对路径切换到你的用户住目录,如下: $ cd ~user1 同理,假如你想切换到user1下的fruit目录,就可以这样: $ cd ~/dir1/fruit
Working with Files
cat:显示文本文件的全部内容,格式为: cat filename 比如,要显示1个名问dante的文本文件的内容,如下: $ cat dante The Life and Times of Dante by Dante Pocai (略) 要注意的是,不要用cat命令去打开那些2进制文件.假如这样做了会造成终端窗口冻结(类似半死机状态)
假如你想查看1个内容很长的文本文件,而cat命令又只能1次全部显示.假如你想1屏1屏的查看,就可以使用more命令.more命令1次只显示1屏的内容,命令格式如下: more filename(s) 来1屏屏的查看dante文件,如下: $ moer dante The Life and Times of Dante by Dante Pocai (略) --More--(1%) 注意上面的--More--(1%),1%代表已经显示了这个文件1%的内容.并且要注意的是,和cat命令一样,不能用more命令去读取2进制文件
在用more命令查看文件内容的时候,可以用到一些快捷键: 1.使用空格键来显示下1屏的输出 2.可以使用回车讲显示下1行的输出(1行行的输出) 3.b键:后退1个满屏 4./(keyword):按关键字搜索 5.n键:使用了/(keyword)以后,按n键跳到下1个符合关键子的输出内容上(类似Microsoft Windows中记事本中的<查找下1个>功能) 6.h键:显示各种在滚动man pages输出内容的帮助 7.q键:退出more命令,返回到Shell提示符
head:显示文件的前10行内容而不是全部内容,可以使用-(n)选项,n为具体想显示的数字,来修改默认只显示10行的数量,格式为: head –(n) filename(s) 假如你想显示/usr/dict/words文件的前10行,如下: $ head /usr/dict/words 1st 2nd 3rd 4th 5th 6rd 7th 8th 9rd 10th $ 假如你只想显示前6行,如下: $ head -6 /usr/dict/words 1st 2nd 3rd 4th 5th $
tail:显示文件尾部10行,10行为默认.可以分别使用+(n)和-(n)来进行修改命令格式为: tail +(n) filename(s) 或 tail –(n) filename(s) +(n)和-(n)的区别是:+(n)是显示从n行开始一直到文件末尾;-(n)是以末尾起算的n行 来看个显示文件末尾5行的实例: $ tail -5 /usr/dict/words zounds z’s zucchini Zurich zygote $ 再来看看显示第25163行开始到末尾的实例,如下: $ tail +25136 /usr/dict/words Zorn Zoroaster Zoroastrian zounds z's zucchini Zurich zygote $
Displaying Line, Word, and Character Counts
wc:显示文件的行数,单词数和字符数,命令格式为: wc –option(s) filename(s) 先看看wc命令的可选选项: 1.-l:显示行数 2.-w:显示单词数 3.-c:显示字节数 4.-m:显示字符数 来看wc命令应用的实例,如下: $ wc dante 32 223 1319 dante $ $ wc -l dante 32 dante $
|