終端機快捷鍵
ctrl+s :終止螢幕輸出。例如用cat命令輸出時,想要暫停一下
ctrl+s :終止螢幕輸出。例如用cat命令輸出時,想要暫停一下
ctrl+q :恢復ctrl+s的輸出
ctrl+c :中斷當前的活動,返回命令提示符
ctrl+d :表示文件的結束或退出,如退出終端機窗口
ctrl+u :清除整個命令行
ctrl+w :清除命令行最後一個單詞
ctrl+h :清除命令行最後一個字符
bc :計算機
ctrl+c :中斷當前的活動,返回命令提示符
ctrl+d :表示文件的結束或退出,如退出終端機窗口
ctrl+u :清除整個命令行
ctrl+w :清除命令行最後一個單詞
ctrl+h :清除命令行最後一個字符
bc :計算機
#ksh 切換到k shell
指令:
# uname
SunOS
NAME
SunOS
NAME
#man uname
uname - print name of current system
uname - print name of current system
SYNOPSIS
uname [-aimnprsvX]
uname [-aimnprsvX]
uname [-S system_name]
# date
2004年05月19日星期三21時57分49秒CST
#
stings
$stings /usr/bin/cat
能夠用來打印可執行文件或二進製文件中的可讀字符。
cat more
#cat -n test.txt //顯示行號
Space:滾動到下一頁
Enter:一次滾動一行
Enter:一次滾動一行
b 向後移動一頁
f 向前移動一頁
h 顯示更多特性的幫助選單
q 退出,返回shell提示符
/string 向前搜索字符串string
n 查找下一處匹配
less
#less test.txt
#less test.txt
F 往下移動一頁
B 往上移動一頁
/string 查找字符
head
#head -5 /export/home/wing/test.txt //顯示開始的5行
#head chap*|more //顯示所有以chap開頭的文件的前n行
用來顯示一個或多個文件的前n行,默認省略-n參數將顯示文件的前10行。
#head -5 /export/home/wing/test.txt //顯示開始的5行
#head chap*|more //顯示所有以chap開頭的文件的前n行
用來顯示一個或多個文件的前n行,默認省略-n參數將顯示文件的前10行。
tail
#tail -5 /export/home/wing/test.txt //顯示最後5行
#tail +5 /export/home/wing/test.txt //顯示第5行開始到結束
用來顯示一個文件的最後n行,默認省略-n參數將顯示文件的最後10行。
#tail -5 /export/home/wing/test.txt //顯示最後5行
#tail +5 /export/home/wing/test.txt //顯示第5行開始到結束
用來顯示一個文件的最後n行,默認省略-n參數將顯示文件的最後10行。
# tail -f /var/adm/messages //持續更新syslog
wc
#wc /export/home/wing/test.txt //顯示文件的行、單詞、字節數
#wc -l /export/home/wing/test.txt //顯示文件的行數
選項功能
-l 統計行數
-w 統計單詞數
-c 統計字節數
-m 統計字符數
-l 統計行數
-w 統計單詞數
-c 統計字節數
-m 統計字符數
diff
#diff -i test.txt test2.txt //忽略文章中的大小寫
#diff -c test.txt test2.txt //進行細緻的比較生成一個差別表
#diff -i test.txt test2.txt //忽略文章中的大小寫
#diff -c test.txt test2.txt //進行細緻的比較生成一個差別表
touch
#touch test1.txt test2.txt test3.txt //可以一次建立多個文件
#touch test1.txt test2.txt test3.txt //可以一次建立多個文件
mkdir
#mkdir /export/home/wing
#mkdir -p /export/home/wing //在路徑中名中不存在的目錄將被建立
#rmdir dir //所要刪除的目錄必須是空的
#mkdir /export/home/wing
#mkdir -p /export/home/wing //在路徑中名中不存在的目錄將被建立
#rmdir dir //所要刪除的目錄必須是空的
rm
rm -i test.txt test2.txt //交互式刪除文件
rm -r /tem/testd //刪除目錄和目錄下的文件
rm -ir /tem/testd //交互式的刪除目錄和目錄下的文件
rm -i test.txt test2.txt //交互式刪除文件
rm -r /tem/testd //刪除目錄和目錄下的文件
rm -ir /tem/testd //交互式的刪除目錄和目錄下的文件
cp
cp -i oldfilename newfilename //交互式拷貝
cp /export/home/keven/ok.txt /export/home/wing/test.txt
cp -ri /export/home/keven /export/home/wing 整個目錄一起拷
cp -rp 文件屬性一起拷貝
cp -i oldfilename newfilename //交互式拷貝
cp /export/home/keven/ok.txt /export/home/wing/test.txt
cp -ri /export/home/keven /export/home/wing 整個目錄一起拷
cp -rp 文件屬性一起拷貝
crontab
直接登陸窗口界面
# crontab -l root //查看作業
/etc/init.d/cron stop //停止進程
在CONSOLE 中輸入指令crontab -e root
crontab -e root //編輯加入要執行的代碼
0-59 * * * * date >> /export/home/keven/keven.txt //加入次行在末尾,每分鐘執行一次
“格式如下:
(1) (2) (3) (4) (5) (6)
0 0 * * 3 date >> /export/home/keven/keven.txt
1. 分鐘(0-60)
2. 小時(0-23)
3. 日(1-31)
4. 月(1-12)
5. 星期(0-6)
6. 所要運行的程序
如1-59分鐘,1-24 小時
(1) (2) (3) (4) (5) (6)
0 0 * * 3 date >> /export/home/keven/keven.txt
1. 分鐘(0-60)
2. 小時(0-23)
3. 日(1-31)
4. 月(1-12)
5. 星期(0-6)
6. 所要運行的程序
如1-59分鐘,1-24 小時
0 18-23 0 0 0-6 //每天的18-23點執行,0-6為周日到週六
ls
$ ls -n total 12
-rw-r--r-- 1 0 1 247 10月2 07:53 list
-rw-r--r-- 2 1002 100 62 10月2 01:10 ok.txt
drwxr-xr-x 2 0 1 512 10月1 21:27 ss
-rw-r--r-- 1 1002 100 171 10月3 01:10 test.txt
-rw-r--r-- 1 1002 100 120 10月2 20:54 test1
-rw-r--r-- 1 1002 100 0 9月30 08:54 test2
-rw-r--r-- 1 1002 100 0 9月30 08:54 test3
-rw-r--r-- 1 0 1 247 10月2 07:58 tt.txt
$ ls -n total 12
-rw-r--r-- 1 0 1 247 10月2 07:53 list
-rw-r--r-- 2 1002 100 62 10月2 01:10 ok.txt
drwxr-xr-x 2 0 1 512 10月1 21:27 ss
-rw-r--r-- 1 1002 100 171 10月3 01:10 test.txt
-rw-r--r-- 1 1002 100 120 10月2 20:54 test1
-rw-r--r-- 1 1002 100 0 9月30 08:54 test2
-rw-r--r-- 1 1002 100 0 9月30 08:54 test3
-rw-r--r-- 1 0 1 247 10月2 07:58 tt.txt
# ls -ld using_samba //查看目錄的權限
drwxr-xr-x 2 root other 512 5月8 22:23 using_samba
drwxr-xr-x 2 root other 512 5月8 22:23 using_samba
$ ls -a
. .cshrc list ss test1 test3
.. .login ok.txt test.txt test2 tt.txt
$ ls -l
總數12
-rw-r--r-- 1 root other 247 10月2 07:53 list
-rw-r--r-- 2 keven user 62 10月2 01:10 ok.txt
drwxr-xr-x 2 root other 512 10月1 21:27 ss
-rw-r--r-- 1 keven user 171 10月3 01:10 test.txt
-rw-r--r-- 1 keven user 120 10月2 20:54 test1
-rw-r--r-- 1 keven user 0 9月30 08:54 test2
-rw-r--r-- 1 keven user 0 9月30 08:54 test3
-rw-r--r-- 1 root other 247 10月2 07:58 tt.txt
總數12
-rw-r--r-- 1 root other 247 10月2 07:53 list
-rw-r--r-- 2 keven user 62 10月2 01:10 ok.txt
drwxr-xr-x 2 root other 512 10月1 21:27 ss
-rw-r--r-- 1 keven user 171 10月3 01:10 test.txt
-rw-r--r-- 1 keven user 120 10月2 20:54 test1
-rw-r--r-- 1 keven user 0 9月30 08:54 test2
-rw-r--r-- 1 keven user 0 9月30 08:54 test3
-rw-r--r-- 1 root other 247 10月2 07:58 tt.txt
$ ls -F //列出目錄名
TT_DB/ keven/ temp/ user2/ www/
cole/ lost+found/ user1/ wing/
符號文件類型
/ 文件夾
* 可執行文件
(none) 無格式文件或者ASCII文件
@ 鏈接符
如:
# ls -F
accept* gsscred* metaset* i86/ //目錄
acctadm* halt* metastat* roleadd*
add_drv* hostconfig*metasync* test.txt //ASCII
cachefslog@ in.rlogind* mount* rtquery*
cachefswssize@鏈接文件in.routed* mountall* rwall*//可執行文件
# ls -F
accept* gsscred* metaset* i86/ //目錄
acctadm* halt* metastat* roleadd*
add_drv* hostconfig*metasync* test.txt //ASCII
cachefslog@ in.rlogind* mount* rtquery*
cachefswssize@鏈接文件in.routed* mountall* rwall*//可執行文件
$ ls -R //遞歸顯示
.:
TT_DB keven temp user2 www
cole lost+found user1 wing
./cole:
inetservices.txt services services.txt
./keven:
dir test.txt
dir test.txt
./keven/dir:
./lost+found:
./lost+found: 權限被否定
./lost+found: 權限被否定
./temp:
so.tar.gz
so.tar.gz
./user1:
./user2:
./wing:
aa dead.letter mywife.tar ok passwd.txt test
aa dead.letter mywife.tar ok passwd.txt test
./wing/test:
./www:
$
$ ls . //顯示當前目錄
dir test.txt
$ ls .. //顯示當前目錄的父目錄,支持路徑表示符如~
TT_DB keven temp user2 www
cole lost+found user1 wing
$ ls -i test.txt test1.txt //節點檢查
64 test.txt 65 test1.txt
$
$ ls . //顯示當前目錄
dir test.txt
$ ls .. //顯示當前目錄的父目錄,支持路徑表示符如~
TT_DB keven temp user2 www
cole lost+found user1 wing
$ ls -i test.txt test1.txt //節點檢查
64 test.txt 65 test1.txt
$ ls -il test.txt test1.txt
64 -rw-r--r-- 1 keven sysadmin 27 10月12 17:27 test.txt
65 -rw-r--r-- 1 keven sysadmin 0 10月12 17:25 test1.txt
$ ls -ld //只顯示目錄
drwxr-xr-x 3 keven sysadmin 512 10月12 17:25 .
64 -rw-r--r-- 1 keven sysadmin 27 10月12 17:27 test.txt
65 -rw-r--r-- 1 keven sysadmin 0 10月12 17:25 test1.txt
$ ls -ld //只顯示目錄
drwxr-xr-x 3 keven sysadmin 512 10月12 17:25 .
file
$ file passwd.txt
passwd.txt: ascii文本
$ file passwd.txt
passwd.txt: ascii文本
lp
$lp ok.txt myfile test.txt
$lp -p evans1 test.txt //-p後為印表機evans1
$lpstat // 列印隊列狀態
$lp ok.txt myfile test.txt
$lp -p evans1 test.txt //-p後為印表機evans1
$lpstat // 列印隊列狀態
ln
#ln file1 newfile
#ln file1 directory/newfilename 硬連結(hard link)
#ln ~/book/chap* /home/brad
為每個chap文件都建立了連結,把這些連結指向/home/brad目錄
如果文件有多個指向它的磁碟連結,只是刪除該文件並不能有效的釋放磁碟空間,你必須刪除掉所有指向它的硬連結才可以。
#ln -s src target //軟連結(soft link)儲存的只是路徑,用ls -l 可以看到,如果原文件已移走刪除改名,則target就沒有用了
# ln -s /export/home/ddd /var // 把/export/home/ddd目錄連接到/var下面
在var下面生成ddd 連結符號。當/var滿了視情況用
mv
#mv -i oldfilename newfilename 將檔案或目錄改名
#mv -i source_file(s) target_directory 移動檔案到其它目錄
swap
# swap -s //列出系統虛擬交換空間的摘要。
total: 25728k bytes allocated + 6140k reserved = 31868k used,56496k
available
available
# swap -l //列出系統物理交換空間的詳細說明。
swapfile dev swaplo blocks free
/dev/dsk/c0t3d0s1 32,28 8 98792 90384
swapfile dev swaplo blocks free
/dev/dsk/c0t3d0s1 32,28 8 98792 90384
vmstat //查看虛擬記憶體狀態
# vmstat
kthr memory page disk faults cpu
rbw swap free re mf pi po fr de sr cd f0 s0 -- in sy cs us sy id
0 0 0 635012 40880 10 36 21 0 1 0 231 3 0 0 0 116 287 184 1 1 99
# vmstat
kthr memory page disk faults cpu
rbw swap free re mf pi po fr de sr cd f0 s0 -- in sy cs us sy id
0 0 0 635012 40880 10 36 21 0 1 0 231 3 0 0 0 116 287 184 1 1 99
# vmstat -s
0 swap ins
0 swap outs
0 pages swapped in
0 pages swapped out
84899 total address trans. faults taken //位址解析錯誤
5916 page ins
6 page outs
12283 pages paged in
9 pages paged out
22759 total reclaims
22759 reclaims from free list
0 micro (hat) faults
84899 minor (as) faults //小錯誤
5186 major faults //主要錯誤
16092 copy-on-write faults //複製寫入操作錯誤
0 swap ins
0 swap outs
0 pages swapped in
0 pages swapped out
84899 total address trans. faults taken //位址解析錯誤
5916 page ins
6 page outs
12283 pages paged in
9 pages paged out
22759 total reclaims
22759 reclaims from free list
0 micro (hat) faults
84899 minor (as) faults //小錯誤
5186 major faults //主要錯誤
16092 copy-on-write faults //複製寫入操作錯誤
22331 zero fill page faults
539644 pages examined by the clock daemon
18 revolutions of the clock hand
570 pages freed by the clock daemon
550 forks
17 vforks
514 execs
431543 cpu context switches
272891 device interrupts
105553 traps
671500 system calls
97227 total name lookups (cache hits 96%)
1297 user cpu
1388 system cpu
230813 idle cpu
1542 wait cpu
#
539644 pages examined by the clock daemon
18 revolutions of the clock hand
570 pages freed by the clock daemon
550 forks
17 vforks
514 execs
431543 cpu context switches
272891 device interrupts
105553 traps
671500 system calls
97227 total name lookups (cache hits 96%)
1297 user cpu
1388 system cpu
230813 idle cpu
1542 wait cpu
#
mpstat //系統負載cpu等訊息
# mpstat 5 //每隔5秒刷新一次
CPU minf mjf xcal intr ithr csw icsw migr smtx srw syscl usr sys wt idl
0 32 2 0 114 68 181 5 0 1 0 263 0 1 1 98
0 2 0 0 101 55 160 1 0 0 0 58 0 0 0 100
0 0 0 0 101 55 164 1 0 0 0 70 0 0 0 100
0 0 0 0 99 52 158 1 0 0 0 48 0 0 0 100
0 22 0 0 102 56 164 1 0 0 0 136 0 0 0 100
# mpstat 5 //每隔5秒刷新一次
CPU minf mjf xcal intr ithr csw icsw migr smtx srw syscl usr sys wt idl
0 32 2 0 114 68 181 5 0 1 0 263 0 1 1 98
0 2 0 0 101 55 160 1 0 0 0 58 0 0 0 100
0 0 0 0 101 55 164 1 0 0 0 70 0 0 0 100
0 0 0 0 99 52 158 1 0 0 0 48 0 0 0 100
0 22 0 0 102 56 164 1 0 0 0 136 0 0 0 100
cal
# cal
2004年5月
日一二三四五六
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
# cal 12 2002 //顯示2002年10月的日曆
2002年12月
日一二三四五六
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
2002年12月
日一二三四五六
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
# date;uname //組合命令,中間用;隔開
2004年05月19日星期三22時05分23秒CST
SunOS
重定向輸入/輸出
#command >filename //如果文件名存在,它將被覆蓋,不存在將被建立
#command >>filename //向一個存在的檔案追加內容 (添加到檔案的末段),而不是覆蓋它,如果不存在就建立。
#command 2>filename //重定向標準錯誤,會建立檔案或覆蓋原有檔案
#command 2>>filename //重定向標準錯誤,向一個存在的檔案追加內容 (添加到文件的末尾),而不是覆蓋它,如果不存在就建立。
#command 2>>filename //重定向標準錯誤,向一個存在的檔案追加內容 (添加到文件的末尾),而不是覆蓋它,如果不存在就建立。
find
#find . -name test.txt //搜索當前目錄
#find dir -name test.txt
#find / -name test.txt
#find /export/home -name test.txt
#find ~ -name '*tif' //用戶的主目錄
#find /export -name core -exec rm {} \ //搜索core文件並刪除它們
#find dir -type d //文件類型
#find /export -type d -name test //文件夾名為test
#find /export -size +400 //文件大於400塊的512byte =1 blocks
#find /export -name test.txt -exec rm {} \; //查找並刪除
#find /export -name test.txt -ok rm {} \; //交互模式刪除y
#find /export -user keven //按用戶查找
#find / -user UID -exec rm{} \; //查找該用戶的文件並刪除
#find / -name pfile -print>find.txt 2>null.txt&
//找到則放入find.txt,否則就放到null.txt 程序在背景運行
#find dir -name test.txt
#find / -name test.txt
#find /export/home -name test.txt
#find ~ -name '*tif' //用戶的主目錄
#find /export -name core -exec rm {} \ //搜索core文件並刪除它們
#find dir -type d //文件類型
#find /export -type d -name test //文件夾名為test
#find /export -size +400 //文件大於400塊的512byte =1 blocks
#find /export -name test.txt -exec rm {} \; //查找並刪除
#find /export -name test.txt -ok rm {} \; //交互模式刪除y
#find /export -user keven //按用戶查找
#find / -user UID -exec rm{} \; //查找該用戶的文件並刪除
#find / -name pfile -print>find.txt 2>null.txt&
//找到則放入find.txt,否則就放到null.txt 程序在背景運行
# find /export -name tex.txt -exec rm {} \; //{} \中間有一個空格
$ find ~ -name '*es' //es的前面為任意字符
$ find ~ -name '*es' //es的前面為任意字符
搜索表達式意義定義
name filename 文件名搜索所有匹配的給定的文件,可以接受元字符(如? *)
type filetype 文件類型搜索匹配給定文件類型的文件(d為目錄)
mtime [+|-]n 修改的時間搜索所有修改時間或者大於,或小於給定時間的文件
atime[+|-]n 訪問的時間搜索所有訪問時間或者大於,或者小於給定時間的文件
user loginid -group groupid 用戶ID和屬組ID 搜索所有匹配登陸ID的所有者或屬組ID的文件
perm mode 權限搜索所有匹配給定權限的文件(只允許八進制模式)
size[+|-]n[c] 搜索所有大小或者大於,小於n的文件,n以512字節每塊計算,如果後面有ac,則以字符(字節)計算
-print 基將搜索結果輸出到標準輸出。該結果是一個全路徑名的文件名列表
-exec command{}\; exec選項必須通過\;來終止;這樣使得find命令可以應用於指定命令中搜索準則中給出的每個文件
-ok command{}\; -exec的交互格式.這個選項用於要求來自用戶的輸入命令.如rm -i
-ls 使用長列表格式打印當前路徑.這個表達式最常用於鏈接一個輸出,把它重定向到一個文件中,以便稍後進行檢查
-ok command{}\; -exec的交互格式.這個選項用於要求來自用戶的輸入命令.如rm -i
-ls 使用長列表格式打印當前路徑.這個表達式最常用於鏈接一個輸出,把它重定向到一個文件中,以便稍後進行檢查
grep
#grep root /etc/passwd //在passwd中查找root
#grep -i root /etc/passwd //忽略大小寫
#grep -v root /etc/passwd //顯示除了含有root的行
# grep -c root group //統計有多少行
10
#grep root /etc/passwd //在passwd中查找root
#grep -i root /etc/passwd //忽略大小寫
#grep -v root /etc/passwd //顯示除了含有root的行
# grep -c root group //統計有多少行
10
# grep -l root passwd group hosts //查找文件中包含root的文件
passwd
group
passwd
group
正規表示式
.(dot) 匹配任意字符可以多次使用,類似ls命令grep chap.. file 顯示所有包含chap,且之後還有兩個字符的行
.(dot) 匹配任意字符可以多次使用,類似ls命令grep chap.. file 顯示所有包含chap,且之後還有兩個字符的行
*(asterisk) 在模式上匹配0個或多個字符grep chap* file 顯示所有包含chap,且之後可以是任意字符
\(back slash) 告訴shell按照字面意思理解\之後的特殊字符
EX.grep dollar\* file // 顯示所有包含dollar*的行./告訴shell按照字面意思理解*,而不是通用符號
^ (caret) 匹配所有以指定模式打頭的所有行grep ^name file 顯示所有以Name開頭的行
$ 匹配所有以指定模式結尾的行grep $800 file 顯示所有以800結尾的行
[] 匹配模式中的一個字符grep [64.128] 顯示所有包含64MB或128MB的行
-i 忽略大小寫
-v 反包含.除了該字符串之外的行
egrep
# egrep 'N(e|o)' /etc/passwd //查找以字母大N開頭後面接e 或者o
listen:x:37:4:Network Admin:/usr/net/nls:
nobody:x:60001:60001:Nobody:/:
noaccess:x:60002:60002:No Access User:/:
nobody4:x:65534:65534:SunOS 4.x Nobody:/:
$ egrep '(Network|uucp) Admin' /etc/passwd
uucp:x:5:5:uucp Admin:/usr/lib/uucp:
nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico
listen:x:37:4:Network Admin:/usr/net/nls:
sort
#cat test.txt
oggg
aaa
ddkk
ddgfg
kk
11
34
22
#sort test.txt
11
22
34
aaa
ddgfg
ddkk
kk
oggg
# ls -ld t* >list
# cat list
-rw-r--r-- 1 keven user 32 10月2 07:51 test.txt
-rw-r--r-- 1 keven user 0 9月30 08:54 test1
-rw-r--r-- 1 keven user 0 9月30 08:54 test2
-rw-r--r-- 1 keven user 0 9月30 08:54 test3
# sort -rn +4 list -o tt.txt //翻轉排序頭4個字符
# ls
list ok.txt ss test.txt test1 test2 test3 tt.txt
# cat tt.txt
-rw-r--r-- 1 keven user 32 10月2 07:51 test.txt
-rw-r--r-- 1 keven user 0 9月30 08:54 test3
-rw-r--r-- 1 keven user 0 9月30 08:54 test2
-rw-r--r-- 1 keven user 0 9月30 08:54 test1
#sort +5M +6n list -o up.txt
選項描述
-n 進行數字排序,n可以單獨和短橫線連接,或者可以跟著一個區域參數
(+|-)n 以第n個分隔符的區域開始或結束。默認的分割符是空格
-r 翻轉排序的順序。 r可以單獨與短橫線連用,或者可以跟著一個區域參數
-f 在排列中忽略大小寫
+nM 把開始的三個字符做為月份名稱的簡寫來排序
-d 使用字典排序,只用字母和空格排序,其它的符號忽略
-o filename 把所有輸出放到文件名中
-n 進行數字排序,n可以單獨和短橫線連接,或者可以跟著一個區域參數
(+|-)n 以第n個分隔符的區域開始或結束。默認的分割符是空格
-r 翻轉排序的順序。 r可以單獨與短橫線連用,或者可以跟著一個區域參數
-f 在排列中忽略大小寫
+nM 把開始的三個字符做為月份名稱的簡寫來排序
-d 使用字典排序,只用字母和空格排序,其它的符號忽略
-o filename 把所有輸出放到文件名中
who
# who
root console 10月2 19:23 (:0) (本地登入)
wing pts/2 10月2 19:22 (192.168.0.1)(遠端登入)
# who -q //登入用戶統計
root wing
# users=2
root wing
# users=2
# who -r //運行等級
. run-level 3 10月2 19:20 3 0 S
. run-level 3 10月2 19:20 3 0 S
$ who -Hu
NAME LINE TIME IDLE PID COMMENTS
keven pts/2 10月12 10:57 . 389 (192.168.0.1)
user pts/3 10月12 10:16 0:52 368 (192.168.0.1)
PID為用戶登入上來的程序
NAME LINE TIME IDLE PID COMMENTS
keven pts/2 10月12 10:57 . 389 (192.168.0.1)
user pts/3 10月12 10:16 0:52 368 (192.168.0.1)
PID為用戶登入上來的程序
#kill -9 368 //把此用戶踢出
$ who
root console 10月3 19:21 (:0)
keven pts/6 10月3 22:11 (192.168.0.1)
wing pts/2 10月3 22:11 (192.168.0.1)
cole pts/3 10月3 22:11 (192.168.0.1)
root console 10月3 19:21 (:0)
keven pts/6 10月3 22:11 (192.168.0.1)
wing pts/2 10月3 22:11 (192.168.0.1)
cole pts/3 10月3 22:11 (192.168.0.1)
w
$w
下午11點01分運行 3:43, 4 users, 平均負載:0.00, 0.00, 0.02
用戶名 終端機 登入時間 閒置 JCPU PCPU 執行命令
root console 下午7點21分 3:40 10 1 /usr/dt/bin/dtscreen -mode blank
keven pts/6 下午10點11分 -csh
wing pts/2 下午10點11分5 w
cole pts/3 下午10點11分50 -ksh
$w
下午11點01分運行 3:43, 4 users, 平均負載:0.00, 0.00, 0.02
用戶名 終端機 登入時間 閒置 JCPU PCPU 執行命令
root console 下午7點21分 3:40 10 1 /usr/dt/bin/dtscreen -mode blank
keven pts/6 下午10點11分 -csh
wing pts/2 下午10點11分5 w
cole pts/3 下午10點11分50 -ksh
$ w keven
下午11點10分運行 3:52, 4 users, 平均負載:0.00, 0.00, 0.02
用戶名 終端號 登入時間 閒置 JCPU PCPU 執行命令
keven pts/6 下午10點11分 9 -csh
logins
# logins
root 0 other 1 Super-User
daemon 1 other 1
bin 2 bin 2
sys 3 sys 3
adm 4 adm 4 Admin
uucp 5 uucp 5 uucp Admin
nuucp 9 nuucp 9 uucp Admin
smmsp 25 smmsp 25 SendMail Message Submission Program
listen 37 adm 4 Network Admin
lp 71 lp 8 Line Printer Admin
wing 1001 adm 4 my wife
keven 1002 user 100
user1 1003 adm 4
user2 1004 adm 4
cole 1005 adm 4
nobody 60001 nobody 60001 Nobody
noaccess 60002 noaccess 60002 No Access User
nobody4 65534 nogroup 65534 SunOS 4.x Nobody
# logins
root 0 other 1 Super-User
daemon 1 other 1
bin 2 bin 2
sys 3 sys 3
adm 4 adm 4 Admin
uucp 5 uucp 5 uucp Admin
nuucp 9 nuucp 9 uucp Admin
smmsp 25 smmsp 25 SendMail Message Submission Program
listen 37 adm 4 Network Admin
lp 71 lp 8 Line Printer Admin
wing 1001 adm 4 my wife
keven 1002 user 100
user1 1003 adm 4
user2 1004 adm 4
cole 1005 adm 4
nobody 60001 nobody 60001 Nobody
noaccess 60002 noaccess 60002 No Access User
nobody4 65534 nogroup 65534 SunOS 4.x Nobody
last
$ last //當前系統的使用者登入歷史
keven pts/2 192.168.0.1 Mon Oct 6 00:55 仍在登錄狀態
cole pts/6 192.168.0.1 Mon Oct 6 00:52 仍在登錄狀態
root console :0 Mon Oct 6 00:44 仍在登錄狀態
wing pts/3 192.168.0.1 Mon Oct 6 00:21 仍在登錄狀態
keven pts/2 192.168.0.1 Mon Oct 6 00:21 - 00:55 (00:34)
reboot system boot Mon Oct 6 00:20
keven pts/2 192.168.0.1 Sun Oct 5 19:47 - 20:02 (00:14)
reboot system boot Sun Oct 5 19:46
wing pts/1 192.168.0.1 Sun Oct 5 07:47 - 07:48 (00:00)
keven pts/1 192.168.0.1 Sun Oct 5 06:24 - 07:47 (01:23)
root console :0 Sun Oct 5 06:22 - 07:48 (01:25)
keven pts/1 192.168.0.1 Sun Oct 5 06:21 - 06:24 (00:02)
reboot system boot Sun Oct 5 06:21
cole pts/6 192.168.0.1 Sun Oct 5 01:58 - 03:09 (01:11)
wing pts/5 192.168.0.1 Sun Oct 5 01:58 - 03:10 (01:11)
finger
# finger
Login Name TTY Idle When Where
root Super-User console Thu 19:23 :0
wing my wife pts/2 Thu 19:22 192.168.0.1
$ finger -s keven //指定查看的使用者
Login Name TTY Idle When Where
keven admin pts/6 11 Fri 22:11 192.168.0.1
$ finger @www //查看一台主機的登入狀況,www為主機名
[www]
Login Name TTY Idle When Where
root Super-User console 1 Fri 19:21 :0
keven admin pts/6 13 Fri 22:11 192.168.0.1
#finger -s username@hostname
#finger @webserver.com
#finger username@webserver.com
$ finger -l keven //長格式顯示
Login name: keven In real life: admin
Directory: /export/home/keven Shell: /bin/ksh
On since Oct 12 10:16:41 on pts/2 from 192.168.0.1
24 seconds Idle Time
No unread mail
No Plan.
# finger user1
Login name: user1 In real life:
Directory: /export/home/wing Shell: /bin/sh
On since Oct 12 11:11:33 on pts/3 from 192.168.0.1
4 minutes 8 seconds Idle Time
No unread mail
No Plan.
# finger
Login Name TTY Idle When Where
root Super-User console Thu 19:23 :0
wing my wife pts/2 Thu 19:22 192.168.0.1
$ finger -s keven //指定查看的使用者
Login Name TTY Idle When Where
keven admin pts/6 11 Fri 22:11 192.168.0.1
$ finger @www //查看一台主機的登入狀況,www為主機名
[www]
Login Name TTY Idle When Where
root Super-User console 1 Fri 19:21 :0
keven admin pts/6 13 Fri 22:11 192.168.0.1
#finger -s username@hostname
#finger @webserver.com
#finger username@webserver.com
$ finger -l keven //長格式顯示
Login name: keven In real life: admin
Directory: /export/home/keven Shell: /bin/ksh
On since Oct 12 10:16:41 on pts/2 from 192.168.0.1
24 seconds Idle Time
No unread mail
No Plan.
# finger user1
Login name: user1 In real life:
Directory: /export/home/wing Shell: /bin/sh
On since Oct 12 11:11:33 on pts/3 from 192.168.0.1
4 minutes 8 seconds Idle Time
No unread mail
No Plan.
$ finger -m //只搜索登陸的用戶名
# man -l uname //輸出該命令的位址
uname (1) -M /usr/share/man
uname (2) -M /usr/share/man
NAME
man - find and display reference manual pages
SYNOPSIS
man [-] [-adFlrt] [-M path] [-T macro-package] [-s section]
name...
man [-] [-adFlrt] [-M path] [-T macro-package] [-s section]
name...
man [-M path] -k keyword...
man [-M path] -f file...
id
# id
uid=0(root) gid=1(other) //為當前用戶的ID,而不是原始登入ID
# id
uid=0(root) gid=1(other) //為當前用戶的ID,而不是原始登入ID
who i am
# who i am //真實的UID
root console Oct 2 19:23 (:0)
wing pts/2 Oct 2 19:41 (192.168.0.1)
# who i am //真實的UID
root console Oct 2 19:23 (:0)
wing pts/2 Oct 2 19:41 (192.168.0.1)
df -k
# df -k
Filesystem kbytes used avail capacity Mounted on
/dev/dsk/c0d0s0 63127 36137 20678 64% /
/dev/dsk/c0d0s6 1201014 768820 372144 68% /usr
/proc 0 0 0 0% /proc
mnttab 0 0 0 0% /etc/mnttab
fd 0 0 0 0% /dev/fd
/dev/dsk/c0d0s3 55047 25063 24480 51% /var
swap 608948 24 608924 1% /var/run
swap 609216 292 608924 1% /tmp
/dev/dsk/c0d0s5 24239 15 21801 1% /opt
/dev/dsk/c0d0s7 2691830 112 2637882 1% /export/home
/dev/dsk/c0d0s1 462639 306816 109560 74% /usr/openwin
du -k
#du -k /export //遞歸顯示資料夾中的檔案或資料夾
# du -sk /etc 查看目錄的使用情況總統計
# du -k /etc 逐個查看
# du -k /export | sort -n 可以迅速發現那個目錄是最大的。
# df -k
Filesystem kbytes used avail capacity Mounted on
/dev/dsk/c0d0s0 63127 36137 20678 64% /
/dev/dsk/c0d0s6 1201014 768820 372144 68% /usr
/proc 0 0 0 0% /proc
mnttab 0 0 0 0% /etc/mnttab
fd 0 0 0 0% /dev/fd
/dev/dsk/c0d0s3 55047 25063 24480 51% /var
swap 608948 24 608924 1% /var/run
swap 609216 292 608924 1% /tmp
/dev/dsk/c0d0s5 24239 15 21801 1% /opt
/dev/dsk/c0d0s7 2691830 112 2637882 1% /export/home
/dev/dsk/c0d0s1 462639 306816 109560 74% /usr/openwin
du -k
#du -k /export //遞歸顯示資料夾中的檔案或資料夾
# du -sk /etc 查看目錄的使用情況總統計
# du -k /etc 逐個查看
# du -k /export | sort -n 可以迅速發現那個目錄是最大的。
vi
vi(文本輸入模式)
命令功能
a 在光標後追加文本
A 在行末追加文本
i 在光標前追加文本
o 在光標下插入新的一行
vi(末行模式)
命令功能
:w 寫緩衝區,保存更改繼續在vi中工作
:w new_filename 把緩衝區寫如new_filename
:wq 或ZZ 寫緩衝區,保存修改,然後退出vi
:q! 不保存修改而退出
:wq! 寫緩衝區保存修改然後推出vi,如果你是文件的所有者將忽略只讀屬性
e! 取消自上次保存以來所做的修改
等價於:wq! wq
u 取消最近的一次編輯
vi(命令模式)
命令功能
j(或向下箭頭) 向下移動一行
k(或向上箭頭) 向上移動一行
h(或向左箭頭) 向後移動一個字符
l(或向右箭頭) 向前移動一個字符
空格向右移動一個字符
w 向前移動一個單詞(包括標點)
b 向後移動一個單詞(包括標點)
$ 移動到行末
0(零)或^ 移動到行首
Enter移動到下一行首
命令功能
j(或向下箭頭) 向下移動一行
k(或向上箭頭) 向上移動一行
h(或向左箭頭) 向後移動一個字符
l(或向右箭頭) 向前移動一個字符
空格向右移動一個字符
w 向前移動一個單詞(包括標點)
b 向後移動一個單詞(包括標點)
$ 移動到行末
0(零)或^ 移動到行首
Enter移動到下一行首
vi(命令模式和末行模式)
命令功能
x (小寫) 刪除光標處字符
dw 刪除單詞
3dw 刪除三個單詞
dd 刪除光標所在的行
3dd 刪除三行
yy 拉出一行拷貝,放到剪貼板中
p(小寫) 把拉出行放到當前之下
P(大寫) 把拉出行放到當前之上
:set nu 顯示行號
:set nonu 隱藏行號
:set showmode 顯示當前操作模式(如用vedit將自動打開)
:set noshowmode 關閉模式顯示
:set 顯示所有vi變量
:set all 顯示所有可能的vi變量和它們的當前的值
G 到達文件的最後一行
:21 到達第21行
/string 向前搜索字符串string
? string 向後搜索字符串string
n 查找匹配的下一個字符串
命令功能
x (小寫) 刪除光標處字符
dw 刪除單詞
3dw 刪除三個單詞
dd 刪除光標所在的行
3dd 刪除三行
yy 拉出一行拷貝,放到剪貼板中
p(小寫) 把拉出行放到當前之下
P(大寫) 把拉出行放到當前之上
:set nu 顯示行號
:set nonu 隱藏行號
:set showmode 顯示當前操作模式(如用vedit將自動打開)
:set noshowmode 關閉模式顯示
:set 顯示所有vi變量
:set all 顯示所有可能的vi變量和它們的當前的值
G 到達文件的最後一行
:21 到達第21行
/string 向前搜索字符串string
? string 向後搜索字符串string
n 查找匹配的下一個字符串
cpio
#cpio -idcmv < lnx_902_disk1.cpio 解壓縮
tar
# tar cvf backup.tar list ok.txt test.txt //備份生成backup.tar
a list 1K
a ok.txt 1K
a test.txt 1K
#tar rvf backup.tar tt.txt //追加tt.txt到backu.tar中去
# tar cvf backup.tar tt.txt //注意會覆蓋backup.tar原有的文件
a tt.txt 1K
# tar cvf /export/home/wing/mywife.tar ok2.txt ss // 備份到另一個目錄
# tar xvf backup.tar //全部還原出來
# tar cvf backup.tar list ok.txt test.txt //備份生成backup.tar
a list 1K
a ok.txt 1K
a test.txt 1K
#tar rvf backup.tar tt.txt //追加tt.txt到backu.tar中去
# tar cvf backup.tar tt.txt //注意會覆蓋backup.tar原有的文件
a tt.txt 1K
# tar cvf /export/home/wing/mywife.tar ok2.txt ss // 備份到另一個目錄
# tar xvf backup.tar //全部還原出來
# tar xvf backup.tar tt.txt //把指定的文件還原出來
tar: block大小= 4
x tt.txt, 290 bytes, 1 tape blocks
# tar tvf backup.tar //查看裡面被壓縮了的文件名,並沒有解壓出來
tar: block大小= 4
-rw-rw-rw- 1002/1 290 2003 10月3 02:10 tt.txt
$tar uf myarch mydir //tar將比較每個存檔文件和用戶目錄中文件的最近更新時間,然後將任何自從上次存檔以來所改變的文件拷貝到檔案中
tar: block大小= 4
x tt.txt, 290 bytes, 1 tape blocks
# tar tvf backup.tar //查看裡面被壓縮了的文件名,並沒有解壓出來
tar: block大小= 4
-rw-rw-rw- 1002/1 290 2003 10月3 02:10 tt.txt
$tar uf myarch mydir //tar將比較每個存檔文件和用戶目錄中文件的最近更新時間,然後將任何自從上次存檔以來所改變的文件拷貝到檔案中
參數說明
c 建立一個新的tar文件
t 列出tar文件的內容
x 從tar文件中解壓出指定的文件
r 向已有的tar文件追加一個新文件進去
f 指定文件名
v 詳細模式
m 將在從一個檔案中抽取文件時,不要給它新的時間戳記
compress
# compress -v kk.txt mm.txt
kk.txt: 壓縮:58.18% -- 用kk.txt.Z替換//注意原來的文件將被.Z所替代
mm.txt: 壓縮:1.33% -- 用mm.txt.Z替換
# ls
err.txt kk.txt.Z mm.txt.Z tt.txt
# uncompress -v ok2.txt.Z //解壓縮,注意原來的.Z文件將被ok2.txt替代
# uncompress -c test1.Z|more //只是查看文件的內容,沒有解壓出來
zip
#zip winzip test1.txt test2.txt //生成winzip.zip文件
#unzip winzip.zip //解壓縮
#zip winzip test1.txt test2.txt //生成winzip.zip文件
#unzip winzip.zip //解壓縮
gzip
# gzip -v test2 test3
test2: 0.0% -- replaced with test2.gz//注意把原來的給替換了
test3: 0.0% -- replaced with test3.gz
# ls
test2.gz test3.gz
# gzip -v test2 test3
test2: 0.0% -- replaced with test2.gz//注意把原來的給替換了
test3: 0.0% -- replaced with test3.gz
# ls
test2.gz test3.gz
gunzip
#gunzip test2.gz
#gunzip test2.gz
gzcat
#gzcat tt.txt.gz
-rw-r--r-- 1 keven user 32 10月2 07:51 test.txt
-rw-r--r-- 1 keven user 0 9月30 08:54 test3
-rw-r--r-- 1 keven user 0 9月30 08:54 test2
-rw-r--r-- 1 keven user 0 9月30 08:54 test1
#gzcat tt.txt.gz
-rw-r--r-- 1 keven user 32 10月2 07:51 test.txt
-rw-r--r-- 1 keven user 0 9月30 08:54 test3
-rw-r--r-- 1 keven user 0 9月30 08:54 test2
-rw-r--r-- 1 keven user 0 9月30 08:54 test1
用戶和權限
chmod
#chmod u+r test.txt
#chmod go+rw test.txt
#chmod ow test.txt
#chmod 555 test.txt
#chmod +t dir //粘帶位權限
#chmod g+s file.txt //setuid
#chmod u+s file.txt //setgid
chown
#chown new_owner filename
#chown -R new_owner directoryname
#chown new_owner filename
#chown -R new_owner directoryname
chgrp
#chgrp new_group filename
#chgrp -R new_group filename
nice
#nice -20 dtterm //優先級增加到20 數值越大優先級越高
#nice --20 dtterm //優先級減少到20
#chgrp new_group filename
#chgrp -R new_group filename
nice
#nice -20 dtterm //優先級增加到20 數值越大優先級越高
#nice --20 dtterm //優先級減少到20
groups
$ groups //顯示自己所在的群組
adm
$ groups root //顯示該用戶屬於什麼群組
other root bin sys adm uucp mail tty lp nuucp daemon
$ groups //顯示自己所在的群組
adm
$ groups root //顯示該用戶屬於什麼群組
other root bin sys adm uucp mail tty lp nuucp daemon
newgrp
$newgrp adm //切換到其它的群組
umask
% umask
22
起始權限-想得到的權限=umask值
% umask
22
起始權限-想得到的權限=umask值
useradd
#useradd user3
#useradd -u 1006 -g 4 -d /export/home/user3 -s /bin/sh -c “web user” user3 //完整的添加使用者
#useradd -u 1006 -g 4 -d /export/home/user3 -m -s /bin/sh -c “web user” user3 //建立用戶的同時建立家目錄文件
參數說明
-c 對每個使用者的註釋,記錄每個使用者的個人訊息
-d 使用者家目錄路徑
-m 用來建立使用者的主目錄,通常與-d路徑名一起用
-g 使用者的默認組
-g 使用者的默認gid
-e 帳號不再有效,通常在建立臨時帳號用
-f 許可使用者的最大閒置天數,在建立臨時帳號時用到
-u 使用者的uid
-s 使用者的shell路徑
-c 對每個使用者的註釋,記錄每個使用者的個人訊息
-d 使用者家目錄路徑
-m 用來建立使用者的主目錄,通常與-d路徑名一起用
-g 使用者的默認組
-g 使用者的默認gid
-e 帳號不再有效,通常在建立臨時帳號用
-f 許可使用者的最大閒置天數,在建立臨時帳號時用到
-u 使用者的uid
-s 使用者的shell路徑
userdel
#userdel user7 //把user7刪除,但是不刪家目錄
#userdel -r username //把家目錄一起刪除
#userdel user7 //把user7刪除,但是不刪家目錄
#userdel -r username //把家目錄一起刪除
usermod
# usermod -u 1005 -c adminisrator cole //修改使用者的一些訊息
#usermod -G group1 ,group2 username //把使用者添加到多個群組
# usermod -G sys,sysadmin cole
# groups cole
mail sys sysadmin
# usermod -g apache cole //主要群組
# groups cole
apache
# usermod -u 1005 -c adminisrator cole //修改使用者的一些訊息
#usermod -G group1 ,group2 username //把使用者添加到多個群組
# usermod -G sys,sysadmin cole
# groups cole
mail sys sysadmin
# usermod -g apache cole //主要群組
# groups cole
apache
passwd
#passwd -f user //下次登入時強制其變更密碼
#passwd user //修改其密碼
#passwd -l user //鎖住使用者使其不能登入
#passwd -x 30 user //密碼有效期為30天
#passwd -w 3 user //密碼失效的前3天提醒使用者修改
#passwd -f user //下次登入時強制其變更密碼
#passwd user //修改其密碼
#passwd -l user //鎖住使用者使其不能登入
#passwd -x 30 user //密碼有效期為30天
#passwd -w 3 user //密碼失效的前3天提醒使用者修改
groupadd
# groupadd -g 2000 usergroup
# groupadd -g 2000 usergroup
groupdel
#groupdel groupname
#groupdel groupname
groupmod
#groupmod -n newname oldname
#groupmod -g gid groupname //修改其gid
#groupmod -g gid -n newname oldname
#groupmod -n newname oldname
#groupmod -g gid groupname //修改其gid
#groupmod -g gid -n newname oldname
程序管理
ps
字段概述:
F十六進制標誌,它們加起來表示進程的當前狀態。
如下所述:
00 進程終止,而且它們在進程表中的空間已釋放。
01 系統進程,長駐內存
02 進程被父進程跟踪
04 進程被父進程跟踪而且已被停止
08 該進程無法被信號量喚醒
10 該進程當前在記憶中,而且被鎖定直到一個事件完成
20 進程不能被交換出
F十六進制標誌,它們加起來表示進程的當前狀態。
如下所述:
00 進程終止,而且它們在進程表中的空間已釋放。
01 系統進程,長駐內存
02 進程被父進程跟踪
04 進程被父進程跟踪而且已被停止
08 該進程無法被信號量喚醒
10 該進程當前在記憶中,而且被鎖定直到一個事件完成
20 進程不能被交換出
S 進程當前狀態,由以下字母之一顯示:
O 當前正在處理器上運行
S 睡眠;等待I/O事件完成
R 運行結束I 空閒;進程被建立
Z 僵死。進程已終止
T由於父進程跟踪而停止
X 等待更多的內存
UID進程所有者的用戶ID
PID進程ID
PPID父進程ID
C 進程的CPU使用情況(即進程佔CPU時間的百分比)
PRI 進程優先權方案。較大的數表示較低的優先權
NI 進程的nice值,該值與優先權方案相關聯。
沒有留言:
張貼留言