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的通配符

.:任意一个字符

 

*:任意多个字符

Shell代码   收藏代码
  1. [root@iZ25tti3rxdZ tem]# cat b.txt   
  2. abc  
  3. def  
  4. syn.c  
  5. synxc  
  6. synxxxxxc  
  7. [root@iZ25tti3rxdZ tem]# grep  "syn\.c" ./* --color=auto  
  8. ./b.txt:syn.c  
  9. [root@iZ25tti3rxdZ tem]# grep  "syn.c" ./* --color=auto  
  10. ./b.txt:syn.c  
  11. ./b.txt:synxc  

 

 

(4)grep 匹配数字

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


相关文章
|
2月前
|
Unix
grep的基本用法
grep的基本用法
19 2
|
2月前
|
Perl
grep的复杂用法
grep的复杂用法
15 3
|
2月前
|
Unix Linux
grep的实战用法
grep的实战用法
22 4
|
2月前
|
Unix Linux
grep的具体用法
grep的具体用法
36 1
|
11月前
grep常见的用法
grep常见的用法
141 0
|
弹性计算 Shell Linux
3天玩转shell--6.sed 和grep用法
本文将通过shell代码示例,简单通俗的讲解shell。通过执行代码和运行结果反向掌握shell编程方法。准备一台低配的阿里云ECS Linux环境,跟着教程走起,本文比较适合shell小白。
157 0
|
索引
$.grep() 的用法
$.grep() 的用法
278 0
$.grep() 的用法
|
机器学习/深度学习 Shell
|
存储 Unix Linux