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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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 - 119 results
netstat -n | grep ESTAB |grep :80 | tee /dev/stderr | wc -l
2016-06-26 11:37:19
User: rubenmoran
Functions: grep netstat tee wc

Summarize established connections after netstat output.

Using tee and /dev/stderr you can send one command output to terminal before executing wc so you can summarize at the bottom of the output.

netstat -np | grep -v ^unix
2015-11-09 17:22:30
User: UnklAdM
Functions: grep netstat

I often have to google this so I put it here for quick reference.

netstat -anp | grep :80 | grep ESTABLISHED | wc -l
2015-04-10 19:32:31
User: krizzo
Functions: grep netstat wc
Tags: session

This counts all established sessions on port 80. You can change :80 to any port number you want to check.

sudo netstat -tulpn | grep :8080
netstat -nr|egrep -v "Routing|Interface|lo0"|awk '{print $5}'|sort -u| while read l; do ifconfig $l ; echo " Station Addr: `lanscan -ia|grep "$l "|cut -d ' ' -f 1`" ; done
netstat -anp | grep ":<port>"
netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head
netstat -tlpn | sort -t: -k2 -n
2014-07-22 14:08:01
User: hute37
Functions: netstat sort
Tags: netstat

Show TCP Listen ports sorted by number

(bugs: IPV6 addresses not supported)

netstat -lptu | grep -E "22.*ESTABLISHED" | cut -s -d ':' -f2 | awk '{print $2}'
2014-06-13 08:38:16
User: DarkXDroid
Functions: awk cut grep netstat

Show If Someone Is Connected To The Android Device On And Get Their IP Address

netstat -pnut -W | column -t -s $'\t'
2014-05-03 00:48:53
User: Nadiar
Functions: column netstat

This takes all of the tab spaces, and uses column to put them into the appropriately sized table.

netstat -tn 2>/dev/null | grep ':80 ' | awk '{print $5}' |sed -e 's/::ffff://' | cut -f1 -d: | sort | uniq -c | sort -rn | head
2014-03-12 12:43:07
User: copocaneta
Functions: awk cut grep netstat sed sort uniq

IP addresses and number of connections connected to port 80.

netstat -tunlapo
2014-01-23 20:44:31
User: treebeard
Functions: netstat
Tags: netstat

-t TCP

-u UDP

-n NO DNS resolution or PORT/SERVICE resolution

-l state

-a ?

-p PORT show

-o flag (keepalive, off, etc)

netstat -t -u -l
2014-01-23 05:01:46
User: prasad
Functions: netstat

This command show listening sockets TCP and UDP. Useful for stop unwanted services from linux.

netstat -tup -W | column -t
2014-01-08 22:39:01
User: b_t
Functions: column netstat

The -W switch of netstat makes it print complete URL of the connections, which otherwise by default

is truncated to fit its default column size.

Now to compensate for irregular column sizes, pipe the output to column (-t switch of column prints in tabular form). The only downside to this part is that the very first row, the header, goes pear shape.

netstat -np --inet|awk '/firefox/{split($5,a,":");z[a[1]]++} END{for(i in z){system("whois " i)}}'|less
netstat -lntp
netstat -tln | grep :25
2013-11-12 16:47:06
User: Peteches
Functions: grep netstat

netstat will list all open ports on the system, unix sockets, tcp sockets and udp sockets. the t flag limits to tcp ports the l flag limits to listening ports and the n flag disables the translation of port to service ( ie :25 displayed instead of :smtp ). then grep for the port you are interested in preceeded by a colon.

netstat -ntu | awk ' $5 ~ /^(::ffff:|[0-9|])/ { gsub("::ffff:","",$5); print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr
2013-09-10 19:28:06
User: mrwulf
Functions: awk cut netstat sort uniq

Same as the rest, but handle IPv6 short IPs. Also, sort in the order that you're probably looking for.

port=32768; while netstat -atn | grep -q :$port; do port=$(expr $port + 1); done; echo $port
sudo netstat -plntu --inet | sort -t: -k2,2n | sort --stable -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | sort -s -t" " -k1,1
2013-08-13 09:21:26
User: thechile
Functions: netstat sort sudo

bit of a contrived example and playing to my OCD but nice for quick scripted output of listening ports which is sorted by port, ip address and protocol.

sudo netstat -tulpn | grep :8080
while true; do netstat -a|grep WAIT|wc -l; sleep 5; done
2013-06-19 09:19:41
User: adimania
Functions: grep netstat sleep wc
Tags: netstat tcp

This has saved me many times while debugging timeout issues to "too many open files" issues. A high number of the order of thousand, indicates that somewhere connection is not being closed properly.

netstat -tn | awk '{print $5}' | egrep -v '(localhost|\*\:\*|Address|and|servers|fff|127\.0\.0)' | sed 's/:[0-99999999].*//g'
2013-06-13 14:35:38
User: kehansen
Functions: awk egrep netstat sed

I used this to get all the remote connection ip addresses connected to my server... I had to start storing and tracking this data so thats why i built this out... probably not optimal as far as the egrep regex but it works ;)

netstat -tuapen | grep LISTEN
netstat -nlput