grep命令常见用法

grep命令常见用法

(1)通过端口号找进程

占用8005端口的进程

netstat -anp |grep ":8005[ ]\+"|awk -F" "   {'print $7'}

 

占用49790端口的进程

netstat -anp |grep ":49790[ ]\+"|awk -F" "   {'print $7'}

 

占用48713端口的进程

netstat -anp |grep ":48713[ ]\+"|awk -F" "   {'print $7'}



 

netstat -anp |grep ":49790[ ]\+"|awk -F" "   {'print $6"\t"$7'}

 

(2)搜索包含关键字的文件

例如搜索包含字符串"syn.c" 的文件:

grep  "syn\.c" /etc/*

注意:句点需要转义

 

[root@iZ25tti3rxdZ tem]# grep  "syn\.c" ./* --color=auto

 

./b.txt:syn.c

(3)grep的通配符

.:任意一个字符

 

*:任意多个字符

[root@iZ25tti3rxdZ tem]# cat b.txt 
abc
def
syn.c
synxc
synxxxxxc
[root@iZ25tti3rxdZ tem]# grep  "syn\.c" ./* --color=auto
./b.txt:syn.c
[root@iZ25tti3rxdZ tem]# grep  "syn.c" ./* --color=auto
./b.txt:syn.c
./b.txt:synxc

 

 

(4)grep 匹配数字

netstat -anp |grep ":8005[ ]\+"|awk -F" "   {'print $6"\t"$7'}|cut -d"/" -f1|grep "[1-9]\+"



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值