grep显示ps输出标题

背景

查找服务器上某个进程详细信息[ps:pid,ppid,内存使用,cpu使用等],常常会使用ps筛选对应的进程,正常情况过滤后信息不会显示ps输出的title。

实操:

1.未显示ps 标题

常规操作:ps aux|grep xx

[rootbird ~]# ps aux | grep libvirt
dnsmasq  2169025  0.0  0.0  71964  2120 ?        S     2021   0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root     2169026  0.0  0.0  71860   428 ?        S     2021   0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root     3040675  0.0  0.0  12108  1068 pts/1    S+   23:09   0:00 grep --color=auto libvirt

2.显示ps 标题

通用法:使用ps的所有参数,例如:ps aux 、ps -ef

ps aux| head -1;ps aux|grep xx  
[rootbird ~]# ps aux |head -1; ps aux| grep libvirt
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
dnsmasq  2169025  0.0  0.0  71964  2120 ?        S     2021   0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root     2169026  0.0  0.0  71860   428 ?        S     2021   0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root     3041792  0.0  0.0  12108  1060 pts/1    S+   23:12   0:00 grep --color=auto libvirt

动态调整,需要根据ps不同参数调整,例如:ps aux 、ps -ef

ps aux|grep -E 'USER|xx'
[rootbird ~]# ps auxw | grep  -E "USER|libvirt"
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
dnsmasq  2169025  0.0  0.0  71964  2120 ?        S     2021   0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root     2169026  0.0  0.0  71860   428 ?        S     2021   0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root     3043012  0.0  0.0  12108  2484 pts/1    S+   23:18   0:00 grep --color=auto -E USER|libvirt
ps -ef|grep -E 'UID|xx'
[rootbird ~]# ps -ef | grep  -E "UID|libvirt"
UID          PID    PPID  C STIME TTY          TIME CMD
dnsmasq  2169025       1  0  2021 ?        00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root     2169026 2169025  0  2021 ?        00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root     3044818 3033179  0 23:26 pts/1    00:00:00 grep --color=auto -E UID|libvirt

实战

查找服务器上进程状况的时候[ps:D,Zone进程],ps aux 与ps -ef配合使用,分别显示各自title显的格外重要

[rootbird ~]# ps -ef | grep  -E "UID|libvirt"
UID          PID    PPID  C STIME TTY          TIME CMD
dnsmasq  2169025       1  0  2021 ?        00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root     2169026 2169025  0  2021 ?        00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root     3044818 3033179  0 23:26 pts/1    00:00:00 grep --color=auto -E UID|libvirt
[rootbird ~]# ps aux | grep  -E "USER|libvirt"
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
dnsmasq  2169025  0.0  0.0  71964  2120 ?        S     2021   0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root     2169026  0.0  0.0  71860   428 ?        S     2021   0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root     3045966  0.0  0.0  12108  2488 pts/1    S+   23:32   0:00 grep --color=auto -E USER|libvirt

-------------------------------------------------工欲善其事,必先利其器--------------------------------------

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李天琦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值