Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 ?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

You could try perl instead:

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

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

share|improve this answer
    
this is where I went wrong, thank you :) –  Lucas Kauffman Aug 6 '11 at 12:59
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.