<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>commandliners</title>
	
	<link>http://commandliners.com</link>
	<description># killall -9 X</description>
	<pubDate>Tue, 18 Nov 2008 19:20:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/commandliners" type="application/rss+xml" /><item>
		<title>iftop</title>
		<link>http://feeds.feedburner.com/~r/commandliners/~3/456481520/</link>
		<comments>http://commandliners.com/2008/11/iftop/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 08:00:00 +0000</pubDate>
		<dc:creator>n0str0m0</dc:creator>
		
		<category><![CDATA[cmd]]></category>

		<category><![CDATA[network]]></category>

		<category><![CDATA[shell]]></category>

		<category><![CDATA[bsd]]></category>

		<category><![CDATA[iftop]]></category>

		<category><![CDATA[net]]></category>

		<category><![CDATA[NIC]]></category>

		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://commandliners.com/?p=290</guid>
		<description><![CDATA[$ iftop


On BSD systems, displays NIC statistics.
Install from /usr/ports/net-mgmt/iftop
]]></description>
			<content:encoded><![CDATA[<pre><code>$ iftop
</code></pre>

On BSD systems, displays NIC statistics.<br />
Install from /usr/ports/net-mgmt/iftop
<img src="http://feeds.feedburner.com/~r/commandliners/~4/456481520" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://commandliners.com/2008/11/iftop/feed/</wfw:commentRss>
		<feedburner:origLink>http://commandliners.com/2008/11/iftop/</feedburner:origLink></item>
		<item>
		<title>Output last lines of a file</title>
		<link>http://feeds.feedburner.com/~r/commandliners/~3/455735616/</link>
		<comments>http://commandliners.com/2008/11/output-last-lines-of-a-file/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 08:00:53 +0000</pubDate>
		<dc:creator>rafacas</dc:creator>
		
		<category><![CDATA[cmd]]></category>

		<category><![CDATA[tail]]></category>

		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://commandliners.com/?p=163</guid>
		<description><![CDATA[$ tail -20 test.txt
Outputs the last 20 lines of file test.txt]]></description>
			<content:encoded><![CDATA[<pre><code>$ tail -20 test.txt</code></pre>
Outputs the last 20 lines of file <code>test.txt</code><img src="http://feeds.feedburner.com/~r/commandliners/~4/455735616" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://commandliners.com/2008/11/output-last-lines-of-a-file/feed/</wfw:commentRss>
		<feedburner:origLink>http://commandliners.com/2008/11/output-last-lines-of-a-file/</feedburner:origLink></item>
		<item>
		<title>Strings in bash</title>
		<link>http://feeds.feedburner.com/~r/commandliners/~3/454167913/</link>
		<comments>http://commandliners.com/2008/11/strings-in-bash/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 17:51:48 +0000</pubDate>
		<dc:creator>pfortuny</dc:creator>
		
		<category><![CDATA[shell]]></category>

		<category><![CDATA[bash]]></category>

		<category><![CDATA[ksh]]></category>

		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://commandliners.com/?p=254</guid>
		<description><![CDATA[	Start with a string:
	$ a=&#34;hi, this is my beautifull string&#34;

	Positional substrings:
	
	Substring from the 4th character on:
	$ echo ${a:3}
this is my beautifull string

	
	Substring of length 4 from the 10th character:
	$ echo ${a:9:4}
is m

	
	
	Substring modification:
	
	Substitute the first instance of a substring:
	$ echo ${a/full/ful}
hi, this is my beautiful string

	
	Same example:
	$ echo ${a/h/H}
Hi, this is my beautifull string

	
	Substitute all [...]]]></description>
			<content:encoded><![CDATA[	<p>Start with a string:</p>
	<pre><code>$ a=&quot;hi, this is my beautifull string&quot;
</code></pre>
	<p>Positional substrings:</p>
	<ol>
	<li>Substring from the 4th character on:
	<pre><code>$ echo ${a:3}
this is my beautifull string
</code></pre>
	</li>
	<li>Substring of length 4 from the 10th character:
	<pre><code>$ echo ${a:9:4}
is m
</code></pre>
	</li>
	</ol>
	<p>Substring modification:</p>
	<ol>
	<li>Substitute the first instance of a substring:
	<pre><code>$ echo ${a/full/ful}
hi, this is my beautiful string
</code></pre>
	</li>
	<li>Same example:
	<pre><code>$ echo ${a/h/H}
Hi, this is my beautifull string
</code></pre>
	</li>
	<li>Substitute <strong>all</strong> the instances of a substring:
	<pre><code>$ echo ${a//hi/HI}
HI, tHIs is my beautifull string
</code></pre>
	</li>
	</ol>
	<p>Substring removal:</p>
	<ol>
	<li>Remove the <strong>shortest</strong> match of a substring <strong>from the start</strong>:
	<pre><code>$ echo ${a#h*i}
, this is my beautifull string
</code></pre>
	</li>
	<li>Same, starting at <strong>the end</strong>
	<pre><code>$ echo ${a%i*g}
hi, this is my beautifull str
</code></pre>
	</li>
	<li>Remove the <strong>longest</strong> match of a substring <strong>from the start</strong>:
	<pre><code>$ echo ${a##h*i}
ng
</code></pre>
	</li>
	<li>Same, starting at <strong>the end</strong>
	<pre><code>$ echo ${a%%i*g}
h
</code></pre>
	</li>
	</ol>
	<p>These are for bash-2, they probably work on bash-3 and they <em>seem to work</em> on ksh (under OS X at least).
</p>
<img src="http://feeds.feedburner.com/~r/commandliners/~4/454167913" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://commandliners.com/2008/11/strings-in-bash/feed/</wfw:commentRss>
		<feedburner:origLink>http://commandliners.com/2008/11/strings-in-bash/</feedburner:origLink></item>
		<item>
		<title>Viewing info about free and used system memory</title>
		<link>http://feeds.feedburner.com/~r/commandliners/~3/450430015/</link>
		<comments>http://commandliners.com/2008/11/viewing-info-about-free-and-used-system-memory/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 08:00:22 +0000</pubDate>
		<dc:creator>rafacas</dc:creator>
		
		<category><![CDATA[cmd]]></category>

		<category><![CDATA[free]]></category>

		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://commandliners.com/?p=161</guid>
		<description><![CDATA[$ free -m
             total       used       free     shared    buffers     cached
Mem:          1003  [...]]]></description>
			<content:encoded><![CDATA[<pre><code>$ free -m
             total       used       free     shared    buffers     cached
Mem:          1003        253        750          0         41        178
-/+ buffers/cache:         32        970
Swap:         1992          0       1992
</code></pre>
Displays information about free and used memory on the system.<img src="http://feeds.feedburner.com/~r/commandliners/~4/450430015" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://commandliners.com/2008/11/viewing-info-about-free-and-used-system-memory/feed/</wfw:commentRss>
		<feedburner:origLink>http://commandliners.com/2008/11/viewing-info-about-free-and-used-system-memory/</feedburner:origLink></item>
		<item>
		<title>Find files ending in mp3</title>
		<link>http://feeds.feedburner.com/~r/commandliners/~3/448177438/</link>
		<comments>http://commandliners.com/2008/11/find-files-ending-in-mp3/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 08:00:03 +0000</pubDate>
		<dc:creator>rafacas</dc:creator>
		
		<category><![CDATA[cmd]]></category>

		<category><![CDATA[find]]></category>

		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://commandliners.com/?p=157</guid>
		<description><![CDATA[$ find / -name &#34;*.mp3&#34;
Search for (starting at the root / directory) all the files ending in &#8220;.mp3&#8243;]]></description>
			<content:encoded><![CDATA[<pre><code>$ find / -name &#34;*.mp3&#34;</code></pre>
Search for (starting at the root / directory) all the files ending in &#8220;.mp3&#8243;<img src="http://feeds.feedburner.com/~r/commandliners/~4/448177438" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://commandliners.com/2008/11/find-files-ending-in-mp3/feed/</wfw:commentRss>
		<feedburner:origLink>http://commandliners.com/2008/11/find-files-ending-in-mp3/</feedburner:origLink></item>
		<item>
		<title>Is this a tty?</title>
		<link>http://feeds.feedburner.com/~r/commandliners/~3/446307239/</link>
		<comments>http://commandliners.com/2008/11/is-this-a-tty/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 08:00:26 +0000</pubDate>
		<dc:creator>pfortuny</dc:creator>
		
		<category><![CDATA[shell]]></category>

		<category><![CDATA[cat]]></category>

		<category><![CDATA[cron]]></category>

		<category><![CDATA[man]]></category>

		<category><![CDATA[profile]]></category>

		<category><![CDATA[screen]]></category>

		<category><![CDATA[stdin]]></category>

		<category><![CDATA[test]]></category>

		<category><![CDATA[tty]]></category>

		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://commandliners.com/?p=182</guid>
		<description><![CDATA[	That is a funny question to ask if you are a human (because you *should* know the answer). But it is not that dumb for a system. As a matter of fact, among the multiple tests the shell admits (man 1 test), there is a -t which serves specifically for that:
	$ test -t 0

	returns 0 [...]]]></description>
			<content:encoded><![CDATA[	<p>That is a funny question to ask <strong>if you are a human</strong> (because you *should* know the answer). But it is not that dumb for a system. As a matter of fact, among the multiple <code>test</code>s the shell admits (<code>man 1 test</code>), there is a <code>-t</code> which serves specifically for that:</p>
	<pre><code>$ test -t 0
</code></pre>
	<p>returns <code>0</code> (that is, <em>success</em> or <em>true</em> in shell jargon) if the standard input (file descriptor <code>0</code>) is open and is associated with a terminal. So, unless things are going pretty bad, the following</p>
	<pre><code>$ test -t 0 &#038;&#038; echo $?
</code></pre>
	<p>Should <strong>always</strong> print a <code>0</code>.</p>
	<p>However, when a file may be run in both interactive and non-interactive environments, the above test is not just useful but sometimes even necessary. Assume you want to automatically run <a href="http://commandliners.com/2008/10/screen-ttys-as-window-managers-1/">screen</a> when you log into your session. You might think of adding the following line</p>
	<pre><code>$ screen -d -R
</code></pre>
	<p>to your <code>.profile</code> file. This is OK as long as your <code>cron</code> jobs do not need to use it. But if they need, you are bound to get errors, strange mails or even lost connections. This is because each time a <code>cron</code> job needs a shell, it will read (and execute) the <code>.profile</code> file and, <em>bang!</em> there go your screens et al.</p>
	<p>To prevent that from happening, you need to tell the shell to run the line <em>only when in interactive mode</em>. To test this, simply check for the &#8216;terminal-&#8217;ness of stdin (that is, test -t 0).</p>
	<p>In summary, one of the proper ways to automatically run screen when you log in is:</p>
	<pre><code>$ cat < .profile
(... snapped ...)
if [ -t 0 ] ; then
    screen -d -R
fi
</code></pre>
	<p>Which can be also written:</p>
	<pre><code>$ cat < .profile
(... ...)
[-t 0] &#038;&#038; screen -d -R
</code></pre>
	<p>but is less human-friendly. For me.</p>
<img src="http://feeds.feedburner.com/~r/commandliners/~4/446307239" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://commandliners.com/2008/11/is-this-a-tty/feed/</wfw:commentRss>
		<feedburner:origLink>http://commandliners.com/2008/11/is-this-a-tty/</feedburner:origLink></item>
		<item>
		<title>man man</title>
		<link>http://feeds.feedburner.com/~r/commandliners/~3/444129020/</link>
		<comments>http://commandliners.com/2008/11/man-man/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 08:00:58 +0000</pubDate>
		<dc:creator>pfortuny</dc:creator>
		
		<category><![CDATA[cmd]]></category>

		<category><![CDATA[man]]></category>

		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://commandliners.com/?p=194</guid>
		<description><![CDATA[$ man man

Some useful info not to be underestimated.]]></description>
			<content:encoded><![CDATA[<pre><code>$ man man
</code></pre>
Some useful info not to be underestimated.<img src="http://feeds.feedburner.com/~r/commandliners/~4/444129020" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://commandliners.com/2008/11/man-man/feed/</wfw:commentRss>
		<feedburner:origLink>http://commandliners.com/2008/11/man-man/</feedburner:origLink></item>
		<item>
		<title>Changing the MAC address of an interface</title>
		<link>http://feeds.feedburner.com/~r/commandliners/~3/441840785/</link>
		<comments>http://commandliners.com/2008/11/changing-the-mac-address-of-an-interface/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 08:00:36 +0000</pubDate>
		<dc:creator>rafacas</dc:creator>
		
		<category><![CDATA[cmd]]></category>

		<category><![CDATA[ifconfig]]></category>

		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://commandliners.com/?p=153</guid>
		<description><![CDATA[# ifconfig eth0 hw ether 11:22:33:44:FF:AA
Set the hardware address of the eth0 interface (the device driver has to support this operation). The hardware class (ethernet in the example) is specified with the ether parameter.]]></description>
			<content:encoded><![CDATA[<pre><code># ifconfig eth0 hw ether 11:22:33:44:FF:AA</code></pre>
Set the hardware address of the <code>eth0</code> interface (the device driver has to support this operation). The hardware class (ethernet in the example) is specified with the <code>ether</code> parameter.<img src="http://feeds.feedburner.com/~r/commandliners/~4/441840785" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://commandliners.com/2008/11/changing-the-mac-address-of-an-interface/feed/</wfw:commentRss>
		<feedburner:origLink>http://commandliners.com/2008/11/changing-the-mac-address-of-an-interface/</feedburner:origLink></item>
		<item>
		<title>pf, OpenBSD’s [p]acket [f]ilter (1)</title>
		<link>http://feeds.feedburner.com/~r/commandliners/~3/439751793/</link>
		<comments>http://commandliners.com/2008/11/pf-openbsds-packet-filter-i/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 08:00:57 +0000</pubDate>
		<dc:creator>pfortuny</dc:creator>
		
		<category><![CDATA[network]]></category>

		<category><![CDATA[firewall]]></category>

		<category><![CDATA[OpenBSD]]></category>

		<category><![CDATA[pf]]></category>

		<guid isPermaLink="false">http://commandliners.com/?p=133</guid>
		<description><![CDATA[	When anyone has asked me in the last two years about installing a firewall at his LAN&#8217;s border, I have always recommended them OpenBSD&#8217;s packet filter pf. I discovered OpenBSD a couple of years ago while designing a hall of residence&#8217;s local network and firewall. I was by then quite tired of Linux&#8217;s netfilter/iptables and [...]]]></description>
			<content:encoded><![CDATA[	<p>When anyone has asked me in the last two years about installing a firewall at his LAN&#8217;s border, I have always recommended them <a href="http://www.openbsd.org">OpenBSD</a>&#8217;s packet filter <a href="http://www.openbsd.org/faq/pf/">pf</a>. I discovered OpenBSD a couple of years ago while designing a <a href="http://www.cmpenafiel.org">hall of residence</a>&#8217;s local network and firewall. I was by then quite tired of Linux&#8217;s <a href="http://www.netfilter.org">netfilter/iptables</a> and the first time I read about pf, I fell in love with it.</p>
	<p>We are now more accustomed to this, but when I saw that you could write <strong>firewall rules</strong> like</p>
	<pre><code>pass in on $ext_if proto tcp from any port 80 to $ext_if
</code></pre>
	<p>I knew I had found my firewall. No more <code>-j</code> or <code>-l</code> or whatever. Just names, words and eventually numbers.</p>
	<p>And, yes, I know there are wrappers in Linux doing the very same thing. But guess what? I just do not like wrappers for this kind of job. Moreover, after you install OpenBSD for the first time and realize you have done it in about 2 minutes with <strong>no</strong> stupid questions (that is, <em>à la slackware</em>) and have a complete, working, no-hassle, simple operating system just ready to filter your network traffic&#8230; You simply never leave it. I wonder how I had not found it before.</p>
	<p>To keep this first post simple, just assume you are for whatever strange reason running a web server on an OpenBSD system which you want to be able to manage remotely via ssh.</p>
	<p>From the firewall point of view, you just want to block all incoming traffic <em>except</em> to ports 80 and 22, and to allow only outgoing packets which arise from external connection on those ports. Technically, you want to allow incoming connections and <em>keep there state</em> (which means all the traffic related to a previously allowed packet is allowed through).</p>
	<p>Fortunately, <strong>pf</strong> keeps state by default. The <code>pf.conf</code> file describing the above set up might perfectly look like:</p>
	<pre><code># pf configuration file for an ssh managed web server
ext_if=&quot;vr0&quot;
ext_ip=1.2.3.4
allowed={http, ssh}
	
block all
pass in on $ext_if proto tcp from any to $ext_ip port $allowed
</code></pre>
	<p>And that is all. Let me explain:</p>
	<ul>
	<li>The assignments create <em>macros</em>. Macros are substituted pretty much like shell variables (a=&#8217;hi&#8217;, $a <em>is</em> &#8216;hi&#8217;).
	<li>Any collection of identifiers, macros or lists between curly brackets is a <em>list</em> (recursive definition). As can be seen, lists can be assigned to macros.
	<li>Rules are applied in a <em>last match</em> hierarchy. Whenever a packet arrives, pf keeps reading rules and applies to the packet the last matching one. The above <em>block all</em> and then <em>pass</em> means exactly: <em>block by default</em> (both incoming and outgoing packets) and let pass only what comes to ports either 80 or 22.
	<li>The fact that <em>pf keeps state</em> by deafult makes the firewall configured with the above file &#8216;let the TCP handshake and later packets&#8217; go through into and out of the firewall, once a valid packet has passed through. One does not need to specify that &#8216;packets related to an allowed packet have to be let through&#8217;.
	<li>The use of $ before the names of macros is clear.
</ul>
	<p>To enable the firewall, </p>
	<pre><code># pfctl -e /etc/pf.conf
</code></pre>
	<p>In the documentation you can find how to enable it at boot time.</p>
	<p>I hope to delve somewhat more in forthcoming articles. As with all things OpenBSD the <a href="http://www.openbsd.org/faq/">FAQ</a> is a good starting point.
</p>
<img src="http://feeds.feedburner.com/~r/commandliners/~4/439751793" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://commandliners.com/2008/11/pf-openbsds-packet-filter-i/feed/</wfw:commentRss>
		<feedburner:origLink>http://commandliners.com/2008/11/pf-openbsds-packet-filter-i/</feedburner:origLink></item>
		<item>
		<title>Adding line numbers to a file</title>
		<link>http://feeds.feedburner.com/~r/commandliners/~3/437807637/</link>
		<comments>http://commandliners.com/2008/10/adding-line-numbers-to-a-file/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 08:00:35 +0000</pubDate>
		<dc:creator>rafacas</dc:creator>
		
		<category><![CDATA[cmd]]></category>

		<category><![CDATA[cat]]></category>

		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://commandliners.com/?p=148</guid>
		<description><![CDATA[$ cat -b /etc/inittab
     1  root:x:0:root
     2  bin:x:1:root,bin,daemon
     3  daemon:x:2:root,bin,daemon
     4  sys:x:3:root,bin,adm
     5  adm:x:4:root,adm,daemon
     6  tty:x:5:
     7  disk:x:6:root
   [...]]]></description>
			<content:encoded><![CDATA[<pre><code>$ cat -b /etc/inittab
     1  root:x:0:root
     2  bin:x:1:root,bin,daemon
     3  daemon:x:2:root,bin,daemon
     4  sys:x:3:root,bin,adm
     5  adm:x:4:root,adm,daemon
     6  tty:x:5:
     7  disk:x:6:root
     8  lp:x:7:daemon,lp
     9  mem:x:8:
    10  kmem:x:9:
    11  wheel:x:10:root
    12  mail:x:12:mail
    13  news:x:13:news
    14  uucp:x:14:uucp
    15  man:x:15:
    [...]
</code></pre>
Adds line numbers to all non blank lines from the specified file.<img src="http://feeds.feedburner.com/~r/commandliners/~4/437807637" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://commandliners.com/2008/10/adding-line-numbers-to-a-file/feed/</wfw:commentRss>
		<feedburner:origLink>http://commandliners.com/2008/10/adding-line-numbers-to-a-file/</feedburner:origLink></item>
	</channel>
</rss>
