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 - 94 results
ifconfig | convert label:@- ip.png
ifconfig | awk '/HWaddr/ { print $1, $5 }'
ifconfig | grep HWaddr | awk '{print $1,$5}'
ifconfig eth0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
ifconfig | grep HWaddr
echo | ifconfig | grep HWaddr
localIP() { ifconfig ${1:--a} | sed '/Link encap\|inet\|6 addr/!d;s/Link encap.*$//;s/.*inet addr:\([0-9\.]*\).*/\1/g;s/.*inet6 addr: \(.*\) .*/\1/g' ; }
2011-03-20 04:59:54
User: vando
Functions: ifconfig sed
-2

If you don't send an interface, it shows private IP address of all interfaces

lsmac() { ifconfig -a | sed '/eth\|wl/!d;s/ Link.*HWaddr//' ; }
ifconfig eth3|sed 's/^eth3.*HWaddr //;q'
2011-02-09 00:22:40
User: avedis
Functions: ifconfig sed
Tags: sed
0

Just replace eth3 with the interface you want the MAC for.

ifconfig | grep eth | awk '{print $5}'
2011-02-02 20:42:22
User: diacus
Functions: awk grep ifconfig
-2

This command is useful when you want to check your nic's mac address, if you're interested in your wireless interface, use its ID instead "eth".

This command was tested under Ubuntu and Slackware GNU/Linux.

ifconfig | grep -o "inet [^ ]*" | cut -d: -f2
2010-12-06 10:36:52
User: dooblem
Functions: cut grep ifconfig
Tags: ifconfig grep cut
-2

This is what we use.

You can grep -v 127.0.0.1 if you wish.

ifconfig | sed -ne 's/^.*inet \(addr:\)*\([^ ]*\).*/\2/;te' -e 'd;:e' -e '/^127\./d;p'
2010-12-05 17:14:57
User: dramaturg
Functions: ifconfig sed
Tags: ifconfig sed
0

This also works on non-Linux machines. If you have GNU sed you can do it more elegantly:

ifconfig | sed -n 's/^\s*inet \(addr:\)\?\([^\s]*\) .*/\2/;T;/^127\./d;p'
ifconfig|sed '/inet/!d;/127.0/d;/dr:\s/d;s/^.*:\(.*\)B.*$/\1/'
2010-12-01 21:08:29
User: marssi
Functions: ifconfig sed
Tags: ifconfig sed
1

Shows only IP-addresses of ifconfig except 127.0.0.0/8.

I fixed the script to work on more systems and configs

short info

/inet/!d; #grep inet

/127.0/d; # grep -v 127.0

/dr:\s/d; # grep -v dr:

s/^.*:\(.*\)B.*$/\1/ # remove everything exept between : and B

ifconfig | grep "inet\ " | grep -v "127.0" | sed -e 's/inet\ addr://g' | sed -e 's/Bcast:/\ \ \ \ \ \ \ /g' | cut -c 1-29 | sed -e 's/\ //g'
ifconfig | awk '/^eth0/ {print $5}'
ifconfig eth0 | grep -o "inet [^ ]*" | cut -d: -f2
ifconfig eth0 | awk '/inet / {print $2}' | cut -d ':' -f2
ifconfig eth0 | grep "inet " | cut -d ':' -f2 | awk '{print $1}'
2010-06-29 00:06:08
User: jaimerosario
Functions: awk cut grep ifconfig
3

I've been using it in a script to build from scratch proxy servers.

ifconfig eth0 | grep 'inet addr' | cut -d ':' -f 2 | cut -d ' ' -f 1
2010-06-26 22:36:21
User: atoponce
Functions: cut grep ifconfig
Tags: ifconfig
2

Simple and easy. No regex, no search and replace. Just clean, built-in tools.

ifconfig eth0 | perl -ne "print if m/inet addr:((\d+\.){3})+/" | sed "s/inet addr//" | sed "s/Bcast//" |awk -F: '{print $2}'
2010-06-26 12:07:15
User: aceiro
Functions: awk ifconfig perl sed
0

only output the ip addres. I put double pipe with sed because not parse with operator OR (|) in redex.

ifconfig eth0 | perl -ne 'print $1 if m/addr:((?:\d+\.){3}\d+)/'
ifconfig eth0 | grep 'HWaddr' | awk '{print $5}' | tr 'a-z' 'A-Z' | sed -e 's/://g'
2010-06-26 05:35:03
User: minigeek
Functions: awk grep ifconfig sed tr
-3

This will get the mac address of the eth0 and change lowercase to uppercase.

The sed command removed the colons.

ifconfig eth0 | grep 'HWaddr' | awk '{print $5}'
dhclient wlan0 && sbnt=$(ifconfig wlan0 |grep "inet addr" |cut -d ":" -f 2 | cut -d "." -f 1-3) && nmap $sbnt.0/24 -sP
2010-06-22 21:00:29
User: wltj
Functions: cut grep ifconfig
-1

This is helpful if you connect to several networks with different subnets such as 192 networks, 10 networks, etc. Cuts first three octets of ip from ifconfig command and runs nmap ping scan on that subnet.

Replace wlan0 with your interface. Assumes class c network, if class b use: cut -d "." -f 1-2 and change nmap command accordingly.

UNIQUE_BY_MAC=$(ifconfig |grep eth0|awk '{ print strtonum("0x"substr($6,16,2)) }')
2010-06-01 17:34:43
User: rubo77
Functions: awk grep ifconfig
-3

gets the last number of the mac address to use it for other stuff