hpux命令

更新时间:2024-01-07 15:13:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

HPUX 命令手册

HP-UX的一些基本命令和常用文件 .................................................................................................... 4 一、用户、组操作命令 ..................................................................................................................... 4 useradd:命令增加用户 ................................................................................................................ 4 userdel: 删除用 ............................................................................................................................ 4 usermod 修改用户属性 ................................................................................................................. 5 passwd: 设置用户密码 ................................................................................................................ 5 pwck: 检测PASSWD文件的正确性 ......................................................................................... 5 vipw: 编辑PASSWD文件 ,等同于vi /etc/passwd.................................................................... 5 groupadd: 添加组 ......................................................................................................................... 5 groupmod:修改组的属性 ............................................................................................................ 5 groupdel:删除用户组 .................................................................................................................. 5 grpck: 检测group文件的正确性................................................................................................ 5 vi /etc/group:修改组配置文件 .................................................................................................... 5 二、文件及目录操作 ......................................................................................................................... 5 1. 目录: ....................................................................................................................................... 5 2. 文件类型: ............................................................................................................................. 6 3. ls .............................................................................................................................................. 6 4. rmdir ........................................................................................................................................ 6 5. mkdir ................................................................................................................................... 6 6. cp ............................................................................................................................................. 7 7. mv ........................................................................................................................................... 7 8. ln ............................................................................................................................................. 7 9. rm ............................................................................................................................................ 8 10. Chmod :改变文件的访问权限 ....................................................................................... 8 11. touch 创建一个新的空文件或改变现有文件的时间戳 .................................................. 9 12. chown:改变文件的属主 .................................................................................................. 9 13. chgrp:改变文件的所在组 ................................................................................................ 9 14. newgrp 改变当前用户的group id .................................................................................. 10 15. alias:为命令设置别名, ............................................................................................... 10 16. r:re_enter command (ksh中使用) ............................................................................ 10 17.du........................................................................................................................................... 10 三、LVM命令集 ............................................................................................................................. 10 1. pvdisplay ............................................................................................................................... 10 2. pvcreate ................................................................................................................................. 11 3. pvremove ............................................................................................................................... 11 4. pvchange ............................................................................................................................... 11 5. vgdisplay ............................................................................................................................... 12 6. vgcreate ................................................................................................................................. 12 7. vgextend ................................................................................................................................ 12 8. vgreduce ................................................................................................................................ 13 9. vgremove ............................................................................................................................... 14 10. vgdisplay ......................................................................................................................... 14 11. lvdisplay ............................................................................................................................ 14 12. lvcreate .............................................................................................................................. 14 13. lvextend ............................................................................................................................. 15 14. lvreduce ............................................................................................................................. 16 15. lvremove............................................................................................................................ 16 16. newfs ................................................................................................................................. 16 17. fsck .................................................................................................................................... 17

18. vgexpot .............................................................................................................................. 17 19. vgimport ............................................................................................................................ 17 20. vgcfgbackup ...................................................................................................................... 17 21. vgcfgrestore ....................................................................................................................... 18 22. mount ................................................................................................................................ 18 23. umount .............................................................................................................................. 18 24.bdf ............................................................................................................................................ 18 25.df .............................................................................................................................................. 18 26.fsadm ........................................................................................................................................ 18 四、npar命令 ................................................................................................................................... 18 1. parstatus ................................................................................................................................ 18 2. parcreate ................................................................................................................................ 19 3. Parmodify .............................................................................................................................. 20 4. Parremove ............................................................................................................................. 21 5. fruled ......................................................................................................................................... 22 6. frupower .................................................................................................................................... 22 五、网络故障诊断命令 ................................................................................................................... 23 1. set_parms ......................................................................................................................... 23 2. lanscan ............................................................................................................................. 23 3. ifconfig ........................................................................................................................... 23 4. linkloop ........................................................................................................................... 24 5. netstat .................................................................................................................................... 24 6. route ................................................................................................................................. 24 8. 禁止其他服务 ........................................................................................................................... 25 六、其他命令 ................................................................................................................................... 26 1. shutdown ............................................................................................................................... 26 2. init ......................................................................................................................................... 26 3. swlist ..................................................................................................................................... 26 4. tsm ......................................................................................................................................... 27 5. mstm,stm,cstm ................................................................................................................ 27 6. lvlnboot ................................................................................................................................. 27 7. setboot ................................................................................................................................... 27 8. mediainit ............................................................................................................................... 28 9. swapinfo swapon ................................................................................................................... 28 10. dmesg ................................................................................................................................ 28 11. top ..................................................................................................................................... 29 12. ioscan ................................................................................................................................ 30 13. info_col.11 ........................................................................................................................ 30 14. dd....................................................................................................................................... 30 15. sar ...................................................................................................................................... 31 16. uname ................................................................................................................................. 32 17. hostname ........................................................................................................................... 33 18. Esc键 ................................................................................................................................ 33 19. col ...................................................................................................................................... 33 20. which ................................................................................................................................. 33 21. 中文环境的配置 ..................................................................................................................... 33 21. who .................................................................................................................................... 33 22. what ................................................................................................................................... 33 23.finger ........................................................................................................................................ 33 24.find ........................................................................................................................................... 33 25.fuser .......................................................................................................................................... 34

26. Whereis: ............................................................................................................................... 35 27. tail 和 head ....................................................................................................................... 35 28. date 和 cal ......................................................................................................................... 35 29. stty ....................................................................................................................................... 35 30. tset ....................................................................................................................................... 35 31. cron ....................................................................................................................................... 35 32. sort........................................................................................................................................... 36 33. compress ................................................................................................................................. 36 34. uncompress.............................................................................................................................. 36 35. set ............................................................................................................................................ 36 36. raq ........................................................................................................................................... 36 37. tsconvert ................................................................................................................................. 36 40. lsof........................................................................................................................................... 37 41. print_manifest ......................................................................................................................... 38 诊断工具........................................................................................................................................... 38 七、vi的命令 ................................................................................................................................... 39 1. 移动光标类命令[/b] ............................................................................................................. 39 2. 屏幕翻滚类命令 ................................................................................................................... 40 3. 插入文本类命令 ................................................................................................................... 40 4. 删除命令 ............................................................................................................................... 40 5. 搜索及替换命令 ................................................................................................................... 40 6. 选项设置 ............................................................................................................................... 41 7. 最后行方式命令 ................................................................................................................... 41 8. 寄存器操作 ........................................................................................................................... 41 八、管道、变量 ............................................................................................................................... 42 1. 变量的引用 ........................................................................................................................... 42 2. shift ....................................................................................................................................... 42 3. read ........................................................................................................................................ 42 4. sh ........................................................................................................................................... 42 5. 局部及全局变量 ................................................................................................................... 42 6. 环境变量: ........................................................................................................................... 42 7. what happened at login............................................................................................................ 44 8. $() ............................................................................................................................................. 44 9. $................................................................................................................................................ 44 10. 管道 ........................................................................................................................................ 44 九、进程:....................................................................................................................................... 46 1. ps 显示机器上运行的进程 ................................................................................................. 46 2. & ........................................................................................................................................... 46 3. jobs ........................................................................................................................................ 46 4. nohup ..................................................................................................................................... 47 5. Nice ....................................................................................................................................... 47 6. Kill ........................................................................................................................................ 47 7. 子程序的运行过程: .............................................................................................................. 47 十、脚本编辑 ................................................................................................................................... 47 1. test:测试命令结果, ............................................................................................................ 47 2. 运算符: ............................................................................................................................... 47 3. 赋值语句: ........................................................................................................................... 48 4. 判断语句 ............................................................................................................................... 48 5. 循环语句 ............................................................................................................................... 49

十一、系统备份 ............................................................................................................................... 51 1. fbackup ................................................................................................................................. 51 2. frecover ................................................................................................................................ 54 3. tar 命令................................................................................................................................. 56 4. SAM ...................................................................................................................................... 57 5. Copyutil ................................................................................................................................ 59 6. make_recovery(make_tape_recovery) ............................................................................ 60 7. 用dd备份 ............................................................................................................................ 64 十二、常用配置文件 ....................................................................................................................... 64 1. etc/hosts ......................................................................................................................... 64 2. etc/passwd ....................................................................................................................... 64 3. etc/group ......................................................................................................................... 65 4. /etc/profile ................................................................................................................... 65 5. etc/inittab ..................................................................................................................... 65 6. etc/fstab ......................................................................................................................... 65 7. /etc/lvmtab ..................................................................................................................... 65 8. /etc/rc.config.d/netconf ........................................................................................... 65 9. stand/system ................................................................................................................... 65 10. var/adm/btmp ......................................................................................................................... 65 11. /var/adm/wtmp ...................................................................................................................... 65 12. /etc/rc.log................................................................................................................................ 66 13. /var/adm/sw/ ............................................................................................................................ 66 16. /var/adm/btmp wtmp .......................................................................................................... 66 17. Command vew 启动停止脚本 ........................................................................................ 66 其他: .............................................................................................................................................. 66 col命令 ......................................................................................................................................... 66 locale命令 .................................................................................................................................... 66

HP-UX的一些基本命令和常用文件 一、用户、组操作命令

useradd:命令增加用户

useradd username 添加用户

-m 添加用户同时建立目录,默认为/home/+用户名 -u 指定userid

-g 指定 primary group

-G 指定 supplement group,可以是多个 -d 指定目录 -s 指定shell userdel: 删除用

userdel username 删除用户

userdelete –r username 删除用户,连同删除目录

usermod 修改用户属性

usermod -G groupname username 改变用户的附属组 -m 将用户的目录移到-d指定的目录 -u 指定userid

-g 指定 primary group

-G 指定 supplement group,可以是多个 -d 指定新的目录

-e指定过期日期如:July 13, 1993 7/13/93 -l 改变login 名称 -s 指定shell passwd: 设置用户密码 passwd username

pwck: 检测PASSWD文件的正确性

vipw: 编辑PASSWD文件 ,等同于vi /etc/passwd

groupadd: 添加组

groupadd groupname

groupadd –g groupid groupname groupid要小于param.h头中所定义的值,`1-99为系统保留,建议不要使用。

grouped –g groupid –o groupname 表示groupid 可相同的建立一个新的组 groupmod:修改组的属性

groupmod -n accounts accts 修改名称 groupmod –g groupid accts 修改groupid -n 改变group的名称

-o 表示groupid 可相同的 groupdel:删除用户组

groupdel groupname grpck: 检测group文件的正确性 vi /etc/group:修改组配置文件

二、文件及目录操作

1. 目录:

../ 表示上一级目录, ../.. 则表示上上一级目录 ./ 表示当前目录

当一个目录被创建时,同时建立 . 及 .. 两个隐含目录。

2. 文件类型:

- A regular file d A directory

l A symbolically linked file n A network special file

c A character device file (terminals, printers) b A block device file (disks)

p A named pipe (an interprocess communication channel)

3. ls

-a 显示所有文件,包括隐含文件

-d Lists characteristics of the directory, instead of the contents of the directory. Often used with -l to display status of a directory.

-l Provides a long listing that describes attributes about each file, including type, mode, number of links, owner, group, size (in bytes), the modification date, and the name.

-F 为显示的目录加上/,可执行文件加上*

-R Recursively lists files in the given directory and in all subdirectories.

ls -F = lsf ls -l = ll ls –R = lsr

4. rmdir

-f 消除确认提示,如果-i参数在前面,-I参数失效,如果在后面-I 参数其作用。 -i 当删除一个目录时出现确认提示。

-p 当删除一个目录时,如果删除后其父目录为空了,那么连同其父目录一起删除直至遇到非

空父目录

例:

To remove directories with a prompt for verification:

rmdir -i test test: ? (y/n) y

To remove as much as possible of a path, type:

rmdir -p component1/component2/dir 5.

mkdir

-m mode 创建一个目录时,其默认的访问权限基于umask, 使用了-m 参数后则根据m

的设定值设定创建目录的权限

-p 创建中间目录,如下例,即使fruit/apple fruit/grape fruit不存在,

也一起创建

EXAMPLES

The following command would make the fruit directory if it does not already exist:

$ mkdir -p fruit/apple fruit/grape fruit/orange

6. cp

拷贝文件或目录

-i 交互式提示,特别到目标同名,时

-f 强制性,没有提示,覆盖目标同名的文件或目录。 -r 拷贝目录

-R 拷贝目录,同时将owner的属性该为可读写。 cp -p –r 拷贝文件和目录时怎样才能保持原来的文件和目录的属性 7. mv

-i 交互式提示,特别到目标同名,时

-f 强制性,没有提示,覆盖目标同名的文件或目录。

8. ln

-f 强制生成连接,即使连接文件名存在,则覆盖原存在的文件

-i -f覆盖存在的同名文件时,提示是否覆盖。

-s 软连接。不加-s则为硬连接 硬连接

Inode Table Data Blocks Directory /mydir

ln /mydir/f1 /mydir/file1 ? ? ? f1 101 file1 101 ? ? 101 -rwxr-xr-x

? ? ? f1 102 file1 103 ? ? 9. rm

硬连接建立后如果将原文件f1删除,连接文件仍然可用,ll 显示出来文件类型为-(普通文件),大小与原文件相同

软连接 102 -rwxr-xr-x 103 link to /mydir/f1

ln –s /mydir/f1 /mydir/file1

软连接原文件f1删除后,链接文件不可用,且ll 显示出来文件类型为l,文件名为file1->f1,大小很小,

-f forces the named files to be removed—no notice will be given to the user, even if an error occurs.

-r recursively removes the contents of any directories named on the command line.

-i interrogate or interactive mode, which requires that the user confirm that the removal be completed. You respond with either y for yes or n for no. Entering a Return is the same as answering no.

10. Chmod :改变文件的访问权限

r read permission w write permission x execute permission

and how you would like to modify that permission: + add permission

??subtract permission = set permission equal

You can also specify which grouping of permissions you wish to modify:

u user (owner of the file)

g group (group the file is associated with) o other (all others on the system)

a all (every user on the system)

none assigns permission to all fields

$ ls -l f1

-rw-r--r-- 1 user3 class 37 Jul 24 11:06 f1 $ chmod g=rw,o= f1 $ ls -l f1

-rw-rw---- 1 user3 class 37 Jul 24 11:06 f1 $ ls -l f2

-rw-rw-rw- 1 user3 class 37 Jul 24 11:08 f2 $ chmod u+x,g=rx,o-rw f2 $ ls -l f2

-rwxr-x--- 1 user3 class 37 Jul 24 11:08 f2

$ chmod 640 filename

11. touch 创建一个新的空文件或改变现有文件的时间戳

The touch command has the following options: -a time Change the access time to time.

-m time Change the modify time to time.(即为 ll 显示的时间) -t time Use time instead of the current time.

-c If the file does not already exist, do not create it.

改变一个文件的时间戳,例:

# echo “+ +” > /.rhosts

这一步生成一个.rhosts文件,看看它的时间. # ls -l /.rhosts

-rw-r–r– 1 root other 4 Jul 2 16:45 /.rhosts 好,我们如下操作看看会怎么样? # touch -r /bin/sh /.rhosts

有什么效果? 我们再次ls -l看一下, # ls -l /.rhosts

-rw-r–r– 1 root other 4 Apr 5 16:32 /.rhosts 已变为路径时间 或者

# touch -t 08181500 /.rhosts

-rw-r–r– 1 root other 4 Aug 18 15:00 /.rhosts 成为指定的任意时间

这样我们看到时间戳已经变了.变成了一个”老”文件,这样很可能就会逃脱管理员的视线...

12. chown:改变文件的属主 chown owner[:group] filename

13. chgrp:改变文件的所在组 chgrp groupname filename

14. newgrp 改变当前用户的group id

不加任何参数回到默认组,如果当前用户没有所要访问的组号的访问权限,则无法成功。

15. alias:为命令设置别名, 例:alias dir=ls

16. r:re_enter command (ksh中使用)

用history [–n ] 显示历史命令,每个命令的前面会有一个号,用r 号码,即可执行相应的历史命令。 17.du

Du –sk /tmp 或到/tmp目录下执行显示该文件目录使用量

三、LVM命令集

1. pvdisplay

pvdisplay [-v] [-b BlockList] pv_path

-v 详细显示pv信息,包括每个block --b BlockList 显示指定block的信息

例:

# pvdisplay -b 04183 /dev/dsk/c1t6d0 --- Physical volumes ---

PV Name /dev/dsk/c1t6d0 VG Name /dev/vg00

PV Status available Allocatable yes VGDA 2 Cur LV 9

PE Size (Mbytes) 4 Total PE 4340 Free PE 156

Allocated PE 4184 Stale PE 0

IO Timeout (Seconds) default Autoswitch On

--- Block Mapping ---

Block Status Offset LV Name

33 structure

2. pvcreate

pvcreate [-b] [-B] [-d soft_defects] [-s disk_size] [-f] [-t disk_type] pv_path -B 创建boot盘,预留boot区

-f 强制创建,即使disk上存在文件系统 -s disk_size 定义pv有效扇区的数量

-t disk_type 当pvcreate无法返回pv的大小时,需要指定设备类型, 如hp7959S,如不加disk_type则获取pv的设备信息。

-d soft_defects 指定BBR区block的最小数量,此值不能超过7039,默认为每8k一个block, 例 :

pvcreate –f /dev/rdsk/c0t1d0 pvcreate –B /dev/rdsk/c0t1d0 3. pvremove

pvremove pv_path 用于删除一个pv的LVM机构信息,删除后该pv不再是一个LVM结构的盘。但如果该pv属于某个vg,则无法完成,需先用vgremove将该pv从vg中取出来。

4. pvchange

pvchange [-A autobackup] -s pv_path

pvchange [-A autobackup] -S autoswitch pv_path

pvchange [-A autobackup] -x extensibility pv_path

pvchange [-A autobackup] -t IO_timeout pv_path

pvchange [-A autobackup] -z sparepv pv_path 改变一个pv在vg中的访问路径,但如果该vg以共享方式被激活时,该命令不能执行。

-A:是否对所作的修改进行保存, y 保存,vgcfgbackup被执行,默认值;n不保存。

-s立即执行访问该路径。

-S 是否执行自动切换:y 当有一条更好的路径可用时切换,默认值;n 当有更好的路径可用时不切换,直至指定的路径不可用才切换到其它路径

-t 设置pv不可访问的延时时间,超过该时间,驱动则认为该设备已坏。为0表示用该设备的默认值

-z y 将一个vg内的pv转换成spare盘,n将spare盘转为一般的pv。旋转mirrodisk. 例:

当路径不可用时切换,且切换后即使原路径可用也不切换回来。 pvchange -S n /dev/dsk/c0t0d0

手动设置pv使用其它路径

pvchange -s /dev/dsk/c2t0d2

设置 IO_timeout 值到60秒

pvchange -t 60 /dev/dsk/c2t0d2

改变一个空盘成spare盘

pvchange -z y /dev/dsk/c2t0d2

5. vgdisplay

pvdisplay [-v] [-b BlockList] pv_path

-v 详细显示vg的信息,包括lv及pv的简要信息。 不加参数显示所有的vg信息。 6. vgcreate

vgcreate [-f] [-A autobackup] [-x extensibility] [-e max_pe] [-l max_lv] [-p max_pv] [-s pe_size] [-g pvg_name] vg_name pv_path ...

-f 强制执行,即使该 pv含文件系统或属于某个vg. -l max_lv 一个vg内lv的最大数量 -e max_pe PE/Pv最大值

-p max_pv 一个vg内pv的最大数量 -s pe_size 设置pe的大小 例:

# mkdir /dev/vg01

# mknod /dev/vg01/group c 64 0x010000 # chown –R root:sys /dev/vg01 # chmod 755 /dev/vg01

# chmod 640 /dev/vg01/group

# vgcreate vg01 /dev/dsk/c0t1d0 /dev/dsk/c0t2d0

Specify the maximum number of LVs allowed in the VG (Default: 255) # vgcreate –l 1-255 vg01 /dev/dsk/c0t1d0 /dev/dsk/c0t2d0

Specify the maximum number of PVs allowed in the VG (Default: 16) # vgcreate –p 1-255 vg01 /dev/dsk/c0t1d0 /dev/dsk/c0t2d0

Specify the extent size (Default: 4MB)

# vgcreate –s 1-256 vg01 /dev/dsk/c0t1d0 /dev/dsk/c0t2d0

Specify the maximum PE/PV (Default: 1016, or the number of PEs on largest initial disk)

# vgcreate –e 1-65535 vg01 /dev/dsk/c0t1d0 /dev/dsk/c0t2d0

7. vgextend

vgextend [-f] [-A autobackup] [-g pvg_name] [-x extensibility] [-z sparepv] vg_name pv_path ... 添加pv扩展vg

-A是否对所作的修改进行保存, y 保存,vgcfgbackup被执行,默认值;n不保存。

-x 可扩展性设置

-z 添加入的盘作为spare盘使用或普通盘使用。y为spare n为普通盘 注:共享激活时不可使用

用vgextend还可就添加多路径。 例:

vgextend /dev/vg03 /dev/dsk/c0t1d0 /dev/dsk/c0t2d0

向pvg0上的vg03加载两块硬盘

vgextend -g PVG0 /dev/vg03 /dev/dsk/c0t3d0 /dev/dsk/c0t4d0

添加一块host spare盘

vgextend -z y /dev/vg03 /dev/dsk/c2t4d0

8. vgreduce

/usr/sbin/vgreduce [-A autobackup] vg_name pv_path ...

/usr/sbin/vgreduce [-A autobackup] [-l] vg_name pv_path

/usr/sbin/vgreduce [-A autobackup] [-f] vg_name 从vg中删除pv

当有多条路径时须将每条路径都删除才能将pv删掉,否则如果删除的是主路径(在用的),则辅路径被使用。删除pv时最后要保留一个pv.

-A是否对所作的修改进行保存, y 保存,vgcfgbackup被执行,默认值;n不保存。

-f 删除vg中丢失的pv,系统根据lvmtab中的信息读取相应的pv,并和内核中的信息比较,如有丢失且pv为空则删除,否则报出相应的pv信息,如要删除需用lvreduce或lvremove删除相应的lv再删除。当pvdisplay显示cur pv大于act pv时存在这样的问题。 例:

从vg01中去除c0t1d0

vgreduce /dev/vg01 /dev/dsk/c0t1d0 将vg01中丢失的pv全部去掉 vgreduce -f /dev/vg01

将vg01中标示为丢失的pv去除(虽然还在lvmtab中) vgreduce -l /dev/vg01

去除掉丢失的盘后出现以下信息:

PV with key 0 successfully deleted from vg /dev/vg01

Repair done, please do the following steps.....:

1. Save /etc/lvmtab to another file.

2. Remove /etc/lvmtab.

3. Use vgscan -v to recreate /etc/lvmtab.

4. NOW use vgcfgbackup(1M) to save the LVM setup.

9. vgremove

vgremove vg_name ... 在系统中删除指定的vg,删除前要求该vg中只剩下一个pv,同时所有的lv均已被删除。 例:

vgremove /dev/vg02

10.vgdisplay

显示逻辑卷组信息,如包含哪些物理盘及逻辑卷等。

显示磁盘各种信息,如磁盘大小,包含的逻辑卷,设备名称等。 c:controller,和磁盘联接的控制器有关。

t:target,每个磁盘有一个唯一的target数字,只有磁盘设备本身才可以修 改。

d:device unit number,对于非共享控制器而言,该值将为0,对于共享控制器而言,该值将为磁盘设备单元的内部号。

11. lvdisplay

lvdisplay [-k] [-v] lv_path -v 详细显示该lv的信息。

-k 同-v,除了显示pvkey(Physical Volume Number in VG),而非pvname。 12.lvcreate

lvcreate [-A autobackup] [-c mirror_consistency] [-C contiguous] [-d schedule] [-D distributed] [-i stripes -I stripe_size] [-l le_number | -L lv_size] [-m mirror_copies] [-M mirror_write_cache] [-n lv_name] [-p permission] [-r relocate] [-s strict] vg_name 创建lv

-d 当设置了mirror时,设置向原盘和mirro 盘写方式,-p 为Parallel –s 为Sequential方式: 例如:

?Create a mirrored LV using the parallel scheduling policy: # lvcreate –L 32 –n data –m 1 –d p vg01

?reate a mirrored LV using the sequential scheduling policy: # lvcreate –L 32 –n data –m 1 –d s vg01 ?Change the scheduling policy on an existing LV: # lvchange –d p /dev/vg01/data

-c 数据一致性恢复设置,配合-M n参数使用,y:(默认) 系统crash后

nomwcsyncd 自动同步整个lv,对于大文件系统则需要花费比较长的时间。n :不进行恢复,常用于向swap这样的区域。

-M 写缓冲设置

?Create a 32-entry MWC table in memory to track pending write requests ?Subdivide each LV into 256K “Logical Track Groups” (LTGs).

?When an LTG has a pending write request, mark that LTG “dirty” in the MWC. ?When a write request completes, mark that LTG “clean” in the MWC. How does LVM retain MWC information across reboots/crashes? ?Create an MCR table in the VGRA on disk

?If a write is scheduled to a new LTG, create an MWC entry and flush to the MCR on-disk

?If a write is scheduled to an LTG already in the MWC, no need to flush ?After a crash, LVM only resyncs LTGs listed in the MCR 有y(默认) n 两个参数 例:

?Create an LV using the MWC consistency recovery policy

# lvcreate –L 32 –m 1 –n data –M y vg01?Create an LV using the NOMWC consistency recovery policy

# lvcreate –L 32 –m 1 –n data –M n –c y vg01?Create an LV with using the NONE consistency recovery policy

# lvcreate –L 32 –m 1 –n data –M n –c n vg01?Change the consistency recovery policy on an existing LV (umount required!) # umount /data

# lvchange –M y /dev/vg01/data

# mount /data

-s mirror分布设置,g:PVG-Strict 并行分布在不同的pv上(需在不同的链路上) y:Strict 在不同的盘上 n:Non-Strict可在同一块盘上。

-l le的数量设置LV的大小(1-65535)

-L LV的实际大小(以M为单位,1-1666772) 例:如上,如果这两个值都没有设,默认值为0

-n lv的名字,如没有则用lvol? -m mirror数量的设置。 13.lvextend

lvextend [-A autobackup] {-l le_number | -L lv_size | -m mirror_copies} lv_path [pv_path ... | pvg_name ...] 增加空间或增加mirror

-l le的数量设置LV的大小(1-65535

-L LV的实际大小(以M为单位,1-1666772) -m 设置mirror, 例:

增加lvol3到100个pe

lvextend -l 100 /dev/vg01/lvol3

增加lvol3到400M

lvextend -L 400 /dev/vg01/lvol4

在一个指定的硬盘上创建lv的mirror

lvextend -m 1 /dev/vg00/lvol3 /dev/dsk/c0t3d0

增加文件系统步骤:

lvextend -L 400 /dev/vg06/lvol3 umount /dev/vg06/lvol3 extendfs /dev/vg06/rlvol3 mount /dev/vg06/lvol3 /mnt

14.lvreduce

lvreduce [-A autobackup] [-f] -l le_number lv_path

lvreduce [-A autobackup] [-f] -L lv_size lv_path

lvreduce [-A autobackup] -m mirror_copies lv_path [pv_path ...]

lvreduce [-A autobackup] -k -m mirror_copies lv_path 减少lv的空间或mirror的数量。

-f 强制执行,如果较少到的空间小于数据空间,不会出现提示执行,数据将被破坏且无法mount,

-k 针对missed盘删除lv,常配合-m 0使用 例:

减少lv到100个pe

lvreduce -l 100 /dev/vg01/lvol3

减少lv的mirror到一个

lvreduce -m 1 /dev/vg01/lvol5

去除mirror

lvreduce -m 0 /dev/vg01/lvol4 /dev/dsk/c1t0d0

15.lvremove

lvremove [-A autobackup] [-f] lv_path ... 删除指定的lv

-f 没有用户提示,直接强制执行。 例如

lvremove -f /dev/vg01/lvol5

16.newfs

newfs [-F FStype] [-o specific_options] [-V] special 创建文件系统

-F 创建文件系统的类型(由/etc/default/fs定义)

-o 文件系统的类型 -v 显示执行过程及结果 例:

newfs -F hfs /dev/rdsk/c1t0d2 :在整个硬盘上创建文件系统

newfs –F vxfs –o largefiles /dev/vg01/rdata 在一个lv上创建,并支持大文件系统

17.fsck

文件系统的一致性检测并进行恢复

fsck [-F FSType] [-m] [-V] [special ...]

fsck [-F FSType] [-o FSspecific-options] [-V] [special ...] -F 文件系统的类型 -m 只进行完整性检查 -o 定义类型

-v 显示执行过程及结果 18.vgexpot

vgexport [-m mapfile] [-p] [-v] [-f outfile] vg_name vgexport -m mapfile -s -p -v vg_name -m 指定所存取的map名

-p 执行命令但不从lvmtab中去除相应的vg及设备文件 -v 显示执行过程及结果

-f 将pv_path的信息写入outfile中

-s 配和-v –p-m 命令使用,将vg信息写如一个map文件 例如:

vgexport vg01 导出vg

vgexport -m /tmp/vg01.map –p –s vg01 导出vg,并存到vg01.map中,且不从lvmtab中去除相应的vg及设备文件 19.vgimport

vgimport [-m mapfile] [-p] [-v] [-f infile] vg_name pv_path vgimport -m mapfile -s -v vg_name -m 指定所存取的map名

-p 执行命令但不向lvmtab中加入相应的vg及设备文件 -v 显示执行过程及结果

-s 配和-v -m 命令使用,基于一个map文件向系统中导入相应的信息 例如

加载c0t1d0 c0t3d0上的vg01

vgimport -v /dev/vg01 /dev/dsk/c0t1d0 /dev/dsk/c0t3d0 利用vg01.map加载vg01的信息

vgimport –m /tmp/vg01.map –s vg01

20.vgcfgbackup

vgcfgbackup [-f vg_conf_path] [-u] vg_name -f 将保存的vg的lvm配置信息保存到指定的路径中,默认情况为/etc/lvmconf/中 例:

vgcfgbackup -f /tmp/vg00.backup vg00

21.vgcfgrestore

vgcfgrestore -n vg_name -l vgcfgrestore [-R] [-F] -n vg_name [-o old_pv_path] pv_path vgcfgrestore -f vg_conf_path -l vgcfgrestore [-R] [-F] -f vg_conf_path [-o old_pv_path]

-n 指定的vg的名称 -F 强制执行 -l 显示配置信息

-R 强制执行,即使vg处于激活状态 向c0t4d0上加载lvm配置信息

vgcfgrestore -f /tmp/vg00.backup /dev/rdsk/c0t4d0

22.mount

加载文件系统点

mount -o ro /dev/dsk/c0t1d0(光驱的设备文件) /cdrom 以只读方式加载光驱 mount /dev/vg01/mydata /mydata

mount –a 加载fstab中定义的所有的文件系统 23.umount

卸载文件系统的mount点 例

umont /cdrom

umount /opt <卸除opt>

-9 强行关掉命令,5988 进程名 24.bdf

列出已加载的逻辑卷及其加载位置。查看容量是否变化 25.df

du是检查目录/文件的的空间,如du -sk /home/ftp可以看出/homt/ftp下面有多少k空间被使用了。在检查在一个文件系统满的时候,du -sk * 这个命令对于确定是那个文件/目录非常方便。 26.fsadm

fsadm –b 819200 /tmp

四、npar命令

1. parstatus parstatus

parstatus -s

parstatus -w parstatus [-X]

parstatus [-A] [-M] -C|-I parstatus [-M] -B|-P

parstatus [-M] -i IOchassis [-i...] parstatus [-V|-M] -c cell [-c...] parstatus [-V|-M] -b cabinet [-b...]

parstatus [-V|-M] -p PartitionNumber [-p...] -w 显示本地partition号 -x 显示complex的属性

-A 显示complex中可用的资源

-v 详细显示相关信息,包括cpu,memory 等 -C 显示complex中所有cell板的信息 -I 显示complex中所有I/O板的信息 -B 显示complex中所有 cabinet 板的信息 -P 显示complex中所有partition板的信息

-c cellid(cabinet/slot,如2/4) 显示指定cell的信息 -p 指定的partion的信息,不加号表示所有的 例:

Lists all nPartitions within the server complex, including the local nPartition # parstatus -P

List detailed information about all cells and nPartitions in the server complex #parstatus -C

Display detailed information about the partition number (-p#) specified #parstatus -V -p#

list all unassigned (available) cells in the server complex #parstatus –AC

2. parcreate

Parcreate 创建一个npar 语法:

HP-UX B.11i

parcreate [-P PartitionName] [-I IPaddress]

-c cell:[type]:[use_on_next_boot]:[failure_usage] [-c...] [-b path] [-t path] [-s path] [-r cell] [-r...] [-B]

HP-UX B.11.23

parcreate [-P PartitionName] [-I IPaddress] [-L clm_value] -c cell:[type]:[use_on_next_boot]:[failure_usage][:clm]

[-c...][-b path] [-t path] [-s path] [-r cell] [-r...] [-B] [-u username:[passwd] -h IPaddress|hostname |-g [passwd] -h IPaddress|hostname ]

参数:此处仅解析11i,其余请参阅man -P PartitionName npar的名称

-I Ipaddress 设置ip地址

-c cell:[type]:[use_on_next_boot]:[failure_usage] 定义添加到npar中的cell, 各参数分别如下

? cell:指定cell的路径,如0/0 为cabinet 0 slot 0 ? type:其值为base

? use_on_next_boot: y Participate in reboot. (Thedefault.) n Do not participate in reboot.

? failure_usage: ri Reactivate with memory interleave (the default). Specifies to integrate the cell into the nPartition as normally occurs.

-b 定义primary引导路径. -t 定义alt引导路径

-s定义alt引导路径(第二条) -r cell 定义core cell

-B Specifies to boot the nPartition.

Creating a New nPartition

#parcreate -P \

Creates a new partition using the cell in cabinet 0 slot 0 (0/0). #parcreate -c 0/0:base:y:ri When the -B option is not specified, the new partition remains inactive (it is not booted) and you still can modify it. To boot the new partition, use the MP Command menu’s BO command.

3. Parmodify

parmodify HP-UX B.11.11:

parmodify -p PartitionNumber

-a cell:[type]:[use_on_next_boot]:[failure_usage] [-a...] | -m cell:[type]:[use_on_next_boot]:[failure_usage] [-m...] | -I IPaddress | -r cell [-r...] | -d cell [-d...] | -b path | -t path | -s path | -P PartitionName | -B HP-UX B.11.23:

parmodify -p PartitionNumber

-a cell:[type]:[use_on_next_boot]:[failure_usage][:clm] [-a...] |-m

cell:[type]:[use_on_next_boot]:[failure_usage][:clm]

[-m...] | -I IPaddress | -r cell [-r...] | -d cell [-d...] | -b path | -t path | -s path | -P PartitionName | -B |

[-u username:[passwd] -h IPaddress|hostname |-g [passwd] -h IPaddress|hostname ]

-p PartitionNumber par号

-a cell:[type]:[use_on_next_boot]:[failure_usage]

HP-UX B.11.23 and Windows:

-a cell:[type]:[use_on_next_boot]:[failure_usage][:clm] 指定要加入npar的cell, 各参数分别如下

? cell:指定cell的路径,如0/0 为cabinet 0 slot 0 ? type:其值为base

? use_on_next_boot: y Participate in reboot. (Thedefault.) n Do not participate in reboot.

? failure_usage: ri Reactivate with memory interleave (the default). Specifies to integrate the cell into the nPartition as normally occurs.

-m cell:[ type]:[ use_on_next_boot]:[ failure_usage] 改变npar中指定cell的属性,参数同上 -I Ipaddress 指定npar的ip地址

-r cell 指定core cell,可定义1-4个 -d cell 删除指定的cell -b path 定义 primary 引导路径 -t path 定义 alternate引导路径 -s path 定义 HAA引导路径 -P PartitionName npar名称

-B 定义是否引导该npar,默认是不。加了该参数后该npar被引导并被激活。修改后需重起到reboot for reconfig以使其生效。

After adding a cell to an active nPartition, you must perform a reboot-for-reconfig (shutdown -R) in order to use the cell in the nPartition.

Adding Cells to an nPartition #parmodify -p1 -a3:base:y:ri [-B] Removing a cell from an nPartition # parmodify -p0 -d4 [-B] Renaming an nPartition

#parmodify -p1 -P \

Adds the cell (0/3) to the specified partition #parmodify -p1 -a 0/3:base:y:ri ?When the -B option is specified, if the partition is inactive it is booted

immediately. For active partitions, perform a reboot-for-reconfig (shutdown -R) of the partition to use the cell.

4. Parremove

Parremove 删除一个npar

parremove -p PartitionNumber [-F] -p PartitionNumber 定义要删除的npar号.

-F 强制删除,即使他在active状态,(仅限于local npar)

Deleting an nPartition #parremove [-F] -p3

You can delete the local partition and any inactive remote partitions within a server complex.

?Use the parremove command or Partition Manager to delete nPartitions. –To remove the local partition issue the parremove -F -p# command, then perform a reboot-for-reconfig (shutdown -R). –To remove an inactive remote partition: parremove -p#?Deleting a partition causes all the partition’s cells (and all associated I/O resources) to be unassigned.

?Before removing a partition, save its current configuration. Use the parstatus -V -p# command, and save the output in case you want to recreate the partition.

5. fruled

该命令闪烁硬件的attention指示灯,或将其关闭。

fruled [-f|-o] [-B] -c cell [-c...]

fruled [-f|-o] [-B] -i IOchassis [-i...] fruled [-f|-o] -b cabinet [-b...] fruled [-f] -C [-l cabinet] [-l...] fruled [-f] -I [-l cabinet] [-l...] -f 关闭指示灯 -o 闪烁指示灯

-B 闪烁或停止 包含cell或io的cabinet number LCD

-c cell 指定cell,它可以是local ( cabinet/slot) 方式或 global ( cell_ID) 方式

-i Iochassis 指定io -b cabinet 指定cabinet -C 关闭所有cell的attention指示灯

-l cabinet 限制-C or –I所在的cabinet。

6. frupower

该命令打开、关闭、显示npar中cell和i/o的电源。

frupower [ -d | -o | -f ] -c cell [-c...]

frupower [ -d | -o | -f ] -i IOchassis [-i...] frupower [-d] -C [-l cabinet] [-l...] frupower [-d] -I [-l cabinet] [-l...]

-d 显示指定cell或io的电源状态 -o 打开指定cell或io的电源. -f 关闭指定cell或io的电源状态

-c cell 指定cell,可以使local方式(cabinet/slot),或global方式(cell_ID)

-i Iochassis 指定io -C 显示所有cell的状态 -I 显示所有io的状态

-l cabinet 限制所在的cabinet

五、网络故障诊断命令

1. set_parms

如需修改网络地址、主机名等,

set_parms hostname | timezone | date_time | root_passwd | ip_address | taddl_netwrk hostname: 修改主机名,同时修改相应的文件,如/etc/hosts,需要重起生效,注意有些软件会记住主机名,如果改了可能不能用。

timezone : 修改时区,需要重起 date_time:修改系统时间 root_passwd:修改root密码

ip_adderss:修改ip地址,一般是修改/etc/rc.config.d/netconf中定义的lan号最低的那个lan。他不会相应的修改etc/hosts等相关文件。

taddl_netwrk :修改掩码,路由,对DNS,NIF的访问控制,需要重起 例

# set_parms hostname # set_parms ip_address

2. lanscan

列出网卡状态及网络配置信息。 lanscan

Hardware Station Crd Hardware Net-Interface Path Address In# state name unitstate 8/20/5/1 0x0800097843FB 0 up lan0 up

3. ifconfig

确认网络地址:

# ifconfig lan0

启动网卡:

# ifconfig lan0 up

4. linkloop

网络不通的诊断过程:

ping 自己网卡地址 (ip 地址)

ping其它机器地址,如不通,在其机器上用lanscan 命令得知 station address,然后linkloop station_address 来确认网线及集成器是否有问 题。 在同一网中, subnetmask 应一致。

5. netstat

netstat –rn 路由信息等。 nestat –in 网卡状态

6. route

配置网关

手动加网关:

route add default 20.08.28.98 1 把网关自动加入系统中

vi /etc/rc.config.d / netconf :

ROUTE_DESTINATION [0]=default ROUTE_GATEWAY [0]=20.08.28.98 ROUTE_COUNT [0]=1 :

/sbin/init.d/net 将执行:

/usr/sbin/route add default 20.08.28.98 1 命令 netstat -rn 查看路由表

另外也可用 set_parms addl_netwrk 来设缺省路由。

7. Arp

显示和修改“地址解析协议 (ARP)”缓存中的项目。ARP 缓存中包含一个或多个表,它们用于存储 IP 地址及其经过解析的以太网或令牌环物理地址。计算机上安装的每一个以太网或令牌环网络适配器都有自己单独的表。如果在没有参数的情况下使用,则 arp 命令将显示帮助信息。

语法

arp [-a [InetAddr] [-N IfaceAddr]] [-g [InetAddr] [-N IfaceAddr]] [-d InetAddr [IfaceAddr]] [-s InetAddr EtherAddr [IfaceAddr]]

参数

-a [InetAddr] [-N IfaceAddr]

显示所有接口的当前 ARP 缓存表。要显示指定 IP 地址的 ARP 缓存项,请使用带有 InetAddr 参数的 arp -a,此处的 InetAddr 代表指定的 IP 地址。要显示指定接口的 ARP 缓存表,请使用 -N IfaceAddr 参数,此处的 IfaceAddr 代表分配给指定接口的 IP 地址。-N 参数区分大小写。 -g [InetAddr] [-N IfaceAddr] 与 -a 相同。

-d InetAddr [IfaceAddr]

删除指定的 IP 地址项,此处的 InetAddr 代表 IP 地址。对于指定的接口,要删除表中的某项,请使用

IfaceAddr参数,此处的 IfaceAddr 代表分配给该接口的 IP 地址。要删除所有项,请使用星号 (*) 通配符代替 InetAddr。

-s InetAddr EtherAddr [IfaceAddr]

向 ARP 缓存添加可将 IP 地址 InetAddr 解析成物理地址 EtherAddr 的静态项。要向指定接口的表添加静态 ARP 缓存项,请使用 IfaceAddr 参数,此处的 IfaceAddr 代表分配给该接口的 IP 地址。 /?

在命令提示符显示帮助。 注释

InetAddr 和 IfaceAddr 的 IP 地址用带圆点的十进制记数法表示。

物理地址 EtherAddr 由六个字节组成,这些字节用十六进制记数法表示并且用连字符隔开(比如,00-AA-00-4F-2A-9C)。

通过 -s 参数添加的项属于静态项,它们不会 ARP 缓存中超时。如果终止 TCP/IP 协议后再启动,这些项会被删除。要创建永久的静态 ARP 缓存项,请在批处理文件中使用适当的 arp 命令并通过“计划任务程序”在启动时运行该批处理文件。

只有当网际协议 (TCP/IP) 协议在 网络连接中安装为网络适配器属性的组件时,该命令才可用。 范例

要显示所有接口的 ARP 缓存表,可键入:

arp -a

对于指派的 IP 地址为 10.0.0.99 的接口,要显示其 ARP 缓存表,可键入:

arp -a -N 10.0.0.99

要添加将 IP 地址 10.0.0.80 解析成物理地址 00-AA-00-4F-2A-9C 的静态 ARP 缓存项,可键入:

arp -s 10.0.0.80 00-AA-00-4F-2A-9C

8. 禁止其他服务

防止syslogd网络监听

安装PHCO_21023补丁可以给syslogd加上-N参数防止网络监听. 编辑/sbin/init.d/syslogd修改为 /usr/sbin/syslogd -DN.

禁止SNMP服务

编辑SNMP启动文件:

/etc/rc.config.d/SnmpHpunix

Set SNMP_HPUNIX_START to 0: SNMP_HPUNIX_START=0 /etc/rc.config.d/SnmpMaster

Set SNMP_MASTER_START to 0: SNMP_MASTER_START=0 /etc/rc.config.d/SnmpMib2

Set SNMP_MIB2_START to 0: SNMP_MIB2_START=0 /etc/rc.config.d/SnmpTrpDst

Set SNMP_TRAPDEST_START to 0: SNMP_TRAPDEST_START=0

禁止sendmail进程

编辑/etc/rc.config.d/mailservs:

export SENDMAIL_SERVER=0

禁止rpcbind进程

# rm /sbin/rc1.d/K600nfs.core

# rm /sbin/rc2.d/S400nfs.core

# mv /usr/sbin/rpcbind /usr/sbin/rpcbind.DISABLE

六、其他命令

1. shutdown

shutdown 0 进入单用户模式,0表示立即执行,不用等待1分钟 shutdown –h 关机 shutdown –r 重新启动 shutdown –R 重新启动partition到BCH模式 shutdown –R -H 重新启动partition到BIB状态

2. init

init 3 进入多用户

3. swlist

显示系统所安装内容 例:

swlist –l fileset –a state|grep PHKL_18543 <查找PHKL_18543这个补丁是否安装>

4. tsm

启动多进程

console上按F1、F2来切换

仿真终端用ctrl_w切换窗口, ctrl_t显示菜单

5. mstm,stm,cstm 查看机器信息

6. lvlnboot

–v <查看启动路径>

lvlnboot -b /dev/vg00/lvol1 lvlnboot -s /dev/vg00/lvol2 lvlnboot -r /dev/vg00/lvol3 lvlnboot -d /dev/vg00/lvol2

7. setboot

设置机器是否自动启动及启动路径

setboot [-p primary-path] [-a alternate-path] [-b on|off] [-s on|off]

[-v] [-t testname=on|off|default]... [-T testname=on|off|default]... (none)

Display the current values for the primary and alternate boot paths and the autoboot and autosearch flags. See example 2 in the \

-p primary-path Set the primary boot path variable to primary-path. See ioscan(1M) for the correct format.

-a alternate-path Set the alternate boot path variable to alternate-path. See ioscan(1M) for the correct format.

-s on|off

Enable or disable the autosearch sequence. The

interpretation of Autoboot and Autosearch has changed for systems that support hardware partitions. Refer to the WARNINGS section. -b on|off

Enable or disable the autoboot sequence. The interpretation of Autoboot and Autosearch has changed for systems that

support hardware partitions. Refer to the WARNINGS section.

-v

Display the current values for the primary and alternate

boot paths and the autoboot and autosearch flags and a status table of the SpeedyBoot tests.

AutoBoot AutoSearch Boot Action

_______________________________________________________________________ off off Go to the BCH and prompt the user. on off Attempt the primary path; on failure go to BCH.

on on Attempt the primary path; on failure try next path.

off on Skip the primary path and try alternate path. If the alternate paths are not configured to boot or fail, go to BCH.

例:

1. Set the primary path to 2/4.1.0 and enable the autoboot sequence:

setboot -p 2/4.1.0 -b on

2. Display the boot paths and auto flags:

setboot

displays

Primary bootpath : 2/0/1.6.0 Alternate bootpath : 2/0/2.0.0 Autoboot is ON (enabled) Autosearch is ON (enabled)

8. mediainit

mediainit /dev/rdsk/cxtydz 对一个磁盘进行格式化和校验其完整性

9. swapinfo swapon

查看机器的一些信息 swapinfo –mt swapon

/etc/dmesg # Aufteilung des physischen Speichers (RAM) swapon [-e] swapon [-p ]

10.dmesg 查看MEMORY

11.top

top监控命令:

top监控工具可以显示CPU占用率为前几位的进程,并提供CPU的实时活动情况

语法:top [-s time] [-d count] [-q] [-u] [-h] [-n number] [-f filename] -s time 设置屏幕刷新的延时,单位为秒,默认值5秒

-d count 设置屏幕刷新的次数,刷新显示完count次后退出 -q 如果经过nice授权,使用-q可以使top运行的更快一些

-u 用显示User ID代替username,提高命令运行速度 -h 当系统由多个CPU时,个别CPU的状态信息被隐藏,只显 示平均状态值

-n number 设置每一屏幕显示的进程数目,number值超过进程最大数目,则设置无效 -f filename 输出重定向到给定的文件名,默认为16个进程信息 屏幕控制命令

当有多个屏幕内容显示时,可以用到下面的命令 键盘命令

j 如果不是最后的屏幕显示,按下j键可以切换到下一屏幕 k 如果不是最初的屏幕显示,按下k键可以切换到前一屏幕 t 按下k键可以切换到最初的屏幕

退出top命令的执行,可以在任何时候键入q键即可 显示信息描述

顺序显示下面三个常规的信息

1 系统信息:

System: pa1011 Tue Jun 1 22:15:56 2004 Load averages: 0.06, 0.04, 0.03

79 processes: 71 sleeping, 8 running Cpu states:

CPU LOAD USER NICE SYS IDLE BLOCK SWAIT INTR SSYS 0 0.11 6.2% 0.0% 3.4% 90.5% 0.0% 0.0% 0.0% 0.0% 1 0.01 5.2% 0.0% 4.4% 90.5% 0.0% 0.0% 0.0% 0.0%

--- ---- ----- ----- ----- ----- ----- ----- ----- ----- avg 0.06 -0.0% -0.0% -0.0% 100.0% -0.0% -0.0% -0.0% -0.0% 首部的几行显示系统的几个信息,其中包括: + system:系统名和当前日期.

+ Load averages:1分钟、5分钟和15分钟内运行的负载平均数 一般来说只要每个CPU的当前活动进程数不大于

3那么系统的性能就是良好的,如果每个CPU的任务数大于5,那么就表示这台机器的性能有严重问题

+ 最近一次更新时存在的套苁⒎直鹆谐鰎un(运行)、sleep(睡眠)、idle(停止)和zomb(‘僵尸’)状态的进程数

+ CPU state:用户占用时间的百分比、系统占用CPU时间的百分比、被nice命令改变优先级的任务占用的CPU时间百分比、以及CPU空闲时间的百分比。(被nice命令改变优先级的任务仅指那些nice值为负的任务)。花费在被nice命令改变优先级的任务上的时间也将被计算在系统和用户时间内,因此整个时间加起来可能会超过百分之百 + avg:活动进程的平均值 (仅当多处理器系统时列出).

2 内存信息

Memory: 610008K (24424K) real, 995344K (30304K) virtual, 12588K free Page# 1/4

Memory:关于内存使用情况的统计,包括实际(real)内存的活动值/总值,虚拟(virtual)内存的使用值/总值,剩余的内存。

3 进程信息

CPU TTY PID USERNAME PRI NI SIZE RES STATE TIME %WCPU %CPU COMMAND 1 ? 33 root 152 20 0K 0K run 153:43 1.18 1.18 vxfsd

0 ? 1751 root 154 20 2500K 868K sleep 2084:19 0.52 0.52 ARMServer 0 ? 1730 root 154 20 4500K 332K sleep 1664:55 0.44 0.44 acactmgr

列出系统里每一个处理器的信息,当信息在一个屏幕内无法显示时,会被分成多个屏幕显示,可以前面提到l,k和t命令查看

(1)CPU:处理器号(仅当多处理器系统时列出) (2)TTY:终端名 (3)PID:进程号

(4)USERNAME:用户名 (5)PRI:任务的优先级

(6)NICE:任务的nice值,一个具有较低值的进程在系统上将具有优先权。可以通过改变nice值提高某些进程速度,但是这实际上是一种交易,因为那些nice值被升高的进程此时将运行得很慢。

(7)SIZE:任务的代码加上数据再加上栈空间的大小。 (8)RES:任务使用的物理内存的总数量。 (9)STATE:任务的状态

(10)TIME:自任务开始时使用的总CPU时间,单位为秒,如153:43,对应是153秒43毫秒 (11)%WCPU:进程的CPU利用率权重百分比

(12)%CPU:进程的原始的CPU利用率百分比,自上一次屏幕刷新以来任务占用CPU 时间的份额

(13)COMMAND:启动进程的命令名。如果名字太长而不能在一行显示时,它将被截短

12.ioscan

列出各I/O卡及设备的所有相关信息:如逻辑单元号,硬件地址及设备文件名等。

ioscan –kfnCtape 查看磁带机 ioscan –kfnCfc 查看光纤卡>

ioscan –fnH0/0/1/0 查看0/0/1/0地址信息

13.info_col.11

收集机器信息,做安装报告用

info_col.1026 收集10.26版本信息>

14.dd

dd if=/dev/rdsk/cxtydo of=/dev/rdsk/cxtydo bs=1024k 整盘copy,if后面是旧盘,of后面是新盘

dd if=/dev/dsk/cxtydo of=/dev/dsk/cxtydo bs=1024k

15.sar

sar [options] [-A] [-o file] t [n]

在命令行中,n 和t 两个参数组合起来定义采样间隔和次数,t为采样间隔,是必须有的参数,n为采样次数,是可选的,默认值是1,-o file表示将命令结果以二进制格式 存放在文件中,file 在此处不是关键字,是文件名。options 为命令行选项,sar命令 的选项很多,下面只列出常用选项:

-A:所有报告的总和。 -u:CPU利用率

-v:进程、I节点、文件和锁表状态。 -d:硬盘使用报告。

-r:没有使用的内存页面和硬盘块。 -g:串口I/O的情况。 -b:缓冲区使用情况。 -a:文件读写情况。 -c:系统调用情况。 -R:进程的活动情况。 -y:终端设备活动情况。

-w:系统交换活动。

例如:#sar –u 3 30 (每隔3秒采样一次,共采样30次)

在业务高峰期使用sar –u命令

? %usr = time spent in user mode ? %sys=time spent in system mode

? %wio=time spent in block, raw, and virtual memory management I/O ? %idle=CPU time not being used

? sar -uM: option for multiprocessor platforms.

首先应看%idle是否接近于0. 如果是,那么看%wio是否大7. 如果%wio大于7,可能需要考虑是否有IO瓶颈。

如果%wio很小,但CPU依然很忙,要看一下%usr与%sys的比率。如果%usr很高,则可能说明用户的应用程序造成CPU瓶颈。 如果大部分时间被%sys占用,需要进一步分析为什么系统会占用这么多时间。比如说内存的瓶颈,造成操作系统

频繁的做swapping操作,就是一个可能的原因。

对于一个典型的系统,通常的建议值是:

%usr %sys %wio %idle 60 25 0 15

#sar –d 5 5

参考blks/s,512byte

avque(The average number of I/O requests in the queue for that disk)为0.5最好,在操作系统里等待,可参见Kmine资料

avwait(The average amount of time a request spends waiting in that disk’s queue),与avque成正比,理想是avwait

device: sar命令正在监视的块设备的名字。

%busy: 设备忙时,传送请求所占时间的百分比。 avque: 队列站满时,未完成请求数量的平均值。 r+w/s: 每秒传送到设备或从设备传出的数据量。 blks/s: 每秒传送的块数,每块512字节。

avwait: 队列占满时传送请求等待队列空闲的平均时间。 avserv: 完成传送请求所需平均时间(毫秒)。 #sar –u //CPU Utilization(usr,sys,wio,idle) #sar –q //Queue lengths/utilization(run, swap) 例如:#sar –q 3 5 看CPU运行队列

#sar –M //Above information in per-processor format #sar –c //System calls

系统response time = avwait + avserv (毫秒)

在显示的内容中,%busy的值比较小,说明用于处理传送请求的有效时间太少,文件系统效率不高,一般来讲,%busy值高些,avque值低些,文件系统的效率比较高,如果%busy和avque值相对比较高,说明硬盘传输速度太慢,需调整。

16. uname

uname –a 列出系统ID 号,OS版本及用户权限等信息。

17. hostname 列出系统名称

18.Esc键

在命令行中可通过击两次Esc键来匹配当前目录中唯一的文件名,这样可节约击入长文件名的时间

19.col

man cp | col –b >cp.txt

该命令可将cp命令的联机帮助手册输出为名为cp.txt的文本文件

20. which

查看某命令的绝对路径 which 命令名

21. 中文环境的配置

a、 查看系统中安装的语言集(locale –a) b、 显示当前语言环境变量(echo $LANG)

c、 如不为中文则修改(export LANG=zh_CN.hp15CN) d、 sty –istrip

21.who

22.what

假如要查看某一core文件的诱因 what core

23.finger

finger –R(查看当前登录到主机的客户机信息)

24.find

find命令是功能最强的命令之一,但同时也是命令行结构最难以掌握的命令之一。

# find / -print | wc -l 显示系统中所有文件和目录的数目。 # find / -user $LOGNAME -print 显示系统中该用户所有文件和目录。

# find / -size 100 -print 显示文件大小为100 blocks。

# find / -size -100 -print 显示文件大小小于100 blocks 。 # find / -size +100 -print 显示文件大小大于100 blocks 。 # find / -name core -exec rm {} \\;查找并删除core文件。 # find . -exec chown $LOGNAME {} \\; 修改一个目录下的所有文件的用户所属。

# find .-type d -exec chmod 770 {} \\;修改一个目录下的所有目录的权限。 Purge core files:

# find / -name core -exec rm -i {} \\; Purge large, old files:

# find / -atime +30 -size +1000c -exec ll -ud {} \\;

25.fuser

fuser [-c|-f] [-ku] file ... [[-] [-c|-f] [-ku] file ...] ... 显示使用某个文件的进程

-c Display the use of a mount point and any file beneath that mount point. Each file must be a file system mount point.

-f Display the use of the named file only, not the files beneath it if it is a mounted file system.

-u Display the login user name in parentheses following each process ID.

-k Send the SIGKILL signal to each process using each file. 例:

Terminate all processes that are preventing disk drive 1 from being

unmounted, listing the process ID and login name of each process being killed.

fuser -ku /dev/dsk/c201d1s?

List process IDs and login names of processes that have the password file open.

fuser -u /etc/passwd

Combine both the above examples into a single command line.

fuser -ku /dev/dsk/c201d1s? - -u /etc/passwd

If the device /dev/dsk/c201d1s7 is mounted on directory /home, list the process IDs and login names of processes using the device.

Alternately, if /home is the mount point for an NFS file system, list process IDs and login names of processes using that NFS file system.

fuser -cu /home

If machine1:/filesystem/2mount is an NFS file system, list all processes using any file on that file system. If it is not an NFS file system, treat it as a regular file.

fuser machine1:/filesystem/2mount

26. Whereis:

搜索命名所在的位置

UNIX stores its commands in four main directories: /sbin , /usr/bin, /usr/local/bin, and/usr/contrib/bin.

-b bin类型 -m manpage -s source

27. tail 和 head

使用tail命令可以查看文件的尾部,head命令则查看文件的头部。 # tail filename

# tail -f filename; 使tail不断执行,当文件被写入时显示文件的新行。 #head filename

28. date 和 cal

cal命令显示日历。 # cal 2000 # cal 1 2000

29. stty

该命令用于检查和修改用户当前注册终端的通信参数。 # stty -a;查看当前注册终端的通信参数。 # stty -ixon;设置ixon为off。 #stty ixon;设置ixon为on。

# stty sane;当终端发生混乱时,通常可以产生有益的效果。

30. tset

用于设置终端类型。 tset -s -Q -m ‘:?hp’

31. cron

cron(chronography,计时),每分钟苏醒一次,查看控制文件以确定当时是否存在应运行的作业,存在则运行之。

# crontab filename ; 创建一个 cron # crontab -r ; 把cron从crontab去掉

crontab位于目录/var/spool/cron/crontabs下,每个用户的cron文件名是其用户名。 32. sort

sort listfile: 按字母顺序对listfile 进行排序 33. compress

compress filename: 压缩文件

34. uncompress

uncompress filename: 解压缩文件

35. set

set -o editor_name: 设置命令行编辑器 36. raq

-d 检查机器所包含的pci等设备

37. tsconvert

转换为一个可信系统:

Creating secure password database...

Directories created.

Making default files.

System default file created...

Terminal default file created...

Device assignment file created...

Moving passwords...

secure password database installed.

Converting at and crontab jobs...

At and crontab files converted.

38. getprivgrp

改变全局特权

HP-UX 有一个特权组,可以分配给一个组特权(参见privgrp(4)). 缺省情况下,CHOWN是分配给所有组的一个全局特权:

$ getprivgrp

global privileges: CHOWN

/sbin/init.d/set_prvgrp在系统启动时执行/usr/sbin/setprivgrp -f /etc /privgroup. 可以创建一个配置文件,删除所有的全局特权 (see setprivgrp(1m)):

# getprivgrp

global privileges: CHOWN

# echo -n >/etc/privgroup

# chmod 400 /etc/privgroup

# /sbin/init.d/set_prvgrp start

# getprivgrp

global privileges:

40. lsof

可以使用lsof –i来查看监听进程和端口信息:

# lsof -i

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

syslogd 261 root 5u inet 0x10191e868 0t0 UDP *:syslog (Idle)

rpcbind 345 root 4u inet 72,0x73 0t0 UDP *:portmap (Idle)

rpcbind 345 root 6u inet 72,0x73 0t0 UDP *:49158 (Idle)

rpcbind 345 root 7u inet 72,0x72 0t0 TCP *:portmap (LISTEN)

sendmail: 397 root 5u inet 0x10222b668 0t0 TCP *:smtp (LISTEN)

snmpdm 402 root 3u inet 0x10221a268 0t0 TCP *:7161 (LISTEN)

snmpdm 402 root 5u inet 0x10222a268 0t0 UDP *:snmp (Idle)

snmpdm 402 root 6u inet 0x10221f868 0t0 UDP *:* (Unbound)

mib2agt 421 root 0u inet 0x10223e868 0t0 UDP *:* (Unbound)

swagentd 453 root 6u inet 0x1019d3268 0t0 UDP *:2121 (Idle)

41. print_manifest

收集系统信息,类似于info_collect

诊断工具

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

rtprio priority command (e.g. rtprio 100 a.out). Change the priority to the real-time process.

nice –10 command : lower priority by 10, nice -- 10 command: increase priority by 10 renice –n10 command: change the niceness of the existing command (lower prio. By 10) tunefs –v /dev/rdsk/c0t9d0 : display the filesystem superblock informaion on disk 9 tunefs –e 999 /dev/rdsk/c0t9d0: turns off maximum blocks per group to favor the large file.

sar –u 1 10: reports the cpu usage every second for total of 10 seconds.

sar –d 1 10: reports the disk usage. If \%busy > 50\avwait > avserv\bottleneck.

sar –b : Buffer cache activity. If the \%rcache <90\%wcache < 70\problem.

sar –w: Swapping activity. # of processes and # of 512byte blocks swap in and out.

Swapin includes both demand paging and swap-in’s. swpot /s should be zero. Otherwise, there is a memory shortage.

sar –q : Run queue and swap queue length. Problem when \runq-sz > 4\swpocc > 5\

sar –c : # of system calls

sar –v: file table, process table and inode table usage. sysdef : list out all the kernel parameters set.

iostat –t 5 10: iostat uses 1024-byte block. It reports the cpu, terminal and disk statistics. vmstat options 5 10: memory, swap(-S option), disk (-d option), etc. activities. vmstat –s : cumulative data after reboot

glance : a really powerful and fully supported performance tool.

chmod 1xxx myprogram : Set the \text page back to server in NFS situation. Or on client side, you could set page_text_to_local =1

? ? ? ? ? ? ?

time command : reports the user, sys, real elapsed time. ps options: list out the processes information

scsictl –a /dev/rdsk/c0t9d0: check the setting of a SCSI device. top : list out all processes by cpu usage size : prints section sizes of object files

fuser file : list out the PIDs of the processes using specified files or block file devices. uptime : list out the average cpu load

七、vi的命令

vi filename :打开或新建文件,并将光标置于第一行首 vi +n filename :打开文件,并将光标置于第n行首 vi + filename :打开文件,并将光标置于最后一行首

vi +/pattern filename:打开文件,并将光标置于第一个与pattern匹配的串处 vi -r filename :在上次正用vi编辑时发生系统崩溃,恢复filename vi filename....filename :打开多个文件,依次进行编辑

1. 移动光标类命令[/b]

h :光标左移一个字符 l :光标右移一个字符 space:光标右移一个字符

Backspace:光标左移一个字符 k或Ctrl+p:光标上移一行 j或Ctrl+n :光标下移一行 Enter :光标下移一行

w或W :光标右移一个字至字首 b或B :光标左移一个字至字首 e或E :光标右移一个字至字尾 ) :光标移至句尾 ( :光标移至句首 }:光标移至段落开头 {:光标移至段落结尾 nG:光标移至第n行首 n+:光标下移n行 n-:光标上移n行

n$:光标移至第n行尾 H :光标移至屏幕顶行 M :光标移至屏幕中间行 L :光标移至屏幕最后行

0:(注意是数字零)光标移至当前行首

$:光标移至当前行尾

2. 屏幕翻滚类命令

Ctrl+u:向文件首翻半屏 Ctrl+d:向文件尾翻半屏 Ctrl+f:向文件尾翻一屏 Ctrl+b;向文件首翻一屏

nz:将第n行滚至屏幕顶部,不指定n时将当前行滚至屏幕顶部。

3. 插入文本类命令

i :在光标前 I :在当前行首 a:光标后

A:在当前行尾

o:在当前行之下新开一行 O:在当前行之上新开一行 r:替换当前字符

R:替换当前字符及其后的字符,直至按ESC键

s:从当前光标位置处开始,以输入的文本替代指定数目的字符 S:删除指定数目的行,并以所输入文本代替之 ncw或nCW:修改指定数目的字 nCC:修改指定数目的行

4. 删除命令

ndw或ndW:删除光标处开始及其后的n-1个字 do:删至行首 d$:删至行尾

ndd:删除当前行及其后n-1行

x或X:删除一个字符,x删除光标后的,而X删除光标前的 Ctrl+u:删除输入方式下所输入的文本

5. 搜索及替换命令

/pattern:从光标开始处向文件尾搜索pattern ?pattern:从光标开始处向文件首搜索pattern n:在同一方向重复上一次搜索命令 N:在反方向上重复上一次搜索命令

:s/p1/p2/g:将当前行中所有p1均用p2替代

:n1,n2s/p1/p2/g:将第n1至n2行中所有p1均用p2替代 :g/p1/s//p2/g:将文件中所有p1均用p2替换

6. 选项设置

all:列出所有选项设置情况 term:设置终端类型

ignorance:在搜索中忽略大小写

list:显示制表位(Ctrl+I)和行尾标志($) number:显示行号

report:显示由面向行的命令修改过的数目 terse:显示简短的警告信息

warn:在转到别的文件时若没保存当前文件则显示NO write信息 nomagic:允许在搜索模式中,使用前面不带“\\”的特殊字符 nowrapscan:禁止vi在搜索到达文件两端时,又从另一端开始 mesg:允许vi显示其他用户用write写到自己终端上的信息

7. 最后行方式命令

:n1,n2 co n3:将n1行到n2行之间的内容拷贝到第n3行下 :n1,n2 m n3:将n1行到n2行之间的内容移至到第n3行下 :n1,n2 d :将n1行到n2行之间的内容删除 :w :保存当前文件

:e filename:打开文件filename进行编辑 :x:保存当前文件并退出 :q:退出vi

:q!:不保存文件并退出vi

:!command:执行shell命令command

:n1,n2 w!command:将文件中n1行至n2行的内容作为command的输入并执行

之,若不指定n1,n2,则表示将整个文件内容作为command的输入

:r!command:将命令command的输出结果放到当前行

8. 寄存器操作

\:将当前行及其下n行的内容保存到寄存器?中,其中?为一个字母,n为一 个数字

\:将当前行及其下n个字保存到寄存器?中,其中?为一个字母,n为一个数 字

\:将当前行及其下n个字符保存到寄存器?中,其中?为一个字母,n为一个 数字

\:取出寄存器?中的内容并将其放到光标位置处。这里?可以是一个字母,也 可以是一个数字

ndd:将当前行及其下共n行文本删除,并将所删内容放到1号删除寄存器中。

八、管道、变量

1. 变量的引用

filename arg1 arg2?

文件中对应引用变量为$1 $2, $0为文件名本身.

${10}为第10变量,不能写成$10,{}为界定符,将其和其他字符分割开来。 $* 为所有的变量,包括arg1 arg2 ?, $# 为所引用的变量的个数 2. shift

shift 2 表示将所带的参数左移两个,如 filename arg1 arg2 arg3 arg4 执行sift2以后,只剩下arg3 arg4两个参数了,$1对应的值为arg3 3. read

read arg1 arg2 在程序中执行到此后,等待用户输入参数的值,并相应的赋给arg1 arg2 4. sh

sh –x filename arg -x 参数提供DEBUG功能,显示程序执行过程中的每一步。

5. 局部及全局变量

局部变量:一个程序被执行时,系统sh创建一个子进程,当程序完成后子进程被杀掉,其内定义的变量也随之被杀掉,此变量为局部变量,同时父进程也看不见子进程内的变量,子进程也看不见父进程的局部变量。

全局(环境)变量,一直在系统中,不会因为进程杀掉而杀掉,同时子进程也可以看见此全局变量,用export创立。也可以用export 将局部变量转换成全局变量。例如:$ color=lavender $ export color export不加参数显示当前系统所有的全局变量。

如果全局变量的值在子程序中被重新赋值,当退出子程序时,全局变量的值变成原来的值。例如export color=gree ; 运行ksh,重新赋值color=red, echo $color 为green, exit后,color 的值仍为green

6. 环境变量:

TERM, COLUMNS, and

LINES HOME PATH LOGNAME

Describe the terminal you are using

Path name to your home directory List of places to find commands User name you used to log in

ENV and HISTFILE DISPLAY

Special POSIX shell variables Special X Window variable

例:$env

MANPATH=/usr/share/man/%L:/usr/share/man:/usr/contrib/man/%L:/usr/contrib/man:/n

PATH=/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/contrib/bin:/opt/nettladm/bin:/opt/fct

COLUMNS=80 EDITOR=vi LOGNAME=root

MAIL=/var/mail/root ERASE=^H

PS1=hpd220#[$PWD] SHELL=/sbin/sh HOME=/

TERM=vt220 PWD=/

TZ=MST7MDT LINES=24

给环境变量赋值:例

EDITOR=/usr/bin/vi use vi commands for line editing ENV=$HOME/.kshrc execute $HOME/.kshrc at shell startup FCEDIT=/usr/bin/vi start vi edit session on previous command lines HOME=/home/user3 designates your login directory ~ (tilde) POSIX shell equivalent for your HOME directory HISTFILE=$HOME/ defines file that stores all interactive commands entered .sh_history

LOGNAME=user3 designates your login identifier or user name MAIL=/var/mail/user3 designates your system mailbox OLDPWD=/tmp designates previous directory location

PATH=/usr/bin:$HOME/bin designates directories to search for commands

PS1= designates your primary prompt PS1= ’[!] $ ’ displays command line number with

prompt

PS1=’$PWD $ ’ displays present working directory

with prompt (NOTE: must be enclosed in single quotes( ’), not

double quotes (\)) PS1=’[!]$PWD$ ’ displays command line number and

present working directory with prompt

PWD=/home/user3/tree designates your present working directory SHELL=/usr/bin/sh designates your command interpreter program TERM=2392a designates the terminal type of your terminal use the command:

eval ‘tset -s -Q -h‘ During startup, this will read the file /etc/ttytype to map your terminal port with the appropriate terminal type. This is useful if you have different models of terminals attached to your system.

TMOUT=300 If no command or Return is entered in this number of

seconds, the shell will terminate or time out.

TZ=EST5EDT Defines the time zone the system should use to display

appropriate time

/usr/bin/X11/xclock -display 192.10.25.54:0

export DISPLAY=15.41.255.40:0.0

7. what happened at login

1. getty

a. Displays the contents of /etc/issue b. Issues the login prompt c. Runs login 2. login

a. Validates user name and password b. Places user in home directory c. Runs the user’s shell 3. shell

a. Executes /etc/profile (POSIX, Bourne, and Korn shells) or /etc/csh.login (C shell)

b. Executes .profile or .login in the user’s home directory

c. Executes .kshrc in the user’s home directory (POSIX and Korn shells) if the user has created this file and if he has declared the ENV variable set to .kshrc in the .profile file d. Issues the shell prompt

/etc/profile设置基本的环境变量,/home/.profile设置特定变量

If you are logging in with CDE, login profile scripts /etc/profile, $HOME/.profile, and

$HOME/.login are normally not used by CDE. You may, however, force $HOME/.profile (for sh or ksh users) or $HOME/.login (for csh users) to be run by setting the following environment variable in .dtprofile:

DTSOURCEPROFILE=true

Otherwise, only .dtprofile will be executed at login. .dtprofile contains commented lines of setup variables you need to set the CDE environment.

8. $()

命令替换:$(command),等同于`command`, 9. $

变量替换:$变量名,注意界定符{}的使用

10. 管道

grep user /etc/passwd | sort > sorted.users

# grep –i error syslog.log <快速查看syslong.log内的错误> # grep –i ―war|err|fail|scsi|lan‖ /dev/adm/syslog/syslog.log

# cat zhao.conf(显示我们所查文件的内容) 48 Dec 3BC1997 LPSX 68.00 LVX2A 138

483 Sept 5AP1996 USP 65.00 LVX2C 189 47 Oct 3ZL1998 LPSX 43.00 KVM9D 512 219 dec 2CC1999 CAD 23.00 PLV2C 68 484 nov 7PL1996 CAD 49.00 PLV2C 234 487 may 5PA1998 USP 37.00 KVM9D 644 471 May 7Zh1999 UDP 37.00 KV30D 643

# grep -c \(统计所有以“48”字符开头的行有多少) # grep -i \(不区分大小写查找有“May”所有的行) 487 may 5PA1998 USP 37.00 KVM9D 644 471 May 7Zh1999 UDP 37.00 KV30D 643

# grep -n \(显示行号;显示匹配字符“48”所在的行的行号)

# grep -v \(显示输出没有字符“48”所有的行)

# grep \(显示输出字符“471”所在的行)

# grep \(精确显示输出字符“48”所在的行)

# grep \(显示输出以字符“48”开头,并在字符“48”后是一个tab键所在的行 注:tab键,安一下tab键即可;和精确显示输出的结果是相同的) 48 Dec 3BC1997 LPSX 68.00 LVX2A 138

# grep \(显示输出以字符“48”开头,第三个字符是“3”或是“4”的所有的行)

# grep '48[34]' zhao.conf(注意使用单引号(‘’)和使用双引号(“”)在Solaris8中输出的结果是一样的;

即:单引号、和双引号是通用的,只要你养成一种习惯就好) 483 Sept 5AP1996 USP 65.00 LVX2C 189 484 nov 7PL1996 CAD 49.00 PLV2C 234

# grep \(显示输出行首不是字符“48”的行) 219 dec 2CC1999 CAD 23.00 PLV2C 68

# grep \(设置大小写查找:显示输出第一个字符以“M”或“m”开头,以字符“ay”结束的行)

487 may 5PA1998 USP 37.00 KVM9D 644 471 May 7Zh1999 UDP 37.00 KV30D 643

# cat zhao.conf(再次显示我们所使用的文件的内容) 48 Dec 3BC1997 LPSX 68.00 LVX2A 138 483 Sept 5AP1996 USP 65.00 LVX2C 189 47 Oct 3ZL1998 LPSX 43.00 KVM9D 512 219 dec 2CC1999 CAD 23.00 PLV2C 68 484 nov 7PL1996 CAD 49.00 PLV2C 234 487 may 5PA1998 USP 37.00 KVM9D 644 471 May 7Zh1999 UDP 37.00 KV30D 643

# grep \(显示输出第一个字符是“K”,第二、三、四是任意字符,第五个字符是“D”所在的行)

47 Oct 3ZL1998 LPSX 43.00 KVM9D 512 487 may 5PA1998 USP 37.00 KVM9D 644 471 May 7Zh1999 UDP 37.00 KV30D 643

# grep \(显示输出第一个字符的范围是“A-D”,第二个字符的范围是“A-D”,

第三个字符的范围是“A-D”,第四个字符是“9”,第五个字符的是“D”,所有的行:已知所查字符串的长

度为5位)

47 Oct 3ZL1998 LPSX 43.00 KVM9D 512 487 may 5PA1998 USP 37.00 KVM9D 644 # grep \

487 may 5PA1998 USP 37.00 KVM9D 644

# grep \(显示输出第一个字符是“3”或“5”,第二、三个字符是任意,以1998结尾的所

有行;已知所查字符串的长度是7位) 47 Oct 3ZL1998 LPSX 43.00 KVM9D 512 487 may 5PA1998 USP 37.00 KVM9D 644

# grep \(模式出现几率查找:显示输出字符“4”至少重复出现两次的所有行) 487 may 5PA1998 USP 37.00 KVM9D 644

# grep \(模式出现几率查找:显示输出字符“9”至少重复出现三次的所有行) 219 dec 2CC1999 CAD 23.00 PLV2C 68 471 May 7Zh1999 UDP 37.00 KV30D 643

# grep \(模式出现几率查找:显示输出字符“9”重复出现的次数在一定范围内(重复出现2

次或3次)所有行)

48 Dec 3BC1997 LPSX 68.00 LVX2A 138 483 Sept 5AP1996 USP 65.00 LVX2C 189 47 Oct 3ZL1998 LPSX 43.00 KVM9D 512 219 dec 2CC1999 CAD 23.00 PLV2C 68 484 nov 7PL1996 CAD 49.00 PLV2C 234 487 may 5PA1998 USP 37.00 KVM9D 644 471 May 7Zh1999 UDP 37.00 KV30D 643

# grep -n \(显示输出空行的行号)

九、进程:

1. ps 显示机器上运行的进程

不加参数: 只显示终端上运行的进程

-e 显示机器上所有的进程,不光包括自己的 -f –l 显示详细信息。 2. &

放在命令行后面用于将命令放在后台,经常配和>使用,否则当有结果输出时,结果仍然会显示在屏幕上。例:find / -name zj.tar>find.out &

3. jobs

fg %pid (%strings) bg %pid (%strings) 将进程放入前台或后台

4. nohup

nohup command line & 挂起一个进程,如果程序没有执行完,即使用户退出系统后,重新进入时进程仍在。 5. Nice

Nice n commandline 按照优先级n启动一条命令 6. Kill

Kill pid

Kill –9 pid 强制停止进程

7. 子程序的运行过程:

When you log in to your UNIX system, the shell program will be loaded, and a shell process executed. When you enter the name of an application (or command) to run at the shell prompt, a child process is created and executed through:

1. A fork which duplicates your shell process, including the program code, the environment data space, and the local data space.

2. An exec which replaces the code and local data space of the child process with the code and local data space of the requested application.

3. The exec will conclude by executing the requested application process.

While the child process is executing, the shell (the parent) will sleep, waiting for the child to finish. Once the child finishes execution, it terminates, releases the memory associated with its process, and wakes up the parent who is now ready to accept another command request. You know the child process has concluded when the shell prompt returns.

十、脚本编辑

1. test:测试命令结果,

例:x=abc

test \或[ “$x” = abc ]

注意如果x没有被付过值 “”则可以不用 $ X=\

$ [ $X = yes ] 也不对,要加””,否则便成了Yes we will=yes

echo $?(返回上次命令的逻辑值,成功为0,不成功为非0)

2. 运算符:

算术运算:

lt (less than) le(less or equal) eq gt ge(great or equal) ne(not equal)

字符运算:

= != -z(是否为空,为空返回TRUE) -n(是否不为空) string 不为空返回TRUE 3. 赋值语句:

let 例:x=10 let x=x+2 等同于((x=x+2)) 或 x=?expr $x + 1? 在赋值语句中可用

Operator Description - Unary minus ! Logical negation

* / % Multiplication, division, remainder + - Addition, subtraction

<= >= < > Relational comparison == != Equals, does not equal = Assignment

返回的值可用在循环判断语句中 4. 判断语句

if if if If list a List List then then Then list b List List else fi Elif list c List fi Then 执行 list a 命令,如 List 果返回值为0(true),执Else 行 list b,否则执行 List list c Fi 等价于: If List Then List Else if List Then List Else List Fi Fi Case:

例: case \red) echo apple ;; yellow) echo banana ;; orange) echo kumquat ;; *) echo vegetable! ;; esac 例二: echo command menu echo d display date echo n display hostname echo l display contend echo please input your choice: read choice case $choice in [dD]*) date;; [nN]*) hostname;; [lL]*) ls;; *) echo invalid input.;; esac 5. 循环语句

do while done 或 while do done 例: $ X=1 $ while [ $X -le 10 ] > do > echo hello X is $X > let X=X+1 > done X=1 while ((X <= 200 )) do ... let X=X+1 done #!/usr/bin/sh

# sum_them: Prompt the user for 10 numbers and add them together #

sum=0 count=1

echo You will be prompted to enter 10 numbers.

echo Their sum will be displayed after all 10 numbers have been entered. while

[ $count -le 10 ] do

echo \read num

let sum=sum+num let count=count+1 done

echo The sum of the 10 numbers you entered is: $sum

untile do done

例:

$ X=1 $ until > [ $X -eq 0 ] > do > echo hello > done hello hello . . . $ X=1 $ until > [ $X -eq 0 ] > do > echo hello > done hello hello . . . #!/usr/bin/sh # ison: Check for a user to log into the system # Usage: ison username # if [ \then echo %user_id\exit 99 fi until who | grep $1 > /dev/null do sleep 60 done # When you reach this point, the user has logged in echo $1 has logged on who | grep $1

until

[ $ans -eq 3 ] clear echo echo echo

echo 1) Double a number.

echo 2) Add together 10 numbers. echo 3) Quit echo

echo \read ans do

case $ans in 1) double_it ;;

2) sum_them ;;

3|quit|q|Q) exit ;;

*) echo You have not entered a legal option. echo Please try again. ;; esac sleep 3

screen clears before displaying menu done

for do done 例: for i in $(lsf | grep for file in * / | cut -d/ -f1) do do size=$(wc -c $file | for name in A B C D E do mkdir ${name}dir

本文来源:https://www.bwwdw.com/article/lp6x.html

Top