---
title: "Solaris/Linux 命令行 简单手册"
author: "吃猫的鱼"
date: "2011-12-06T15:49:38Z"
tags: []
categories: ["操作系统"]
slug: "solaris-linux"
draft: false
lastmod: "2011-12-06T15:49:38Z"
id: 1294121
url: "https://superyang0804.iteye.com/blog/1294121"
---

1. 系统
# passwd：修改口令
# exit：退出系统

2. 文件
# cp：复制文件或目录，参数：-a递归目录，-i覆盖确认
# mv：改名移动
# rm：删除，参数：-r递归删除

3. 目录
# mkdir：创建目录
# rmdir：删除空目录
# cd：改变工作目录
# pwd：查看当前路径
# ls：列目录，参数：-a所有文件，-c按时间排序，-l详细信息

4. 文本
# sort：排序
# uniq：删除重复行

5. 备份压缩
# tar：档案，参数：-c创建新档案，-r追加到末尾，-t列出档案内容，-u更新文件，-x释放文件，-f使用档案文件或设备，-M多卷，-v详细报告，-w每步确认。例tar cvf text.tar *.txt
# gzip：压缩解压缩，参数：-d解压，-r递归压缩
# unzip：解压缩，参数：-d目录，-x解压缩

6. 权限
# chmod：改变权限，r可读，w可写，x可执行。0表示没有权限，1表示可执行权限，2表示可写权限，4表示可读权限，然后将其相加。例如，如果想让某个文件的属主有“读/写”二种权限，需要把4（可读）+2（可写）＝6（读/写）。
# chgrp：改变所属用户组
# chown：改变属主

7. 管理
# wall：发送信息到全部登录用户
# write：向某个用户发送信息
# mesg y：设定允许别人给自己发送信息
# sync：缓存同步校验
# shutdown：关机，参数：-r重启，-h关机不重启，-f快速关机，-c取消关机
# free：查看内存
# uptime：显示系统运行时间
# df：磁盘占用空间，参数：-a显示所有文件系统
# du：磁盘使用情况
# dd：拷贝并格式转换
# fdformat：低格软盘
# echo：显示文字
# cal：日历
# date：系统日期和时间
# clear：清屏

8. 我的回忆 by tom2sun
# who：查看当前用户
# finger：查看其他用户信息
# rlogin：远程登录
# rcp：远程复制
# netstat：网络状态
# cat：一次完全显示
# more：分屏显示
# file：列出文件类型
# grep：查找内容
# find：查找文件
# ps：当前运行程序，参数-a显示所有进程
# at：时间，命令，Ctrl+D结束
# lp：打印
# nice：指定优先级
# renice：调整优先级
# kill：终止进程
# man：获取命令帮助
# touch：改变时间记录
# ln：链接
# mount -t vfat /dev/hda1 /mnt/dos：挂载Dos分区(不适用于Unix-Center)

9. FTP
# ftp：启动FTP程序
ftp>
open：打开
close：关闭
bye：离开
get：下载
put：上传
mget/mput：多个文件下载/上传
reget：恢复下载
binary：二进制传送文件
ascii：ASCII码传送
cd：改变远程目录
lcd：改变本地目录
mkdir：建目录
rmdir：删除目录
delete：删除文件
mdelete：一次删除多个
rename：重命名
status：显示状态
prompt：交互式
hash：每传送1024字节显示#（hash）
size：显示文件大小
reset：重置

10. vi
a,i：进入输入状态
ESC：返回命令状态
:命令模式
Q!：退出

11. 快键及其他
Alt+F1~F6：访问多个虚拟控制台(不适用于Unix-Center)
Tab：命令补全
末尾&：后台进程

—————————————-

硬件系统：

1、如何查看cpu的状态？
# psrinfo -v
# mpstat     可以列出多cpu负载的状态

2、如何查看内存？
# prtconf | grep ‘Memory’ 可以查看内存的多少.
# /usr/platform/sun4u/sbin/prtdiag

3、如何动态添加swap分区？ # $su － root                                  —–  成为超级用户
# mkfile 100m /home/swapfile         —–  创建100m的Swap文件
# /usr/sbin/swap －a /path/filename  —–  激活Swap文件
# /usr/sbin/swap －l                 —–  验证swap文件
# /usr/sbin/swap －d /path/filename  —–  取消swap文件
# rm -rf /home/swapfile              —–  删除swap文件

4、如何查看当前网卡是以何种速率起来的？
# dmesg |grep Link

5、如何调整x-window的分辨率和刷新频率？
字符界面登陆，运行：#/kdmconfig

6、如何使用光、软驱？
一般情况下用：
# /etc/init.d/volmgt start
# volcheck
以上方法不行，用：
# /etc/init.d/volmgt stop
# mount -F hsfs -o ro /dev/dsk/c0t6d0s0 /cdrom –挂接光驱
# mount -F pcfs /dev/diskette0 /floppy         –挂接软驱
solaris定义系统磁盘文件系统说明：
ufs – UNIX文件系统。是Solaris缺省的文件系统。
hsfs – 高密度CD-ROM文件系统，是只读文件系统。
pcfs – PC文件系统，支持DOS格式化的软盘

7、SCSI设备的命名规则是什么？
带有总线控制器的硬盘的使用，下面列出了总线控制器的硬盘命名习惯：
cWtXdYsZ
c Logical controller number
t Physical bus target number
d Drive number
s Slice (or partition) number (0 to 7)
例如：
/dev/rdsk/c0t0d0s0 该原始接口对应第一个控制器的第一个SCSI目标地址的第一个硬盘的第一片(根)
/dev/rdsk/c0t0d0s2 该原始接口对应第一个控制器的第一个SCSI目标地址上的第一个硬盘的第三片(表示整上硬盘)

8、如何查看硬盘的使用情况？
# df -k      可以看到已安装的文件系统的空间大小及剩余空间大小。
# quota -v       查看用户的磁盘空间信息,如果你用quota限制了用户空间大小的话。
# du -sk *   查看目录的使用情况
# du -k | sort -n  可以迅速发现那个目录是最大的。

9、如何查看硬盘物理信息？
# format       这个命令也可以查看硬盘的类型和分区的详细情况
# iostat -E看硬盘的大小和型号
# prtvtoc /dev/rdsk/c0t0d0s0   显示某个磁盘的分区状况

10、查看系统内核命令。
# isainfo        看内核的bit,
# isainfo -kv      调整内核
# modinfo          显示可载入的模组
# prtconf          显示系统硬件配置（周边设备）
#sysdef           显示可载入的模组，硬件配置与一些可以调整的核心参考值
#ulimit -a

11、打印当前的OBP版本号
# prtconf –V
OBP 3.20.0 2000/10/24 10:47
# /usr/platform/sun4u/sbin/prtdiag –v | grep OBP
OBP 3.20.0 2000/10/24 10:47 POST 6.1.0 2000/10/24 10:49
ok. .version
Release 3.20 Version 0 created 2000/10/24 10:47
OBP 3.20.0 2000/10/24 10:47
POST 6.1.0 2000/10/24 10:49
OBDIAG 4.5.1 2000/10/24 10:48

12、查看及启动系统的32位或64位内核模式
64位模式
# isalist –v
sparcv9+vis sparcv9 sparcv8plus+vis sparcv8plus sparcv8 sparcv8-fsmuld sparcv7 sparc
# isainfo –v
64-bit sparcv9 applications
32-bit sparc applications
# isainfo –b
64
启动64位内核模式
ok. boot kernel/sparcv9/unix

32位模式
# isalist –v
sparcv8plus+vis sparcv8plus sparcv8 sparcv8-fsmuld sparcv7 sparc
# isainfo –v
32-bit sparc applications
# isainfo –b
32
启动32位模式
ok. boot kernel/unix

13、测定当前的显示器刷新频率
# /usr/sbin/fbconfig –rev \?

14、如何配置网卡ip？
# ifconfig -a             –查看网卡,例如是hme0
# ifconfig hme0  unplumb  –停止网卡
# ifconfig hme0  plumb    –起用网卡
# ifconfig hme0 inet 192.168.2.3 netmask 255.255.255.0 up  –添加ip、子网掩码
# vi /etc/defaultrouter   添加默认路由的ip
# vi /etc/hostname.hme0   添加主机名
# vi /etc/nodename        添加主机名
# vi /etc/resolv.conf
domain china.com          你的域名
nameserver 202.106.0.20   你使用的nds ip
# vi /etc/nsswitch.conf     更改 hosts：file dns

15、 PROM状态命令与参数
格式：  OK>; 指令
命令        说明
banner                     显示当前机器配置状况，CPU,内存,hostid,EtherNet
probe-scsi                 显示内部SCSI通道所挂接设备
probe-scsi-all             显示所有SCSI通道及所挂接设备
probe-ide                  显示所有IDE通道及所挂接设备(针对U10,U5)
devalias                   显示设备别名，如 cdrom,disk,disk0,disk1等
printenv                   无参数，显示环境变量或
参数为环境变量名 如： printenv auto-boot?
setenv                     设置环境变量，如： setenv auto-boot? false
set-default                恢复环境变量预定值  如：set-default auto-boot?
set-defaults               恢复所有环境变量预定值
boot device option        启动主机
设备别名:  cdrom 或 disk
设备名:   /pci@1f,4000/scsi@3,1/disk@6,0:f
option  -r  设备配置
-s  单用户
eject cdrom|floppy         弹出cdrom或floppy
reset                         复位
test net
watch-net-all
show-devs

16、查找网卡名称及接口个数
# grep network /etc/path_to_inst

17、如何一块网卡帮定三个ip,并且子网掩码不同？
举例说明，网卡名hme0：
# vi /etc/hosts
127.0.0.1 localhost
192.168.2.1 dbs loghost
192.168.9.15 dd
192.168.9.65 aa
# vi /etc/netmasks
192.168.2.0 255.255.255.0
192.168.9.0 255.255.255.192
192.168.9.64 255.255.255.252

#vi /etc/hostname.hme0
dbs
#vi /etc/hostname.hme0:1
dd
#vi /etc/hostname.hme0:2
aa
# ipconfig hme0 inet 192.168.2..1 netmask 255.255.255.0 up
# ipconfig hme0:1inet 192.168.9.15 netmask 255.255.255.192 up
# ipconfig hme0 inet 192.168.9.65 netmask 255.255.255.252 up
# init 6
#ipconfig -a

18、如何在prom状态下查看光纤硬盘 ？
stop +a进入ok状态：
ok>; select 光纤卡设备名（可用show-devs查看到）
ok>; show-children

19、主机双屏幕设置。
1.Confirm there are two Video Cards。
2.Confirm driver installed and patches installed if need。
3.vi /usr/dt/config/Xservers.
comment the last line.
and uncomment the nearest line like this.
4.reboot.

20、查看硬盘参数及其物理地址：
#format </dev/null

21、显示磁盘的分区情况：
#prtvtoc /dev/rdsk/c0t0d0s2

系统应用：

1、、查看系统运行级别
# who -r 看运行级别

2、进程工具
pstop pid　 停止进程
prun　pid　 重新启动进程
ptime pid　 使用微状态计算进程时间
pwait pid　 等待指定的进程终止
pcred pid　显示可信度　　　 *
pfiles pid 显示已打开文件的fstat和fcntl信息　　 *
pflags pid 显示每个lwp的/proc跟踪标志，等待和待有信号量以及其他状态信息　 *
pldd　 pid 显示链接到每个进程的动态链接库　　 *
pmap　pid　 显示地址映射空间　　 *
psig　pid　显示信号操作　　　 *
pstack pid 显示每个lwp的十六进制与符号堆跟踪　　 *
ptree　pid　显示包含指定PID的进程树
pwdx　 pid 显示当前工作目录　　　*
后面加*的必须是超级用户执行。
这些工具在/usr/proc/bin/里面。

3、patch软件包的安装
每个补丁都有编号。例如补丁号为101945，版本是34的话，这个补丁的目录名就是101945-34.
# patchadd 105160-01     安装补丁
# patchrm                删除补丁
# patchadd -p            检查系统的补丁情况
# showrev -p             查看所有已经安装的patch

4、如何容许root用户远程登录？
# vi /etc/default/login
CONSOLE=/dev/console  —用#注释掉这一行。

5、如何限定telnet登陆数？solaris pts的数量缺省为47, 修改/etc/system文件， 增加如下内容:
set maxusers=数量
set pt_cnt=数量

6、显示已经使用和未使用的i-node数目
# df –F ufs –o i

7、显示cpu使用率最高的进程
# ps –eo pid,pcpu,args | sort +1n
该命令输出当前系统进程的pid, CPU占用率及命令描述，并以pcpu来排序

8、查看当前的OpenWindows版本
# showrev –w
OpenWindows version:
X11 Version 6.4.1 5 November 2001

9、查看当前CDE的版本
# /usr/ccs/bin/what /usr/dt/bin/dtmail
/usr/dt/bin/dtmail:
CDE Version 1.4.6_06
CDEVersion1.4.6_06

10、文消掉本中的^M
# cat test.dat | tr -d ’15′ >; test.out
这样可以将 test.dat 内 ^M(15) 这个字元去掉, 产生 test.out

11、关机命令。
关闭系统的方式根据关闭的原因而不同.执行关闭有的是为了转至执行等级S，有的是要停止操作系统并关闭设备的电源.
(1) /usr/sbin/shutdown –gtime –ilevel -y
(2) init 0
(3) halt
(4) STOP+A ; sync
(5) 关闭电源
紧急情况，按Stop_A , 如Stop_A不起作用，则将设备电源关闭再打开.这是
极端情况.这两种方法不是干净的关闭，是突然关闭的，仅在紧急情况使用.

12、Solaris下怎么发送即时消息？
用wirte命令到单个用户的终端。
$ wirte username
输入消息正文，结束按ctrl-d,消息就会出现在用户终端。
用户可以用mesg n来决定是否启动接受消息。

用wall，是发给所有系统用户。
$ wall
hello ,i love you …… 结束用ctrl-D.

rwall -n netgroup 给网络上所有用户。
$ rwall -n workgroup ——–发给组workgroup下的每一个用户
hi ! no smoking …… 结束用ctrl -d

$ rwall sune450 ——或者主机名为sune450。用法如上。。。

13、系统是sunos5.8， 不知何种原因现在唯一的普通用户起不了Terminal, vi等，但是超级用户可以，如何补救？
用/etc/skel/local.cshrc 替换掉登陆路径下的 .cshrc, 重新登陆， 就OK了！
$cp /etc/skel/local.cshrc ./

14、关机时这个题是什么意思？
/usr/sbin/vold:  卸载 /vol 时发生问题；中断系统调用
uxwdog:  error communicating with server (Broken pipe)

你还没卸下来/VOL就启动，才出问题，运行：
# umount -f /vol后再做。

15、find常用的例子：
命令格式: find dir -name filename command
例子:
# find . -name hello -print         寻找目前目录及所有的子目录内叫hello的文档。
# find . -ctime +7 -print            找出七天内未被更动的文档
# find . -size +2000m -print         找出大小超过2000 bytes的文档
# find /tmp -user b1234567 -print    在/tmp下属於b1234567的文档
# find . -name ‘*.c’ -exec rm {}     删除所有的.c档
# find . -name test\* -print         显示当前目录及其子目录文件名前4位为test的文件名

16、忘记solarsi的root口令怎么办？
方法一:
1.别怕 ,跟我来.
2.把你的solaris光盘放进cdrom
3.键入stop+a
4.当出现’ok’字样时,键入boot cdrom -s
5.cd /tmp
6.mkdir /tmp/xxx (xxx是什么鬼东西就无关紧要了)
7.mount /dev/dsk/c0t0d0s0 /tmp/xxx (在这里c0t0d0s0是你的root盘)
8.运行csh
9.TERM=sun;export TERM或者
setenv TERM vt220
10.cp /tmp/root/xxx/shadow /tmp/root/xxx/shadow/shadow.backup
11.vi /tmp/root/xxx/shadow并且将password里root项删除。
12.重启动，你就可以以无密码的root登陆了，这时更改你的密码。
要是没有shadow,就把/etc/passwd里root用户名后面的X删掉,就可以了
方法二:
找一台有系统的solaris机器,把忘记密码的系统放进去mount上来,重复方法一10以后的步骤.

solaris for x86的机器：
用光盘启动到要你安装的时候退出去就成单用户，剩下的操作如上。

17、常见文件的解压                   
一般而言,在solaris下,会有这么几种格式的软件:
1) .gz结尾的文件,我们用gunzip或者gzip -d来解压,再用tar来解压.
2) .tar结尾的文件,我们肯定知道用tar xvf的格式来解压.
3) .zip结尾的文件,我们用unzip,注意,这个只有在高版本的solaris下,才有.而且该文件格式以solaris的patch比较多.
4) .Z结尾的文件,我们一般用uncompress来解压(当然,每个人的习惯不一样.)
上面讲的是解压,一般解压后,会生成这么几种方式:
1)生成.local的文件,这个时候,我们用: pkgadd -d xxx.local来安装.
2) 生成一个目录,而且该目录下会有一些pkg信息,我们用: pkgadd -d . ;指在当前目录下,安装,并且按照缺省的路径来安装.
3) 生成一个数字的目录,一般是指solaris的patch,这个时候我们用patchadd来安装.

18、如何在命令行界面替换一个文件中的字符段？
# vi file 在命令模式中输入：
：1， $s/diag/peng/g 全文件查找diag并替换为peng

19、请问TERM=VT100和TERM=dtterm都在什么情况下设置？
一般情况下如果你在机器的显示器上登陆或者通过XMANAGER等登陆，就默认是dtterm，telnet 一般是ansi，当你通过telnet修改文件的时候，需要设置成 TERM = VT100 ; export

TERM

20、如何查看系统的版本？
$ uname -X
$ more /etc/release

21、命令行进入CDE：
#/usr/dt/bin/dtlogin -daemon;exit
or
#/etc/rc2.d/S92dtlogin start;exit;

22、查看patch安装过程中返回错误代码的含义：
#more /usr/sbin/patchadd

23、如何从一台SOL8的机器登录到另外一台SOL8的CDE桌面上去。
登陆CDE的时候点击一下菜单：选择–登陆远程主机–

24、如何查看你的默认语言环境？    C.Arthur
# more /etc/default/init

25、如何更改/home的权限？
停掉autofs服务，或者将/etc/auto_master的home注释掉：
#vi /etc/auto_master
————内容如下———-
# Master map for automounter
#
+auto_master
/net -hosts -nosuid,nobrowse
#/home auto_home -nobrowse
/xfn -xfn

第三方软件应用或技巧：

1、查看当前的bind版本信息
# nslookup –class=chaos –q=txt version.bind

2、在登录时显示系统指定的消息？
#vi /etc/motd    —-删除所有过时的消息,输入新消息
注意：对于已经登录且正在使用系统的用户不显示该消息，超过一屏的消息无法显示。每次修改该文件后，该文件的时间戳随之更新。

3、去掉文本中^M
# dos2unix aaa.txt bbb.txt,会去掉aaa.txt中的^M，生成bbb.txt文件。

4、将系统中7天前的txt文件查找并打包。
# find / -mtime -7 >;aaa.txt
# tar cvf bbb.tar -I aaa.txt
—查找出文件记录在aaa.txt文件中，在作成bbb.tar文件包。

5、查找并删除比某一天更老的文件：
#find . ! -mtime -<days>; | /usr/bin/xarys rn -rf

6、solaris9普通用户下无法正确输入中文的解决方法：
在用户目录在#vi .profile 修改如下：
stty cs8 -istrip

7、请问如何防止telnet登陆发呆时间过长被踢呢？
这里，vi /etc/default/login
# TIMEOUT sets the number of seconds (between 0 and 900) to wait before
# abandoning a login session.
#
#TIMEOUT=300
修改之后不是立即生效，在这之后所又的login session都符合这个要求，但是在修改之前已经建立的连接不受影响。

8、如何安装gcc。
去sunfreeware.com上下载相应平台的pkg包的gcc版本。
#pkgadd -d gcc*
设置环境变量：
bash 和sh 的shell:
vi $home/.profiel
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/etc:/usr/local/bin:/usr/ccs/bin;export PATH
CC=gcc;export CC
csh的shell：
vi $home/.cshrc
set path=( /bin /usr/bin /usr/ucb /etc /usr/local/bin /usr/local/sbin .)
setenv CC gcc

9、列出当前目录下的目录。
ls -al | grep ‘^d’

10、用命令行来打开一个新的terminal。
/usr/dt/bin/dtterm

X86或者Vmware：

1、在Solaris10 x86上挂接window98分区的方法。
#mount -F pcfs /dev/dsk/c0d1p0:e /mnt
总结一下：
偶的硬盘是接在IDE1的slaver盘上，用上述命令可将E：盘挂在/mnt
目录下。如果你的电脑只有一个硬盘，并且是接在主板的IDE1槽，设为
Master盘（通常这种情况较多），现在想挂WIN98下的D：盘，可输入
#mount -F pcfs /dev/dsk/c0d0p0:d /mnt
注意，/mnt可以改为任意的其它空目录，如/data(我在文件管理器中自己
新建的一个目录），可改为
#mount -F pcfs /dev/dsk/c0d0p0:d /data
按回车后如没有任何出错提示，则表示挂接成功，你就可以进入挂接的文件夹（此处为/data）找到你所挂接的win98的D：分区上的文件了。
本方法经过偶N次实验，是确实可行的。为后来者不再偶走过的弯路，偶特在此总结一下，哪位初学者不会在Solaris10 x86（Solaris9也应该行）
挂win98分区的话，可参考本方法。

—————————————-

SysAdmin Commands

Debugging

truss executable
/* Trace doing of given command ( useful debugging ) */

truss -f -p <pid of a shell>
/* Using multiple windows, this can be used to trace setuid/setgid programs */

Arp, ethernet trouble shooting

arp -a .
/* Shows the ethernet address arp table */

arp -d myhost
/* Delete a stale ethernet entry for host myhost */

Disk Commands

du -k .
/* Reports disk space used in Kilobytes */

du -sk .
/* Reports only total disk space used in Kilobytes */

du -sk *|sort -k1,1n
/* Reports total disk space used in Kilobytes in present directory */

du -ad /var | sort -nr
/* Tells you how big the /var files are in reverse order */

fdformat -d -U
/* Format diskette */

/usr/bin/iostat -E
/* Command to display drives statistics */

/bin/mount -F hsfs -o ro /dev/sr0 /cdrom
/* Mount an ISO 9660 CDROM */

newfs -Nv /dev/rdsk/c0t0d0s1
/* To view the superfblocks available */

prtvtoc /dev/rdsk/c0t0d0s2
/* Disk geometry and partitioning info */

quot -af
/* How much space is used by users in kilobytes */

Driver Parameters

ndd /dev/ip \?
/* Shows IP variables in the kernel */

ndd /dev/ip ip_forwarding
/* Tells you if forwarding is on (=1) */

ndd -set /dev/ip ip_forwarding 1
/* Enables IP forwarding between interfaces */

File Manipulation

dos2unix | -ascii <filename>
/* Converts DOS file formats to Unix */

split
/* Split files into pieces */

 : %s/existing/new/g
/* Search and Replace text in vi */

 :set nu
/* Set line numbers in vi */

 :set ts=
/* Set tab stops in vi */

File System

cat /dev/null > filename
/* Zero’s out the file without breaking pipe */

dd if=/dev/rdsk/… of=/dev/rdsk/… bs=4096
/* Make a mirror image of your boot disk */

df -k | grep dg| awk ‘{print $6}’ |xargs -n 1 umount
/* Unmount all file systems in disk group dg */

fsck -F ufs /dev/rdsk/c0t0d0s0
/* Check a UFS filesystem on c0t0d0s0 */

fsck -F ufs -y /dev/rdsk/c0t0d0s0
/* Check answering yes to all questions */

fsck -F ufs -o b=97472 /dev/rdsk/c0t0d0s0
/* Check using an alternate super block */

gzip -dc file1.tar.gz | tar xf -
/* Unpack .tar.gz files in place */

gzip -d -c tarball.tgz | (cd /;tar xf – ) &
/* Unpacking tarballs to diff location */

ln  <source file> <destination file>
/* Creating hard links and soft links */

ls -la | awk ‘{ print $5,”    “,$9 }’ | sort -rn
/* File sizes of current directory */

mount -f pcfs /dev/dsk/c0d0p1 /export/dos
/* Mount DOS fdisk partition from Solaris */

mount -F ufs -o rw,remount /
/* Used to remount root to make it writeable */

mount -o remount,logging /spare
/* Re-mount the ro file system rw and turn on ufs logging */

pax -rw . /newdir
/* Efficient alternative for copying directories */

prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s – /dev/rdsk/c0t1d0s2
/* Cloning Partitiontables */

tar cvf filename.tar
/* Create a tape (tar) archive */

tar xvf filename.tar
/* Extract a tape (tar) archive */

tar cf – . | (cd /newdir ; tar xf -)
/* Recursively copy files and their permissions */

/sbin/uadmin x x
/* Syncs File Systems and Reboots systems fast */

zcat  | cpio -itmv
/* Show the contents of a compressed cpio */

zcat <patch_file.tar.Z | tar xvf -
/* Extract the patch_file that is a compressed tar file */

File Transfer

get filename.suffix |”tar xf -”
/* Undocumented Feature of FTP */

put “| tar cf – .” filename.tar
/* Undocumented Feature of FTP */

find . -depth | cpio -pdmv /path/tobe/copied/to
/* Fast alternative to cp -pr */

sendport
/* Transferring large numbers of files within the same ftp control session */

General

/usr/bin/catman -w
/* Create windex databases for man page directories */

FQ_FILENAME=<fully_qualified_file_name>; echo ${FQ_FILENAME%/*}
/* Extract directory from fully-qualified file name. */

mailx -H -u <username>
/* List out mail headers for specified user */

set filec
/* Set file-completion for csh */

uuencode   | mailx -s “Subject” 
/* Send files as attachments */

Hardware

cfgadm
/* Verify reconfigurable hardware resources */

m64config -prconf
/* Print M64 hardware configuration */

m64config -depth 8|24
/* Sets the screen depth of your M64 graphics accelerator */

m64config -res ‘video_mode’
/* Change the resolution of your M64 graphics accelerator */

Kernel

/usr/sbin/modinfo
/* Display kernel module information */

/usr/sbin/modload <module>
/* Load a kernel module */

/usr/sbin/modunload -i <module id>
/* Unload a kernel module */

nm -x /dev/ksyms | grep OBJ | more
/* Tuneable kernel parameters */

/usr/sbin/sysdef
/* Show system kernal tunable details */

Memory

prtconf | grep Mem
/* Display Memory Size */

Network Information

ndd /dev/arp arp_cache_report
/* Prints ARP table in cache with IP and MAC address */

netstat -a | grep EST | wc -l
/* Displays number active established connections to the localhost */

netstat -k hme0
/* Undocumented netstat command */

netstat -i
/* Show the TCP/IP network interfaces */

netstat -np
/* Similar to arp -a without name resolution */

netstat -r
/* Show network route table */

netstat -rn
/* Displays routing information but bypasses hostname lookup. */

netstat -a | more
/* Show the state of all sockets */

traceroute <ipaddress>
/* Follow the route to the ipaddress */

Network/Tuning

ifconfig eth0 mtu 1500
/* Change MTU of interface */

ifconfig eth0 10.1.1.1 netmask 255.255.255.255
/* Add an Interface */

/sbin/ifconfig hme0:1 inet 10.210.xx.xxx netmask 255.255.0.0 broadcast 10.210.xxx.xxx
/* Virtual Interfaces */

/sbin/ifconfig hme0:1 up
/* Bring virtual interface up */

/usr/sbin/ndd -set /dev/hme adv_100fdx_cap 1
/* Nailling to 100Mbps */

ndd -set /dev/ip ip_addrs_per_if 1-8192
/* To set more than 256 virtual ip addresses. */

ndd -set /dev/tcp tcp_xmit_hiwat 65535
/* Increase TCP-transmitbuffers */

ndd -set /dev/tcp tcp_recv_hiwat 65535
/* Increase TCP-receivebuffers */

Processes

fuser -uc /var
/* Processes that are running from /var */

kill -HUP `ps -ef | grep roccess | awk ‘{print $2}’`
/* HUP any related process in one step */

lsof -i TCP:25
/* Mapping port with process */

pfiles <pid>
/* Shows processes’ current open files */

pkill -n <name>
/* Kill a process by name */

kill `ps -ef | grep program_name | grep -v grep | cut -f8 -d ‘ ‘`
/* pkill for solaris 2.6 */

prstat -a
/* An alternative for top command */

/usr/ucb/ps -aux | more
/* Displays CPU % usage for each process in ascending order */

/usr/ucb/ps -auxww | grep <process name>
/* Gives the full listing of the process (long listing) */

ps -ef | grep -i <string> | awk ‘{ print $2 }’
/* Creates list of running PID by */

ps -ef | grep -v “0:00″ | more
/* Gives you a list of any process with CPU time more than 0:00 */

ps -ef | more
/* Show all processes running */

ps -eo pid,args
/* List processes in simplified format */

ps -fu oracle|grep pmon
/* See which instances of Oracle are running */

/usr/proc/bin/ptree <pid>
/* Print the parent/child process ‘tree’ of a process */

/usr/proc/bin/pwdx <pid>
/* Print the working directory of a process */

top -b 1
/* Returns the process utilizing the most cpu and quits */

Resource Management

/usr/bin/ldd 
/* List the dynamic dependencies of executable files */

/usr/proc/bin/pmap pid
/* Report address space map a process occupies */

Route Configuration

route add net 128.50.0.0 128.50.1.6 1
/* Adds route to 128.50 network via 128.50.1.6 */

route change 128.50.0.0 128.50.1.5
/* Changes the destination address for a route */

route delete net 128.50.0.0 128.50.1.6
/* Deletes route to 128.50 network */

route get 
/* Which interface will be used to contact hostname */

route monitor
/* Monitors traffic to the routes */

route flush
/* Removes all entries in the route table */

Searching Items

egrep “patterna|patternb” <filename>
/* Search for multiple patterns within the same file */

find . -exec egrep -li “str” {} \;
/* Find a string in files starting cwd */

find / -fstype nfs -prune -o fstype autofs -prune -o -name filename -print
/* Find without traversing NFS mounted file systems */

find . -mtime -1 -type f
/* Find recently modified files */

find / -mtime <# of days>
/* Find files modified during the past # of days */

find . ! -mtime -<days> | /usr/bin/xargs rm -rf
/* Finds and removes files older than <days> specified */

find . -type f -exec grep “<sub-string>” {} \; -print
/* Find files (and content) containing <sub-string> within directory tree */

find . -type f -exec grep -l “<sub-string>” {} \;
/* Find filenames containing <sub-string> within directory tree */

find . -type f -print | xargs grep -i 
/* Recursive grep on files */

find / -user <username>
/* Find all files owned by <username> */

find / | grep 
/* Fast way to search for files */

find <start_path> -name “<file_name>” -exec rm -rf {} \;
/* Recursively finds files by name and automatically removes them */

find /proc/*/fd -links 0 -type f -size +2000 -ls
/* Find large files held open by a process */

ls -lR | grep <sub_string>
/* Fast alternative to find */

Security

echo ‘Please go away’ > /etc/nologin
/* Stops users logging in */

find / -perm -0777 -type d -ls
/* Find all your writable directories */

find / -type f -perm -2000 -print
/* Find all SGID files */

find / -type f -perm -4000 -print
/* find all SUID files */

Set Terminal Options

stty erase ^H
/* Sets the Backspace Key to erase */

stty erase ^?
/* Sets the Delete Key to erase */

stty sane
/* Rreset terminal after viewing a binary file. */

tput rmacs
/* Reset to standard char set */

Snoop Your Network

snoop -d pcelx0
/* Watch all network packets on device pcelx0 */

snoop -o /tmp/mylog pcelx0
/* Saves packets from device pcelx0 to a file */

snoop -i /tmp/mylog host1 host2
/* View packets from logfile between host1 & host2 */

snoop -i /tmp/mylog -v -p101
/* Show all info on packet number 101 from a logfile */

snoop -i /tmp/mylog -o /tmp/newlog host1
/* Write a new logfile with all host1 packets */

snoop -s 120
/* Return the first 120 bytes in the packet header */

snoop -v arp
/* Capture arp broadcasts on your network */

Swap File

mkfile -v 10m /export/disk1/myswap
/* Makes a 10 Megabyte swapfile in /export/disk */

mkfile -nv 10m /export/disk1/myswap
/* Makes an empty 10 Megabyte swapfile */

Swap Space

swap -s
/* List the amount of swap space available, also see mkfile */

swap -a /export/disk1/swapfile
/* Add a swapfile */

swap -d /dev/dsk/c0t0d0s4
/* Deletes a swap device */

swap -l
/* List the current swap devices */

System Configuration

drvconfig ; disks
/* Adding hot-plug disks to system */

/usr/sbin/eeprom auto-boot? false
/* Changes eeprom autoboot? setting without going to Ok prompt */

/usr/sbin/eeprom diag-switch? true
/* Set the system to perform diagnostics on the next reboot. */

/usr/sbin/eeprom local-mac-address?=true
/* Multiple Port Network Card Setting */

/usr/sbin/grpck
/* Check /etc/group file syntax */

/usr/sbin/pwck
/* Check /etc/passwd file syntax */

/usr/sbin/sys-unconfig
/* Clear host specific network configuration information */

System Information and Monitoring

coreadm -e log
/* Report global core */

/bin/echo “0t${stamp}>Y\n<Y=Y” | adb
/* Convert UNIX timestamp to something human-readable */

/usr/sbin/eeprom
/* Show eeprom parameters */

grep “\-root” /var/adm/sulog | grep -v \+ | tail -25
/* List most recent attempts to switch to superuser account. */

isainfo -bv
/* Quickly checkout if machine is in 32 or 64 bit mode */

last
/* Tells who was or still is on the system */

logger -i
/* Log the process ID */

psradm -f 
/* Take processor offline */

/usr/sbin/prtconf -vp
/* Show system configuration details */

/usr/platform/`/bin/uname -i`/sbin/prtdiag -v
/* System Diagnostics */

prtconf -pv | grep banner-name |awk -F\’ ‘ { print $2 } ‘ | head -1
/* Show actual model name of machine */

psrinfo | wc -l
/* Display number of processors */

sar -A <time in sec>
/* Provides cumulative system report. */

sar -a <time in sec>
/* Report use of file access system routines. */

sar -u
/* Report CPU Utilization */

telnet <remote machine> 13 | grep ‘:’
/* Get the time on remote Unix machine */

uname -a
/* Displays system information */

vmstat 10
/* Displays summary of what the system is doing every 10 seconds */

who -b
/* Displays the date of the last system reboot. */

ypcat hosts | sort -n -t. +0 -1 +1 -2 +2 -3 +3 -4
/* Take the input of “ypcat hosts” or “cat /etc/inet/hosts” and sort by IP. */

Linux命令速查，超棒
(来自：http://wubinjie.spaces.live.com/ … 901BF6246!201.entry)

一. 启动,关机,登入,登出相关命令
<login> 登录
<logout> 登出
<exit> 登出
<shutdown> 停止系统
<halt> 停止系统
<reboot> 重启动
<poweroff> 切断电源
<sync> 把内存里的内容写入磁盘
<lilo> 安装lilo启动管理程序
<grub> 安装lilo启动管理程序

二. Shell相关命令
<chsh> 切换Shell
<history> 显示命令履历
<alias> 设置命令别名
<unalias> 取消命令别名
<which> 显示命令所在位置
<type> 查询命令种类
<echo> 显示字符串或者变量内容
<set> 设置/显示Shell变量
<printenv> 显示环境变量
<export> 设置环境变量
<env> 设置临时环境变量
<unset> 释放环境变量
<setenv> 设置环境变量
<unsetenv> 释放环境变量
<source> 执行文件当中的命令
<man> 查询命令手册
<info> 查询超文本命令手册
<whatis> 显示命令简介
<apropos> 通过关键字查询手册

三. 用户管理相关命令
<su> 切换到其他用户
<useradd> 追加用户
<adduser> 追加用户
<userdel> 删除用户
<usermod> 修改用户设置
<chfn> 修改用户私人信息
<groupadd> 追加组
<groupdel> 删除组
<groupmod> 修改组设置
<passwd> 更改密码
<whoami> 显示用户名
<logname> 显示登录用户帐号
<users> 显示所有登录用户信息
<who> 查询登录用户信息
<w> 查询登录用户信息
<id> 显示指定用户的ID信息
<groups> 显示指定用户的所属组
<finger> 显示指定用户的个人信息
<mesg> 开关与他人收发消息
<write> 给其他用户发消息
<wall> 给所有用户发消息
<talk> 和其他用户聊天

四. 系统消息相关命令
<date> 显示/设置当前时间
<uptime> 显示系统运行时间
<arch> 显示机器的核心构架（如i386）
<uname> 显示操作系统信息
<tty> 显示终端名
<last> 显示登录/登出在履历
<lastb> 显示非法登录信息
<dumpkeys> 显示当前键盘配置
<loadkeys> 变更键盘配置
<df> 查询磁盘使用信息
<du> 查询磁盘使用信息
<dmesg> 显示系统启动消息
<script> 保存输入输出到文件

五. 文件操作相关命令
<ls> 显示文件列表
<tree> 显示目录树
<pwd> 显示当前路径
<cd> 更改当前路径
<pushd> 追加路径到目录堆栈
<popd> 从目录堆栈删除路径
<dirs> 显示目录堆栈的内容
<mkdir> 创建路径
<rmdir> 删除路径
<cp> 复制文件/目录
<rm> 删除文件/目录
<mv> 移动文件/目录，修改文件名
<chown> 更改文件/目录的所有者
<chgrp> 修改文件/目录的所有组
<chmod> 修改文件/目录的权限
<touch> 更改文件时间
<ln> 建立文件/目录链接
<find> 查找文件
<whereis> 显示文件存在的路径名
<file> 查询文件种类
<size> 查询文件大小

六. 文件编辑相关命令
<cat> 显示文件内容
<tee> 输出到文件和屏幕
<more> 分屏显示文件内容
<less> 分屏显示文件内容
<head> 显示文件头部内容
<tail> 显示文件尾部内容
<fold> 折叠显示长行
<sort> 排列文件的行
<cmp> 比较文件内容
<diff> 显示文件差异
<nkf> 更改日语文件编码
<dd> 变更文件之后复制
<wc> 统计文本单词数，文件大小等
<split> 分割文件
<paste> 以行连接文件
<join> 以字段连接文件
<grep> 查询文字
<uniq> 过滤重复部分显示文件内容
<tr> 替换文字
<sed> 替换文字

七. 压缩/解压缩相关命令
<ar> 压缩/解压缩文件
<tar> 压缩/解压缩文件
<compress> 压缩/解压缩文件
<uncompress> 解压缩
<gzip> 压缩/解压缩文件
<gunzip> 解压缩
<zcat> 显示压缩文件的内容
<lha> 压缩/解压缩文件
<uuencode> 把二进制文件编码为文本文件
<uudecode> 把经过编码的文本文件还原为二进制文件

八. MS-DOS工具集命令
<mdir> 显示文件列表
<mcd> 改变当前目录
<mmd> 新建目录
<mrd> 删除目录
<mdeltree> 删除目录树
<mcopy> 复制文件
<mdel> 删除文件
<mmove> 移动文件
<mren> 更改文件或目录名
<mattrib> 修改文件属性
<mtype> 显示文件内容
<mdu> 查询文件或目录大小
<minfo> 显示磁盘信息
<mformat> 以MS-DOS方式格式化磁盘
<mlabel> 设置磁盘标签

九. 控制外部设备相关命令
<mount> mount上设备
<umount> 解除已经mount上的设备
<eject> 弹出（CD/DVD等）
<fdformat> 格式化软盘
<fdisk> 配置/显示硬盘分区
<mkfs> 格式化磁盘分区
<fsck> 检查/修复磁盘错误
<lpr> 打印到打印机
<lprm> 中断打印任务
<lpq> 显示打印任务的状态
<lpc> 管理/控制打印任务
<ifconfig> 显示/设定NIC配置

十. 进程及任务管理相关命令
<ps> 显示正在运行的进程
<jobs> 显示后台运行任务
<fg> 把任务切换到前台
<bg> 把任务切换到后台
<kill> 中止进程或任务
<killall> 中止进程或任务
<wait> 等待进程或任务的结束
<at> 设置定时执行任务
<atq> 显示尚未执行的任务
<atrm> 删除定时执行任务
<batch> 在系统负荷减轻的时候执行任务
<nice> 改变优先度并执行任务
<nohup> 在后台执行任务，Logout之后也不退出
<sleep> 休眠一定的时间

十一. 网络管理相关命令
<netstat> 显示当前网络连接状况
<route> 显示/设置路由
<host> 显示网络主机情况
<hostname> 显示/设置当前主机的名字
<ping> 确认和远程机器的连接情况
<traceroute> 显示路由信息
<rwho> 查询网上机器的登陆用户
<ruptime> 查询网上机器的系统运行时间
<rlogin> 登陆到远程机器
<telnet> 用telnet登陆到远程机器
<rsh> 给远程机器发送命令
<rcp> 在远程机器之间复制文件
<mail> 收取邮件
<sendmail> 发送邮件
<mailq> 确认邮件队列
<ftp> 用ftp传输文件

十一. 其他命令
<cal> 显示日历
<clear> 清屏
<gcc> 编译C语言代码
<as> 汇编
<bc> 计算
<rpm> Redhat的包管理
<dpkg> Debian的包管理
<installpkg> Slackware的包安装（删除命令则是removepkg）
<XF86Setup,turboxfg,Xconfigurator> 配置 X 服务器
<startx> 启动 X-Window 系统
附：组合命令
重定向，如
$ ls -l /bin > ls-output
$ more ls-output
管道命令，如
$ cat file1 file2 | sort | uniq
经常被用于管道的命令
awk, fold, grep, head, nnkf, pr, sed, sort, tail, tee, tr, uniq, wc