在日常运维工作中,我们经常需要了解服务器上的系统资源的使用情况,要清楚知道一些重要进程所占的资源比例。这就需要熟练掌握下面几个命令的使用:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
1)查看占用CPU最高的5个进程 # ps aux | sort -k3rn | head -5
或者 # top (然后按下P,注意大写,CPU使用率降序)
2)查看占用内存最高的5个进程 # ps aux | sort -k4rn | head -5
或者 # top (然后按下M,注意大写,内存使用率降序)
3)查看所有信息使用命令 # ps aux
------------------------------ sort | uniq 排序去重
sort | uniq -c 打印重复的次数
sort | uniq -d 打印交集的部分
sort | uniq -u 打印去掉交集的部分
sort -rn 降序
sort -k3rn 按照第三列降序
|
举例如下:
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
32
33
34
35
36
37
38
39
40
41
42
43
|
[root@bastion-IDC ~] # cat a
sdfasasdf 2 3 4 asdfasf asdfsdfasdfasdf [root@bastion-IDC ~] # cat b
adfasf1231 2 3 sdf435 4 [root@bastion-IDC ~] # cat a b|sort|uniq
2 3 4 adfasf1231 asdfasf asdfsdfasdfasdf sdf435 sdfasasdf [root@bastion-IDC ~] # cat a b|sort|uniq -c
2 2 2 3 2 4 1 adfasf1231 1 asdfasf 1 asdfsdfasdfasdf 1 sdf435 1 sdfasasdf [root@bastion-IDC ~] # cat a b|sort|uniq -d
2 3 4 [root@bastion-IDC ~] # cat a b|sort|uniq -u
adfasf1231 asdfasf asdfsdfasdfasdf sdf435 sdfasasdf |