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 ifconfig from sorted by
Terminal - Commands tagged ifconfig - 51 results
for i in `lanscan -i | awk '{print $1}'` ; do ifconfig $i ; done 2> /dev/null
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
host `hostname` | rev | cut -d' ' f1 | rev
2014-10-01 18:55:05
Functions: cut host rev
0

Gives the DNS listed IP for the host you're on... or replace `hostname` with any other host

ifconfig | egrep -A2 "eth|wlan" | tr -d "\n"| sed 's/\-\-/\n/g'|awk '{print "mac: "$5 " " $7}' | sed 's/addr:/addr: /g'
ifconfig | head -n 2 | tr -d '\n' | sed -n 's/.*\(00:[^ ]*\).*\(adr:[^ ]*\).*/mac:\1 - \2/p'
ifconfig | egrep [0-9A-Za-z]{2}\(:[0-9A-Za-z]{2}\){5} | awk '{print $1 ":\t" $5}'
2013-07-30 17:02:07
User: jaimeanrm
Functions: awk egrep ifconfig
1

Is the better option on a Open SuSE Box

sudo ifconfig wlan0 | grep inet | awk 'NR==1 {print $2}' | cut -c 6-
2013-02-18 14:10:07
User: mouths
Functions: awk cut grep ifconfig sudo
-1

On wired connections set 'eth0' instead of 'wlan0'

ifconfig | grep inet
2012-12-05 20:54:07
User: Karunamon
Functions: grep ifconfig
Tags: Linux ifconfig
0

Returns the IP, broadcast, and subnet mask of your interfaces absent any other extraneous info.

I know it's a bit lame, but I've created an alias for this when I *quickly* want to know what a system's IP is. Small amounts of time add up :)

ifconfig eth0 | grep HW | cut -d " " -f 11
ifconfig | awk -F"[: ]+" '/inet addr/ {print $4}'
ifconfig | grep "inet" | tail -1 | awk '{print $2}'
ifconfig | grep "inet" | grep "broadcast" | awk '{print $2}'
ifconfig | grep "inet addr" | cut -d":" -f2 | cut -d" " -f1
for i in `netstat -rn|egrep -v "Interface|Routing"|awk '{print $5}'`;do ifconfig $i;done
ifconfig | awk '/inet / {sub(/addr:/, "", $2); print $2}'
watch -n 2 -d '/sbin/ifconfig eth0'
ifconfig | awk '/HWaddr/ { print $1, $5 }'
ifconfig | grep HWaddr | awk '{print $1,$5}'
{ if (/^[A-Za-z0-9]/) { interface=$1; next } else { if (/inet [Aa][d]*r/) { split($2,ip,":") } else { next } } print interface"\t: "ip[2] }
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 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.