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 using ifconfig from sorted by
Terminal - Commands using ifconfig - 92 results
ifconfig | awk -F':| +' '/ddr:/{print $4}'
2009-07-25 22:51:08
User: 0x89
Functions: awk ifconfig
Tags: Linux ifconfig
1

and, a lot uglier, with sed:

ifconfig | sed -n '/inet addr:/s/[^:]\+:\(\S\+\).*/\1/p'

Edit:

Wanted to be shorter than the perl version. Still think that the perl version is the best..

ifconfig | grep "inet [[:alpha:]]\+" | cut -d: -f2 | cut -d' ' -f2
2009-07-24 13:16:37
User: feraf
Functions: cut grep ifconfig
Tags: Linux ifconfig
-6

Get the IP address of all your network cards.

ifconfig | grep "inet addr" | cut -d: -f2 | cut -d' ' -f1
ifconfig | perl -nle'/dr:(\S+)/ && print $1'
2009-07-23 09:33:31
User: xsawyerx
Functions: ifconfig perl
11

Fetches the IPs and ONLY the IPs from ifconfig. Simplest, shortest, cleanest.

Perl is too good to be true...

(P.S.: credit should go to Peteris Krumins at catonmat.net)

ifconfig $DEVICE | perl -lne '/inet addr:([\d.]+)/ and print $1'
2009-07-21 13:48:19
User: jdob
Functions: ifconfig perl
Tags: IP
-2

Found this useful for scripts where I needed to work with the machine's IP. If $DEVICE is not specified, this will return all IPs on the machine. If $DEVICE is set to a network adapter, it will return just that adapter's IP.

ran=$(head /dev/urandom | md5sum); MAC=00:07:${ran:0:2}:${ran:3:2}:${ran:5:2}:${ran:7:2}; sudo ifconfig wlan0 down hw ether $MAC; sudo ifconfig wlan0 up; echo ifconfig wlan0:0
2009-07-16 16:21:44
User: workingsmart
Functions: echo head ifconfig sudo
7

Next time you are leaching off of someone else's wifi use this command before you start your bittorrent ...for legitimate files only of course.

It creates a hexidecimal string using md5sum from the first few lines of /dev/urandom and splices it into the proper MAC address format. Then it changes your MAC and resets your wireless (wlan0:0).

echo "-------------" >> nicinfo.txt; echo "computer name x" >> nicinfo.txt; ifconfig | grep status >> nicinfo.txt; ifconfig | grep inet >> nicinfo.txt; ifconfig | grep ether >> nicinfo.txt; hostinfo | grep type >> nicinfo.txt;
ifconfig eth0 down hw ether (newmacaddresshere) && ifconfig eth0 up && ifconfig eth0 (newipaddresshere) netmask 255.255.255.0 up && /bin/hostname (newhostnamehere)
2009-06-04 20:25:49
User: localGhost
Functions: ifconfig
-3

The command above has been changed due to very good constructive criticism - thanks x 2! This command can be used after acquiring mac's, ip's and hostname's or any of the above from a freshly scanned LAN. User must be root, and remember to change your settings on your network managing software manually (Fedc10 NetworkManager Applet 0.7.1 is mine) instead of 'auto DHCP'. You can also substitute eth0 for wlan0 etc - be good and ENJOY!

sudo ifconfig eth0 hw ether 00:01:02:03:04:05
2009-06-04 09:02:35
User: momitov
Functions: ifconfig sudo
6

eth0 = the name of the interface

00:01:02:03:04:05 = the new mac adresse

the same thing for wireless card $ sudo iwconfig eth1 hw ether 00:01:02:03:04:05

ifconfig eth0 hw ether 00:11:22:33:44:55
ifconfig en1 | awk '/inet / {print $2}' | mail -s "hello world" email@email.com
2009-04-28 06:01:52
User: rez0r
Functions: awk ifconfig mail
9

This is useful if you have need to do port forwarding and your router doesn't assign static IPs, you can add it to a script in a cron job that checks if you IP as recently changed or with a trigger script.

This was tested on Mac OSX.

while true; do ifconfig eth0 | grep "inet addr:"; sleep 60; done;
2009-04-01 19:29:28
User: bandit36
Functions: grep ifconfig sleep
Tags: script while loop
-5

You can use this to loop any command to periodically see the output.

while true; do [YOUR COMMAND HERE]; sleep [# of seconds]; done;

Alternatively, you can put it in a simple shell script to save typing!

#/!bin/bash

while true; do $1; sleep $2; done;

/path/to/script.sh "ifconfig eth0 | grep 'inet addr:'" 60
while true; do X=$Y; sleep 1; Y=$(ifconfig eth0|grep RX\ bytes|awk '{ print $2 }'|cut -d : -f 2); echo "$(( Y-X )) bps"; done
ifconfig -a | nawk 'BEGIN {FS=" "}{RS="\n"}{ if($1~ /:/) {printf "%s ", $1}}{ if($1=="inet") {print " -- ",system("arp "$2)}}'|egrep -v "^[0-9]$"
2009-03-02 23:15:13
User: leprasmurf
Functions: ifconfig
1

Needed to get the Mac of various devices on a solaris box, but didn't have root. This command used awk to display the Network device, the IP, and the MAC a line at a time.

ifconfig | awk '/inet / {print $2}'
2009-02-27 17:05:08
User: haivu
Functions: awk ifconfig
1

On the Mac, the format ifconfig puts out is little different from Linux: the IP address is space separated, instead of colon. That makes parsing the IP address easier. See releated command for Linux/Unix:

http://www.commandlinefu.com/commands/view/651/getting-the-ip-address-of-eth0

watch ifconfig eth0
ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}'