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 - 93 results
sudo ifconfig en1 ether 00:e2:e3:e4:e5:e6
2010-03-30 21:48:55
User: rpavlick
Functions: ifconfig sudo
0

If you want to check that the spoof worked, type the same command as earlier:

ifconfig en1 | grep ether

Now you will see:

ether 00:e2:e3:e4:e5:e6

For the wired ethernet port:

sudo ifconfig en0 ether 00:e2:e3:e4:e5:e6
ifconfig | grep cast | cut -d':' -f2 | cut -d' ' -f1
2010-03-28 02:15:34
Functions: cut grep ifconfig
0

Gets the IP addresses of all interfaces except loopback. Cuts out all of the extra text.

Shorter than the other options, and much easier to type.

'ifconfig | grep cast' is enough to get the IP address, but it doesn't strip the rest of the junk out.

ifconfig | awk '/inet addr/ &&! /127.0.0.1/{ gsub(/addr:/,""); print $2 }'
ifconfig | sed '/.*addr.*Bcast.*/ ! d'| sed 's/.*addr:\([0-9\.]*\).*/\1/'
2010-03-26 08:13:13
User: Haegin
Functions: ifconfig sed
-3

This doesn't make any assumptions about your IP address and prints out one IP address per line if you have multiple network interfaces.

ifconfig | grep addr:192 | sed s/Bcast.*// | sed 's/^.*inet addr://'
2010-03-26 07:37:21
User: hasenj
Functions: grep ifconfig sed
-5

This assumes your local ip starts with 192.something (e.g. 192.168), it greps ifconfig output for an ip that starts with 192, then strips the extra garbage (besides the ip)

Maybe `ifconfig | grep addr | grep Bcast` would also do it

ifconfig | awk '/inet addr/ {print $2 }' | sed 's/.*://g'
2010-03-04 08:15:08
User: Guyverix
Functions: awk ifconfig sed
-2

Easy way to grab the IP address of a machine for easy script use. If needed a "| grep -v 127.0.0.1" at the end will suppress localhost.

ifconfig | awk '/HWaddr/ { print $NF }'
ifconfig -a| grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
2010-02-27 14:30:43
User: evenme
Functions: grep ifconfig
Tags: ifconfig grep
3

Get mac address listed for all interfaces.

for i in `lanscan -i | awk '{print $1}'` ; do ifconfig $i ; done
for i in `netstat -rn |grep lan |cut -c55-60 |sort |uniq`; do ifconfig $i; done
2010-01-28 17:35:20
User: Kaio
Functions: cut grep ifconfig sort
-4

HP UX doesn't have a -a switch in the ifconfig command.

This line emulates the same result shown in Solaris, AIX or Linux

ifconfig eth0:1 192.168.0.1/24
2010-01-12 11:57:11
User: glaudiston
Functions: ifconfig
1

the below command create a alias for share your internet connection with another.

ifconfig eth0:1 192.168.0.1/24

Its obviously necessary too activate the iptables post-routing and ip forwarding, as root:

modprobe iptable_nat iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE echo 1 > /proc/sys/net/ipv4/ip_forward

Be sure that the alias 192.168.0.0/24 is not your active real ip range

ifconfig | grep -B 1 "inet addr:" | head -1 | cut -d" " -f1
2010-01-04 23:02:57
User: jasonwalsh
Functions: cut grep head ifconfig
-2

Get the line containing "inet addr:" and the line before that, get down to only the first line, and then get the first word on that line, which should be the interface.

ifconfig -l | xargs -n1 ipconfig getifaddr 2> /dev/null
ipcalc $(ifconfig eth0 | grep "inet addr:" | cut -d':' -f2,4 | sed 's/.+Bcast:/\//g') | awk '/Network/ { print $2 } '
awk '/inet end/ {print $3}' <(ifconfig eth0)
ifconfig eth0 | grep "inet:" | cut -d ":" -f2 | cut -d " " -f1
ifconfig -a| awk 'BEGIN{FS="[ :]+"} /Bcast/{print $4}'
ifconfig -a|grep Bcast:|cut -d\: -f2|awk '{print $1}'
ifconfig | awk '/HW/ {print $5}'
2009-11-05 18:00:50
User: Cont3mpo
Functions: awk ifconfig
0

Simple MAC adrress, thanks to ifconfig.

sudo ifconfig -a | grep eth | grep HW | cut -d' ' -f11
ifconfig eth1 | grep inet\ addr | awk '{print $2}' | cut -d: -f2 | sed s/^/eth1:\ /g
2009-11-03 19:26:40
User: TuxOtaku
Functions: awk cut grep ifconfig sed
2

Sometimes, you don't really care about all the other information that ifconfig spits at you (however useful it may otherwise be). You just want an IP. This strips out all the crap and gives you exactly what you want.

ips(){ for if in ${1:-$(ip link list|grep '^.: '|cut -d\ -f2|cut -d: -f1)};do cur=$(ifconfig $if|grep "inet addr"|sed 's/.*inet addr:\([0-9\.]*\).*/\1/g');printf '%-5s%-15s%-15s\n' $if $cur $(nc -s $cur sine.cluenet.org 128 2>/dev/null||echo $cur);done;}
2009-08-07 10:04:46
User: frozenfire
Functions: cut echo grep ifconfig link sed
-3

Gets the internal and external IP addresses of all your interfaces, or the ones given as arguments

ifconfig $devices | grep "inet addr" | sed 's/.*inet addr:\([0-9\.]*\).*/\1/g'
ifconfig | grep "0xffffffff" | awk '{ print $2 }' | xargs -n 1 ifconfig em0 delete
2009-08-04 05:18:36
User: vwal
Functions: awk grep ifconfig xargs
3

The example command deletes all aliases for network interface 'em0' assuming that the aliases have netmask of 255.255.255.255 and the master IP has some other netmask (such as 255.255.255.0). See here -> http://my.galagzee.com/2009/07/22/deleting-all-network-interface-aliases/ for more on the rationale of this command.

ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'
2009-07-31 09:49:17
User: sneaker
Functions: ifconfig perl
12

works on Linux and Solaris. I think it will work on nearly all *nix-es