0

I wanted to write a grep function to show me all listening ports on my host.

I know how to do it by using the -i function in grep :

netstat -a |egrep -i 'listen'

But now I wanted to write it in regex :

netstat -a |egrep 'm/listen/i'

I thought : m because netstat outputs multiple lines and i because it is LISTEN, so I wanted case insensivety.

However this does not give any output. What am I doing wrong ?

womble
  • 97,049

2 Answers2

5

You can show all listening ports with:

netstat --protocol=ip -nlp

About your command, grep works line by line. Where did you read this syntax, it seems belong to sed.

quanta
  • 51,798
2

You could try perl instead:

netstat -an | perl -n -e 'print m/listen/i'

I like the netstat solution. 1 Command done and dusted.

gm3dmo
  • 10,257