(一)基本命令
1.ls 显示文件名,等同于dos下dir命令
命令格式:ls [option] file
option:
-l 显示详细列表
域1 :文件类型和文件权限
域2 :文件连接数
域3 :文件所有者名字
域4 :文件用户组名字
域5 :文件长度
域6-8 :最近修改日期
域9 :文件名
-a 显示所有文件,包含隐藏文件(以. 起头的文件名)
-R 显示文件及所有子目录
-F 显示文件(后跟*)和目录(后跟/)
-d 与l选项合用,显示目录名而非其内容
4.cat 显示文件内容,等同于dos下type命令
命令格式:cat filename
5.more 以分页方式查看文件内容.
命令格式:more filename
6.rm 删除文件
命令格式: rm [-r] filename (filename 可为档名,或档名缩写符号.)
rm -r dir1 删除目录 dir1,及其下所有文档及子目录.
7.mkdir 创建目录
命令格式: mkdir [-p] directory-name
mkdir dir1 建立一新目录 dir1.
mkdir -p dir/subdir 直接创建多级目录
8.rmdir 删除目录
目录必须首先为空
9.cp 文档复制
命令格式: cp [-r] source destination
10.mv 文件移动
命令格式: mv source destination
11.du 查看目录所占磁碟容量
命令格式: du [-sk] directory
例子 :
du dir1 显示目录 dir1 的总容量及其次目录的容量
du -sk dir1 显示目录 dir1 的总容量,以k bytes为计量
12.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的文件名
13.vi 编辑器
命令状态:
j,k,h,l:上下左右
0: 行首
$: 行尾
i,I :插入命令,i 在当前光标处插入 I 行首插入
a,A:追加命令,a 在当前光标后追加,A 在行末追加
o,O:打开命令,o 在当前行下打开一行,O在当前行上插入一行
r,R :替换命令,r 替换当前光标处字符,R从光标处开始替换
数字s: 替换指定数量字符
x: 删除光标处字符
dd: 删除当前行
d0: 删除光标前半行
d$: 删除光标后半行
ctrl f :后翻页
ctrl b:前翻页
G : 文件尾
数字G: 数字所指定行
/string 查找字符串
n 继续查找
N 反向继续查找
% 查找对应括号
u 取消上次操作
ex命令状态
:set number 显示行号
:set smd 显示显示状态
:0 文件首
:1,5 copy 7 块拷贝
:1,5 del 块删除
:1,5 move 7 块移动
:1,$s/string1/string2/g 全文件查找string1并替换为string2
:wq! 存盘退出
 
(二) 增强命令
1. ln 文档连结
命令格式:ln -s oldname newname ( Hard link )
同一文档,可拥有一个以上之名称,可将文档做数个连结.
ln -s file1 file2   将名称 file2,连结至文档 file1.
2.grep 搜索字符串
命令格式:
grep string filename
寻找字串的方法很多,比如说我想找所有以M开头的行.此时必须引进pattern的观
念.以下是一些简单的□例,以及说明:
^M 以M开头的行,^表示开始的意思
M$ 以M结尾的行,$表示结束的意思
^[0-9] 以数字开始的行,[]内可列举字母
^[124ab] 以1,2,4,a,或b开头的行
^b.503 句点表示任一字母
* 星号表示0个以上的字母(可以没有)
加号表示1个以上的字母
\. 斜线可以去掉特殊意义 
cat passwd | grep ^b 列出大学部有申请帐号者名单
cat passwd | grep ^s 列出交换学生申请帐号者名单
cat passwd | grep '^b.503' 列出电机系各年级...
grep '^\.' myfile.txt 列出所有以句点开头的行
3.fgrep 搜索字符串
命令格式:fgrep string file
4.file 显示文件类型
命令格式:file fileall
文件类型为shell script,ELF 32bit,ASCII text,data or tar file
5.diff 比较文档或目录之不同内容
命令格式:diff [-r] name1 name2 ( name1 name2 可同时为档名,或目录名称.)
例子 :
%diff file1 file2
比较文档 file1 与 file2 内,各行之不同处.
%diff -r dir1 dir2
比较目录 dir1 与 dir2 内,各文档之不同处.
6.cmp 比较文档相同部分
命令格式:cmp file1 file2
7.ftp 远程文件传输
命令格式: ftp [hostname|IP address]
(1) ftp 命令
ascii 将传输模式设为 ascii 模式.通常用於传送文字档.
binary 将传输模式设为 binary 模式,通常用於传送执行档,压缩档与影像档等.
cd remote-directory 将远程主机上的工作目录改变.
lcd [ directory ] 更改本地主机的工作目录.
ls [ remote-directory ] [ local-file ] 列出远程主机上的文档.
get remote-file [ local-file ] 取得远方的文档.
mget remote-files 可使用通用字元一次取得多个文档.
put local-file [ remote-file] 将本地主机的文档送到远程主机.
mput local-files 可使用通用字元一次将多个文档放到远程主机上.
help [ command ] 线上辅助指令.
mkdir directory-name 在远程主机创建一个目录.
prompt 更改交谈模式,若为 on 则在 mput 与 mget 时每作一个文档之传
输时均会询问.
quit/bye 离开ftp .
(2) 后台执行ftp
1.首先,将过程所用到的指令依顺序放入文档中,如下:
 ftp_command
!mkdir test
lcd test
cd test
prompt
binary
mget *.*
bye
2.其次,建一个.netrc档,属性为400,让ftp 自动到此读取Username 与Password,方可顺利login 到的主机,如下: 
.netrc
machine remote login anonymous password guest
3.最後再执行下面指令即可.
%nohup ftp remote < ftp_command > message &
 
用户管理
1.文件信息
ls -l
drwxrwxrwx filename
(1)访问权限
mode : rwx rwx rwx r:read w:write x:execute
user group other
缩写 : (u) (g) (o)
(2) 文件类型
: 普通文件
b : 块特殊文件,如硬盘和CDROM设备
c : 字符文件设备
l : 符号连接
p : 管道或流,用于进程通讯
d : 目录
2.缺省权限
创建文件和目录时,系统自动设置一定的权限.缺省权限由用户mask码控制
$umask ? 显示用户umask码
umask 设置 文件 目录
022 新文件属主有读权和修改权 用户组和其他用户有读权和修改权
用户组和其他用户只有读权
可用umask maskvalue 改变缺省权限
3.系统安全文件
(1) /etc/passwd
(2) /etc/shadow
/etc/group
/etc/default/login
(二)相关命令
1. chmod 改变文档或目录之属性
命令格式:chmod [-R] mode name
( name 可为档名或目录名;mode可为 3 个 8 位元之数字,或利用ls -l命令,列出文档或目录之读、写、执行允许权之文字缩写.)
例子 :
%chmod 755 dir1 将目录dir1,设定成任何使用者,皆有读取及执行之权利,但只有拥有者可做修改.
%chmod 700 file1
将文档file1,设定只有拥有者可以读、写和执行.
%chmod o x file2
将文档file2,增加拥有者可以执行之权利.
%chmod g x file3
将文档file3,增加群组使用者可执行之权利.
%chmod o-r file4
将文档file4,除去其它使用者可读取之权利.
2.chown 改变文档或目录之拥有权
命令格式:chown [-R] username name ( name 可为档名或目录名.)
例子 :
%chown user file1 将文档 file1 之拥有权,改为使用者 user 所有.
%chown -R user dir1 将目录 dir1,及其下所有文档和子目录之拥有权,改为使用者 user 所有.
3.chgrp 改变文档或目录之群组拥有权
命令格式:chgrp [-R] groupname name ( name 可为档名或目录名 )
例子 :
%chgrp vlsi file1
将文档 file1 之群组拥有权,改为 vlsi 群组.
%chgrp -R p_w_picpath dir1
将目录dir1,及其下所有文档和子目录,改为 p_w_picpath 群组. 
4.touch 改变文档或目录之最後修改时间
命令格式:touch name ( name 可为文档或目录名称.) 
5.who 查看系统注册用户
6. id 查看当前用户用户号和组号
7. passwd 修改用户口令
命令格式:passwd username
无用户参数修改本用户口令
8. su 转换用户
命令格式: su [-] username
无用户参数为转换到超级用户
- :执行新用户环境设置
(三)shell特点
1. solaris三类shell
Bourne(缺省shell) 
C
Korn
Shell 基本特点
特点
Bourne
C
Korn
别名机制
No
Yes
Yes
增强的cd(CDPATH)功能
Yes
Yes
Yes
历史列表
No
Yes
Yes
作业控制
No
Yes
Yes
防止文件被覆盖
No
Yes
Yes
忽略Control_D
No
Yes
Yes
2. B shell
变量设置
实例: 终端类型:TERM=vt100;export TERM
语言环境:LANG=C;export LANG
PATH=$PATH:/usr/bin; export PATH
(2) 环境文件
.profile
3. C shell
变量设置
例子: 终端类型:setenv TERM=vt100
路径变量:set path=($path /usr/bin)
(2) 环境文件
.login .cshrc
(四) 创建,删除用户帐户
admintool
 
Shell                                       Prompt
C shell                               machine_name%
C shell for superuser      machine_name#
Bourne shell and Korn shell       $
Bourne shell and Korn shell for superuser        #
Sun Studio Express Sun Studio Express is a program of interim releases of the next Sun Studio release in
development. Sun Studio ExpressMay 2008 is available in the IPS repository, and can
be installed (as superuser) with the command:
pkg install sunstudioexpress

If you want additional developer tools, you can install the ss-dev package instead of
the sunstudioexpress package. The ss-dev includes Sun Studio Express software
plus Subversion, CCS tools,GNUlibtool utility and wrappers,Mercurial,GNU
automake, gmake, CVS, Bison, Flex, math libraries, and various Solaris programmer
tools. You can install as superuser with the following command:
pkg install ss-dev

You can also use the PackageManager desktop application by selecting System >
Administration > PackageManager in the menu bar. To find the Sun Studio packages
in PackageManager, select the “All” category, then type studio in the Search field.
Select a package to install by clicking its checkbox and then clicking Install/Update
button.
 
NetBeans IDE 6.0.1 TheNetBeans IDE 6.0.1 is available in the IPS repository. You can install the IDE and
all available add-ons in a single netbeans package. You can do this with one
command, as superuser:
pkg install netbeans

You can also install packages with the PackageManager desktop application by
selecting System > Administration > PackageManager. To find all theNetBeans
packages from PackageManager, select the category All, then type netbeans in the
Search field.
 
AMP Web Stack Two package clusters for the AMP stack are available in the IPS repository: amp and
amp-dev. You can install Apache,MySQL, and PHP by installing the amp package, with
one command, as superuser:
pkg install amp

You can also install packages with the PackageManager desktop application by
selecting System > Administration > PackageManager from the menu bar. To find all
the AMP packages from PackageManager, select the category All, then type amp in the
Search field. Select a package to install by clicking its checkbox and then clicking
Install/Update button.
The amp-dev cluster includes the Apache,MySQL, and PHP packages, plus additional
developer software, including the Web Stack user interface, and recent versions of
NetBeans,Mercurial, CVS, Python, Subversion, and other open source tools and
servers.
 
HPC ClusterTools
7.1
The Sun HPC ClusterTools software is a set of development tools that you can use to
develop parallel applications designed to run on distributed-memory systems.
The IPS includes HPC ClusterTools 7.1, which you can install with one command as
superuser:
pkg install clustertools

You can also install packages with the PackageManager desktop application by
selecting System > Administration > PackageManager from the menu bar. To find
ClusterTools packages from PackageManager, select the category All, then type
clustertools in the Search field. Select a package to install by clicking its checkbox
and then clicking Install/Update button.
 
 
Logging In Remotely (rlogin)
The rlogin command enables you to log in to other UNIX machines on your
network.
To remotely log in to another machine, type the following command.
$ rlogin machinename
In the previous example, machinename is the name of the remote machine.
If a password prompt appears, type the password for the remote machine and press
Return. If your machine name is in the other machine’s /etc/hosts.equiv file, the
current machine does not prompt you to type the password.
venus$ rlogin starbug -l user2
Password:
Last login: Wed Nov 1 13:08:36 from venus
Sun Microsystems Inc. SunOS 5.9 Generic February 2002
venus$ pwd
/home/user2
venus$ logout
Connection closed.
venus$
rlogin Without a Home Directory
In the previous example, user user2 logs in to the remote machine starbug at the
directory /home/user2, as indicated by the pwd command. When you log in to a
machine where you have no account, rlogin displays a message stating that you
have no home directory on the remote machine. rlogin then logs you in to the root
(/) directory of that machine:
venus$ earth -l user2
Password:
No directory! Logging in with home=/
rlogin as Someone Else
The -l option of the rlogin command enables to log in to a remote machine as
someone else. This option can be useful if you are working on someone else’s machine
(using their username) and you want to log in to your own machine as yourself.
Use the following command syntax for the -l option of the rlogin command.
# rloginmachinename -l username
The following example shows how user user2 on machine venus would log in to
machine starbug as user1.
venus$ rlogin starbug -l user1
Password:
Last login: Thu Nov 2 12:51:57 from venus
Sun Microsystems Inc. SunOS 5.9 Generic February 2002
starbug$ pwd
/home/user1
starbug$ logout
Connection closed.
starbug$
Note that when you log in to a remote machine as someone else, you are placed in that
user’s home directory.
Last login: Thu Nov 2 12:51:57 from venus
Sun Microsystems Inc. SunOS 5.9 Generic February 2002
earth$ pwd
/
earth$ logout
Connection closed.
earth$
 
Aborting an rlogin Connection
Normally you terminate an rlogin connection by typing logout at the end of a
work session. If cannot terminate a session in this manner, you can abort the
connection by typing a tilde character followed by a period (~.). The remote login
connection to the remote machine is aborted and you are placed back at your original
machine.
If you log in to a series of machines, gaining access to each machine through another
machine, and you use ~. to abort the connection to any of the machines, you are
returned to your original machine.
venus$ rlogin starbug -l user2
Password:
Last login: Thu Nov 2 15:13:10 from venus
Sun Microsystems Inc. SunOS 5.9 Generic February 2002
starbug$ ~. (You may not see the ~ on the screen.)
Closed connection.
venus$
If you want to back up to an intermediate rlogin connection, use two tildes followed
by a period (~~.).
venus$ rlogin starbug -l user2
Password:
Last login: Thu Nov 2 15:14:58 from venus
Sun Microsystems Inc. SunOS 5.9 Generic February 2002
starbug$ rlogin rlogin earth -l user2
Password:
Last login: Thu Nov 2 15:24:23 from starbug
Sun Microsystems Inc. SunOS 5.9 Generic February 2002
earth$ ~~. (You may not see the ~~ on the screen.)
Closed connection.
starbug$
Suspending an rlogin Connection
When you want to suspend an rlogin connection so you can return to it later, type
the tilde character (~) followed by Ctrl-Z. The rlogin connection becomes a stopped
process and you are placed back at the machine from which you logged in.
To reactivate the connection, type fg. You can also type the percentage sign (%)
followed by the process number of the stopped process. If you do not specify a process
number, % activates the process most recently suspended.
venus$ rlogin goddess -l user2
Password:
Last login: Thu Aug 31 14:31:42 from venus
Sun Microsystems Inc. SunOS 5.9 Generic February 2002
goddess$ pwd
/home/user2
goddess$~^Z
Stopped (user)
venus$ pwd
/home/user2/veggies
venus$fg
rlogin goddess
goddess$ logout
venus$
You can also type two tildes and press Ctrl-Z to suspend the current rlogin and
place you at an intermediate rlogin.
For more information on the rlogin(1) command, refer to the man Pages(1): User
Commands.
Verifying Your Location (who am i)
After logging in to a variety of remote machines, you might need to verify where you
are. Type who am i to display the name of the machine you are currently logged in to
as well as your current login name.
 
Copying Files Remotely (rcp)
The rcp command enables you to copy files from one machine to another. This
command uses the remote machine’s /etc/hosts.equiv and /etc/passwd files to
determine whether you have unchallenged access privileges. The syntax for rcp is
similar to the command syntax for cp.
Note – To copy subdirectories and their contents from one machine to another, use
rcp -r.
Copying Files From a Remote Machine
To copy from a remote machine to your machine, use the rcp command with the
following syntax.
$ rcp machinename:source destination
In the previous example, machinename is the name of the remote machine, source is the
name of the file(s) you want to copy, and destination is the path name on your machine
where you want the copied file(s) to reside.
The following example illustrates how to copy the file /etc/hosts from the remote
machine starbug to the /tmp directory on the local machine venus.
venus$ rcp starbug:/etc/hosts /tmp
You can also combine various abbreviations and syntaxes when using rcp. For
example, to copy all of the files ending in .doc from user hank’s home directory on
remote machine fretful to the current directory on local machine venus, type the
following command.
venus$ rcp fretful:~hank/*.doc .
venus$
Copying Files From Your Machine to Another
To copy files from your local machine to a remote machine, use the following
command syntax.
$ rcp source machinename:destination
In the previous example, source is the file(s) you want to copy, machinename is the name
of the remote machine, and destination is the path name on the remote machine where
you want the copied file(s) to reside.
The following example illustrates how to copy the file newhosts from your /tmp
directory to the /tmp directory on the remote machine starbug.
venus$ cd /tmp
venus$ rcp newhosts starbug:/tmp
venus$
For more information on the rcp(1) command and its options, refer to the man
Pages(1): User Commands.
 
Executing Commands Remotely (rsh)
The rsh command (for remote shell) enables you to execute a single command on a
remote machine without having to log in to the remote machine. If you know you only
want to do one thing on a remote machine, rsh enables you to quickly execute one
command on a remote machine.
To execute a command on a remote machine, use the following command syntax.
rsh machinename command
The following example shows how you would view the contents of the directory
/etc/skel on the machine starbug.
 
venus$ rsh starbug ls /etc/skel*
local.cshrc
local.login
local.profile
venus$
Similar to the rlogin and rcp commands, rsh uses the remote machine’s
/etc/hosts.equiv and /etc/passwd files to determine whether you have
unchallenged access privileges to the remote machine.
For more information on the rsh(1) command and its options, refer to the man
Pages(1): User Commands
Viewing User Information (rusers)
The rusers command (for remote users) shows you which users are logged in to other
machines on your network. Type the rusers command by itself to display each
machine on the network and the user(s) logged in to these machines.
$ rusers
starbug user2 user1 root
earth user1
venus user3
Notice that three users are logged in to the machine starbug.
To display information on a specific remote machine, type the rusers command
followed by the name of the machine.
$ rusers starbug
starbug user2 user1 root
$
The -l option to the rusers command displays the following information.
User names
Machine and terminal names
Time each user logged in
How long each user has been idle (if more than one minute)
Name of the machine that each user logged in from
$ rusers -l starbug
root starbug:console Oct 31 11:19 (:0)
user2 starbug:pts/7 Oct 31 11:20 40:05 (starbug)
user1 starbug:pts/13 Nov 1 14:42 17:18 (starbug)
$
You can also use the -l option without providing a machine name.
How to Run an Application on a Remote Machine
1. Use the xhost command on the local machine to give the remote machine display
access.
starbug$ xhost + venus
2. Log in to the remote machine.
starbug$ rlogin venus -l user2
Password:
Last login: Wed Nov 1 16:06:21 from starbug
Sun Microsystems Inc. SunOS 5.9 Generic February 2002
3. Set the DISPLAY variable to the local machine.
venus$ DISPLAY=starbug:0.0
4. Export the DISPLAY variable to the local machine.
venus$ export DISPLAY
5. Run the application.
venus$ bigprogram &
Even though you interact with this application just as you would with any other
application on your screen, the application runs on the remote machine.
The benefit from running an application in this way is that it uses fewer computing
resources than an application that is installed on your machine. This example shows
how to run any remote application to which you have access.
Depending on which shell is set up as your default, your user profile can be one of the
following:
.profile (for the Bourne and Korn shells)
.bash_profile (for the Bourne Again shell)
.login and .cshrc (for the C shell)
.tcshrc and .cshrc (for the TC shell)
.zlogin and .zshrc (for the Z shell)
Your user profile file(s) is located in your home directory and enables you to configure
your working environment to your preference.