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 - 117 results
python -c "import socket; print '\n'.join(socket.gethostbyname_ex(socket.gethostname())[2])"
2009-04-30 16:10:43
User: haivu
Functions: python
Tags: Network python
-6

The socket.gethostname() call returns the host name of the computer. The socket.gethostbyname_ex() call returns a list of three items: The host name, the list of aliases for this host, and a list of IP addresses. Recall that Python?s array starts with index 0, the socket.gethostbyname_ex(?)[2] expression refers to the list of IP addresses. Finally, the print statement prints out the IP addresses, one per line.

for i in /sys/class/net/*; do e=`basename $i`; echo "# $e"; sudo ethtool $e | grep -E "Link|Speed" ; done
2009-04-25 14:32:08
User: hank
Functions: echo grep sudo
Tags: Network Linux
0

Basically an improvement on an earlier ethtool command line.

lsof -i
/sbin/ifconfig -a | awk '/(cast)/ { print $2 }' | cut -d':' -f2 | head -1
mtr --report --report-cycles 10 www.google.com > google_net_report.txt
2009-04-10 07:57:44
User: CafeNinja
Tags: Network
7

The report mode of mtr produces a text formated result of the mtr run using the number of ping cycles stated by the command. This text file could then be attached to an email with ease.

I use this also without the ">" portion when writing email from within mutt using VI from the command mode with ":r !mtr --report --report-cycles 10

sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"
2009-04-04 01:41:48
User: peterc
Functions: grep sudo tcpdump
-2

Replace "en1" with your network interface (on OS X, usually en0, en1, eth0, etc..)

arp -s $(route -n | awk '/^0.0.0.0/ {print $2}') \ $(arp -n | grep `route -n | awk '/^0.0.0.0/ {print $2}'`| awk '{print $3}')
alias tproxy='ssh -ND 8118 user@server&; export LD_PRELOAD="/usr/lib/libtsocks.so"'
/usr/sbin/arp -i eth0 | awk '{print $3}' | sed 1d
ping -i 60 -a IP_address
2009-03-04 06:21:22
User: haivu
Functions: ping
Tags: Network
99

Waiting for your server to finish rebooting? Issue the command above and you will hear a beep when it comes online. The -i 60 flag tells ping to wait for 60 seconds between ping, putting less strain on your system. Vary it to your need. The -a flag tells ping to include an audible bell in the output when a package is received (that is, when your server comes online).

ping -c 10 hostname
2009-03-04 06:14:52
User: haivu
Functions: ping
Tags: Network
-4

On Linux and Mac systems (I have not tested with other Unix systems), the ping command will keep on pinging until the user interrupts it with Ctrl+C. On Windows system, ping will execute for a number of times then quit. The -c flag on Linux and Mac will make this happen

nc -l -p 2000 -e /bin/bash
2009-03-02 15:58:25
User: prayer
Tags: Network netcat
6

To connect to the shell run:

nc server.example.org 2000
nc -l -p 2000 < song.mp3
nc -l -p 2000 -c "nc example.org 3000"
2009-03-01 21:28:39
User: prayer
Tags: Network netcat
23

Redirect the local port 2000 to the remote port 3000. The same but UDP:

nc -u -l -p 2000 -c "nc -u example.org 3000"

It may be used to "convert" TCP client to UDP server (or viceversa):

nc -l -p 2000 -c "nc -u example.org 3000"
mii-tool [if]
nmap -sS -P0 -sV -O <target>
2009-02-18 07:32:03
User: starchox
Tags: Network net
18

Where < target > may be a single IP, a hostname or a subnet

-sS TCP SYN scanning (also known as half-open, or stealth scanning)

-P0 option allows you to switch off ICMP pings.

-sV option enables version detection

-O flag attempt to identify the remote operating system

Other option:

-A option enables both OS fingerprinting and version detection

-v use -v twice for more verbosity.

nmap -sS -P0 -A -v < target >
vncserver -nohttpd -name hidef-server -depth 24 -geometry 1440x900
2009-02-17 17:50:33
User: starchox
Tags: Network , net
3

-nohttpd don't run mini-httpd if VNC java applet is found

-name change the name of the desktop, it's passed to xstartup script via $VNCDESKTOP, run different set of apps acording the name.

-depth pixel depth in bits of the desktop, default is 16

-geometry size of the desktop, default is 1024x768