亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区
Chinaunix
標題:
如何統(tǒng)計文本中字符串出現(xiàn)的數(shù)量
[打印本頁]
作者:
338378WN8
時間:
2015-07-03 10:20
標題:
如何統(tǒng)計文本中字符串出現(xiàn)的數(shù)量
一臺服務器,一直報打開文件數(shù)過多。
想寫個腳本用lsof命令查找是那個用戶哪個進程打開的文件數(shù)最多。
比如lsof出現(xiàn)的信息如下
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
init 1 root cwd DIR 8,2 4096 2 /
init 1 root rtd DIR 8,2 4096 2 /
init 1 root txt REG 8,2 43496 415811 /sbin/init
init 1 root mem REG 8,2 139416 575728 /lib64/ld-2.5.so
init 1 root mem REG 8,2 1717800 575729 /lib64/libc-2.5.so
init 1 root mem REG 8,2 23360 575731 /lib64/libdl-2.5.so
init 1 root mem REG 8,2 247496 575745 /lib64/libsepol.so.1
init 1 root mem REG 8,2 95464 575746 /lib64/libselinux.so.1
init 1 root 10u FIFO 0,17 2769 /dev/initctl
migration 2 root cwd DIR 8,2 4096 2 /
migration 2 root rtd DIR 8,2 4096 2 /
migration 2 root txt unknown /proc/2/exe
ksoftirqd 3 root cwd DIR 8,2 4096 2 /
ksoftirqd 3 root rtd DIR 8,2 4096 2 /
ksoftirqd 3 root txt unknown /proc/3/exe
migration 4 root cwd DIR 8,2 4096 2 /
migration 4 root rtd DIR 8,2 4096 2 /
migration 4 root txt unknown /proc/4/exe
ksoftirqd 5 root cwd DIR 8,2 4096 2 /
ksoftirqd 5 root rtd DIR 8,2 4096 2 /
ksoftirqd 5 root txt unknown /proc/5/exe
events/0 6 root cwd DIR 8,2 4096 2 /
events/0 6 root rtd DIR 8,2 4096 2 /
events/0 6 root txt unknown /proc/6/exe
events/1 7 root cwd DIR 8,2 4096 2 /
events/1 7 root rtd DIR 8,2 4096 2 /
那有什么方法可以自動計算每個進程打開了多少文件,并根據(jù)打開文件的數(shù)量自動排序?
作者:
338378WN8
時間:
2015-07-03 10:32
自己能想得到的是用 lsof |awk '{print $2}'|uniq -c|sort -g
作者:
dn833
時間:
2015-07-03 11:16
awk '{a[$2]++}END{for(i in a)print i,a[i]|"sort -n"}'
復制代碼
作者:
hjfeng1988
時間:
2015-07-03 11:38
統(tǒng)計進程:
awk 'NR>1{a[$1]++}END{for(i in a)print i,a[i]}' file | sort -n -k2,2
復制代碼
統(tǒng)計用戶:
awk 'NR>1{a[$3]++}END{for(i in a)print i,a[i]}' file | sort -n -k2,2
復制代碼
作者:
haooooaaa
時間:
2015-07-03 13:28
本帖最后由 haooooaaa 于 2015-07-03 13:58 編輯
回復
1#
338378WN8
[root@cAdmin 456]# lsof | awk 'function f(d){for(i in d){printf "%-18s %-10s\n",i,d[i] | "sort -k2nr"};close("sort -k2nr");print "=================="}NR>1&&$5!~/unknown/{p[$1]++;u[$3]++}END{f(u);f(p)}'
root 729
postfix 92
haldaemon 53
dbus 25
rpc 24
rpcuser 24
==================
master 126
sshd 96
cupsd 57
mingetty 48
pickup 46
qmgr 46
udevd 46
hald 37
automount 36
hald-addo 35
lsof 26
dbus-daem 25
rpcbind 24
復制代碼
作者:
338378WN8
時間:
2015-07-03 14:17
回復
4#
hjfeng1988
嗯,這個好像可以的
作者:
338378WN8
時間:
2015-07-03 14:18
回復
5#
haooooaaa
高手啊,sed我還看得懂,awk基本就抓瞎了。
作者:
Herowinter
時間:
2015-07-03 15:55
回復
7#
338378WN8
理論上來說, awk比較好懂吧,比較接近高級語言的語法.
歡迎光臨 Chinaunix (http://www.72891.cn/)
Powered by Discuz! X3.2