What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands using netstat from sorted by
Terminal - Commands using netstat - 117 results
netstat -nt | awk -F":" '{print $2}' | sort | uniq -c
netstat -ntu | awk ' $5 ~ /^[0-9]/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
2011-07-04 20:23:21
User: letterj
Functions: awk cut netstat sort uniq
Tags: netstat

netstat has two lines of headers:

Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address Foreign Address State

Added a filter in the awk command to remove them

netstat -ntu | awk ' $5 ~ /^[0-9]/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
netstat -nt | awk '{print $6}' | sort | uniq -c | sort -n -k 1 -r
netstat -n -f inet|awk '/\.389/{print $2}'|cut -f1-4 -d.|sort -u
watch -n 2 netstat -antu
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
netstat -lnptu
while sleep 1; do date; (netstat -a -n | grep 80) ; done
netstat -a -o -n | grep 8080
2011-04-28 09:58:59
User: evandrix
Functions: grep netstat

I cannot run Tomcat from Eclipse. It says that there?s other process that is running on port 8080, but I don?t know what is the process, and how to stop it from the Services manger in Windows. So here?s how you can kill and find out what is that process:

To find out what PID 8080 was (hopefully not a trojan)

I typed tasklist /FI ?PID eq 8080″

taskkill /F /PID 2600

netstat -tulpnc
2011-04-20 07:30:31
User: altern
Functions: netstat

shows opened ports on machine in continuous mode (refreshing every 10 sec)

(netstat -atn | awk '{printf "%s\n%s\n", $4, $4}' | grep -oE '[0-9]*$'; seq 32768 61000) | sort -n | uniq -u | head -n 1
netstat -atn | perl -ane 'if ( $F[3] =~ /(\d+)$/ ) { $x{$1}=1 } END{ print( (grep {!$x{$_}} 32768..61000)[0] . "\n" )}'
netstat -atn | perl -0777 -ne '@ports = /tcp.*?\:(\d+)\s+/imsg ; for $port (32768..61000) {if(!grep(/^$port$/, @ports)) { print $port; last } }'
2010-12-14 20:44:37
User: bashrc
Functions: last netstat perl

Not really better - just different ;)

There's probably a really simple solution out there somewhere...

netstat -lnp6 | grep :8080 | sed 's#^[^\/]*/\([a-z0-9]*\)#\1#'
2010-11-03 14:11:21
User: cicatriz
Functions: grep netstat sed

Gets the application's name that's listening from the port 8080 through IPv6

netstat -n | grep '^tcp.*<IP>:<PORT>' | tr " " | awk 'BEGIN{FS="( |:)"}{print $6}' | sort | uniq -c | sort -n -k1 | awk '{if ($1 >= 10){print $2}}'
2010-09-16 21:06:30
User: guptavi
Functions: awk grep netstat sort tr uniq

This command is primarily going to work on linux boxes.

and needs to be changed, for example



netstat -rn | awk '/UG/{print $2}'
2010-08-09 15:56:02
User: putnamhill
Functions: awk netstat

Tested on CentOS, Ubuntu, and MacOS.

netstat -rn | grep UG | tr -s " " | cut -d" " -f2
netstat -antp | grep 22
netstat -l -p --tcp | egrep -e 'www.*[0-9]{3,4}\/(apache2|httpd)' | awk '{print$7}'
netstat -an | grep ESTABLISHED | awk '\''{print $5}'\'' | awk -F: '\''{print $1}'\'' | sort | uniq -c | awk '\''{ printf("%s\t%s\t",$2,$1); for (i = 0; i < $1; i++) {printf("*")}; print ""}'\''
2010-07-09 00:25:45
User: mramos
Functions: awk grep netstat sort uniq

Displays a connection histogram of active tcp connections. Works even better under an alias. Thanks @Areis1 for sharing this one.

netstat -tunlp
2010-06-07 13:26:05
User: ender_x
Functions: netstat
Tags: netstat

Shows you all listening tcp/udp ports, and what program has them open(depending on rights)

netstat -an | awk '/tcp/ {print $6}' | sort | uniq -c
2010-05-06 17:04:37
User: Kered557
Functions: awk netstat sort uniq

Counts TCP states from Netstat and displays in an ordered list.

netstat -n | awk '/^tcp/ {++B[$NF]} END {for(a in B) print a, B[a]}'