snipt

Ctrl+h for KB shortcuts

Bash

retrieves the name of the first ethernet interface

1
2
3
ifconfig -a | grep -i "link[ ]*encap[ ]*:[ ]*ethernet" | awk 'BEGIN{ iface="z" }
{ if( $1 ~ /^eth/ && iface > $1 ) iface=$1 }
END{ print iface }'
https://snipt.net/embed/c0d56ee8c9b6176b238ec51b931e244c/
https://snipt.net/raw/c0d56ee8c9b6176b238ec51b931e244c/
c0d56ee8c9b6176b238ec51b931e244c
bash
Bash
3
2016-09-29T10:22:41
True
False
False
/api/public/snipt/13606/
retrieves-the-name-of-the-first-ethernet-interface
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>ifconfig -a <span class="p">|</span> grep -i <span class="s2">&quot;link[ ]*encap[ ]*:[ ]*ethernet&quot;</span> <span class="p">|</span> awk <span class="s1">&#39;BEGIN{ iface=&quot;z&quot; }</span> </span><span id="L-2"><a name="L-2"></a><span class="s1">{ if( $1 ~ /^eth/ &amp;&amp; iface &gt; $1 ) iface=$1 }</span> </span><span id="L-3"><a name="L-3"></a><span class="s1">END{ print iface }&#39;</span> </span></pre></div> </td></tr></table>
eth, eth0, ifconfig, interface

Bash

print the list of local IP addresses from ifconfig

#/bin/sh
ifconfig | grep 'inet addr' | awk '{print $2}' | cut -f 2 -d ':' 
https://snipt.net/embed/7876306ff771e8d768e07540988a7dc0/
https://snipt.net/raw/7876306ff771e8d768e07540988a7dc0/
7876306ff771e8d768e07540988a7dc0
bash
Bash
2
2016-09-29T20:45:32
True
False
False
/api/public/snipt/7133/
echo-address
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c">#/bin/sh</span> </span><span id="L-2"><a name="L-2"></a>ifconfig <span class="p">|</span> grep <span class="s1">&#39;inet addr&#39;</span> <span class="p">|</span> awk <span class="s1">&#39;{print $2}&#39;</span> <span class="p">|</span> cut -f <span class="m">2</span> -d <span class="s1">&#39;:&#39;</span> </span></pre></div> </td></tr></table>
address, awk, cut, grep, ifconfig, ip, shell

Bash

Get the IP address of a local ethernet interface

ifconfig <INTERFACE> | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1 }'
https://snipt.net/embed/0284caa94e65be0e8e0189a3de6a9ee4/
https://snipt.net/raw/0284caa94e65be0e8e0189a3de6a9ee4/
0284caa94e65be0e8e0189a3de6a9ee4
bash
Bash
1
2016-09-29T07:27:38
True
False
False
/api/public/snipt/5382/
get-the-ip-address-of-a-local-ethernet-interface
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>ifconfig &lt;INTERFACE&gt; <span class="p">|</span> grep <span class="s1">&#39;inet addr:&#39;</span> <span class="p">|</span> cut -d: -f2 <span class="p">|</span> awk <span class="s1">&#39;{ print $1 }&#39;</span> </span></pre></div> </td></tr></table>
awk, bash, cut, grep, ifconfig, ip

Bash

Get Current IP Address

ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1 }'
https://snipt.net/embed/fdf01ba1398fa35d3b130cf87282d039/
https://snipt.net/raw/fdf01ba1398fa35d3b130cf87282d039/
fdf01ba1398fa35d3b130cf87282d039
bash
Bash
1
2016-09-30T14:50:20
True
False
False
/api/public/snipt/5367/
get-current-ip-address
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>ifconfig eth0 <span class="p">|</span> grep <span class="s1">&#39;inet addr:&#39;</span> <span class="p">|</span> cut -d: -f2 <span class="p">|</span> awk <span class="s1">&#39;{ print $1 }&#39;</span> </span></pre></div> </td></tr></table>
bash, ifconfig, ip, server, unix

Bash

Learning IP in OSX

ifconfig en0 | awk '/inet / { print $2 } '
https://snipt.net/embed/e9e10c778bb2a57846a8b73053c85f20/
https://snipt.net/raw/e9e10c778bb2a57846a8b73053c85f20/
e9e10c778bb2a57846a8b73053c85f20
bash
Bash
1
2016-09-28T15:55:37
True
False
False
/api/public/snipt/1699/
learning-ip-in-osx
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>ifconfig en0 <span class="p">|</span> awk <span class="s1">&#39;/inet / { print $2 } &#39;</span> </span></pre></div> </td></tr></table>
awk, bash, ifconfig, ip, osx
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.