Hide

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands tagged Network from sorted by
Terminal - Commands tagged Network - 115 results
sudo tcpdump -i wlan0 -n ip | awk '{ print gensub(/(.*)\..*/,"\\1","g",$3), $4, gensub(/(.*)\..*/,"\\1","g",$5) }' | awk -F " > " '{print $1"\n"$2}'
curl ip.telize.com
2014-02-04 12:25:52
User: fcambus
0

ip.telize.com (Listen on both IPv4 and IPv6)

ip4.telize.com (Listen on IPv4 only)

ip6.telize.com (Listen on IPv6 only)

More information on : http://www.telize.com

nc -zv localhost 25
2013-11-21 22:04:00
User: toaster
0

Using netcat (nc)

25 can be replaced with the friendly value (smtp). Check error code for result or use -v option to echo output

nc -z localhost smtp && echo open || echo closed

nc -zv host protocol

netstat -lntp
sudo lsof -iTCP:25
sudo lsof -iTCP:25 -sTCP:LISTEN
netstat -tln | grep :25
2013-11-12 16:47:06
User: Peteches
Functions: grep netstat
0

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.

(echo >/dev/tcp/localhost/25) &>/dev/null && echo "TCP port 25 open" || echo "TCP port 25 close"
2013-11-12 02:11:01
User: YouM
Functions: echo
0

Check trough unix sockets if tcp port is open or close

tcpdump host <IP> -nXXv -s0 -w file.pcap
while curl -dsL example.com 2>&1 | grep 503;do sleep 8;done;echo server up
while true; do curl -vsL -o /dev/null example.com 2>&1 | grep 503 > /dev/null || echo "OK: server is up."; sleep 8; done
curl l2.io/ip
ifdata -pN eth0
ifconfig -a | awk '/Bcast/{print $2}' | cut -c 5-19
ifconfig -a | awk '/Bcast/{print $2}' | cut -c 5-19
ip -o -4 addr show | awk -F '[ /]+' '/global/ {print $4}'
2013-04-09 16:34:39
User: atoponce
Functions: awk
1

Why use many different utilities all piped together, when you only need two?

curl http://ipecho.net/plain
sudo nethogs eth0
ifconfig eth0 | grep HW | cut -d " " -f 11
remserial -d -p 23000 -s "115200 raw" /dev/ttyS0 &
2012-11-19 17:56:02
User: phattmatt
1

Requires software found at: http://lpccomp.bc.ca/remserial/

Remote [A] (with physical serial port connected to device)

./remserial -d -p 23000 -s "115200 raw" /dev/ttyS0 &

Local [B] (running the program that needs to connect to serial device)

Create a SSH tunnel to the remote server:

ssh -N -L 23000:localhost:23000 user@hostwithphysicalserialport

Use the locally tunnelled port to connect the local virtual serial port to the remote real physical port:

./remserial -d -r localhost -p 23000 -l /dev/remser1 /dev/ptmx &

Example: Running minicom on machine B using serial /dev/remser1 will actually connect you to whatever device is plugged into machine A's serial port /dev/ttyS0.

telnet 0 <port>
2012-11-16 03:38:49
User: somaddict
Functions: telnet
0

Super fast way to ftp/telnet/netcat/ssh/ping your loopback address for testing. The default route 0.0.0.0 is simply reduced to 0.

sudo tc qdisc add dev lo root netem delay 500ms
2012-11-05 05:29:51
User: caiosba
Functions: sudo
Tags: Network delay tc
7

Replace 500ms by the desired delay.

To remove it: sudo tc qdisc del dev lo root netem delay 500ms

echo foo | ncat [ip address] [port]
2012-10-26 10:53:47
User: dragonauta
Functions: echo
-1

you can use a pair of commands to test firewalls.

1st launch this command at destination machine

ncat -l [-u] [port] | cat

then use this command at source machine to test remote port

echo foo | ncat [-u] [ip address] [port]

First command will listen at specified port.

It will listen TCP. If you use -u option will listen UDP.

Second command will send "foo" through ncat and will reach defined IP and port.

for i in `ls /sys/class/net/`; do echo $i: `cat /sys/class/net/$i/operstate`; done
2012-10-15 18:20:37
User: dragonauta
Functions: echo
Tags: Network device
0

no need for installing mii-tools, all generic tools

working under archlinux.

curl -s mi-ip.net | grep '"ip"' | cut -f2 -d ">" | egrep -o '[0-9.]+'
2012-10-15 16:48:20
User: dragonauta
Functions: cut egrep grep
0

looks at html for "ip" (it's a CSS class), then a little of cut and egrep to get IPv4 address.

I use this oneliner into conky.