<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Terminally Incoherent &#187; unix</title>
	<atom:link href="http://www.terminally-incoherent.com/blog/category/unix/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.terminally-incoherent.com/blog</link>
	<description>Utterly random, incoherent and disjointed rants and ramblings...</description>
	<lastBuildDate>Tue, 16 Mar 2010 15:03:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Create Arbitrary Sized Sparse Files under Windows and Linux</title>
		<link>http://www.terminally-incoherent.com/blog/2008/09/25/create-arbitrary-sized-sparse-files-under-windows-and-linux/</link>
		<comments>http://www.terminally-incoherent.com/blog/2008/09/25/create-arbitrary-sized-sparse-files-under-windows-and-linux/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 15:47:27 +0000</pubDate>
		<dc:creator>Luke Maciak</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.terminally-incoherent.com/blog/2008/09/25/create-arbitrary-sized-sparse-files-under-windows-and-linux/</guid>
		<description><![CDATA[Apparently there is something to be said about short blog posts. Allegedly I tend to get long winded sometimes and my posts can run a tad verbose sometimes. I usually tell people to STFU and go read Steve Yegge if they want to see verbose. I&#8217;m short, concise and to the point compared to him. [...]]]></description>
			<content:encoded><![CDATA[<p>Apparently there is something to be said about short blog posts. Allegedly I tend to get long winded sometimes and my posts can run a tad verbose sometimes. I usually tell people to STFU and go read Steve Yegge if they want to see verbose. I&#8217;m short, concise and to the point compared to him. But I figured that I&#8217;ll try some of that short blog post thing that people seem to be enjoying in other parts of the web. So I&#8217;m making a post about a silly little windows command. This is so that I don&#8217;t forget it about it next time I need it. </p>
<p>Have you ever needed a file of specific size to test something but you didn&#8217;t care what that file was? You know, just a space holder or a space filler kind of a thing? This is what you need to do to create one on Windows XP:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">fsutil file createnew file.ext 10000</pre></div></div>

<p>Naturally <samp>file.ext</samp> is the desired name of the file you want to create, and the numeric argument is the desired size in bytes. Note that fsutil creates a <a href="http://en.wikipedia.org/wiki/Sparse_file" rel="nofollow" class="liwikipedia">sparse file</a> which means that this operation will be blindingly fast. For example it took about 3 seconds to create a 10GB file on my elderly windows machine.</p>
<p>Useful trick. I sometimes use it to see how a given app will act when it encounters a file of certain size. To accomplish the same thing in linux you apparently need to do something like:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">dd <span style="color: #000000; font-weight: bold;">if</span><span style="color: #339933;">=/</span>dev<span style="color: #339933;">/</span>zero of<span style="color: #339933;">=</span>my<span style="color: #339933;">-</span>file bs<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span> count<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span> seek<span style="color: #339933;">=</span>10G</pre></div></div>

<p>I messed around with it, and the <em>bs</em> and <em>count</em> are important so don&#8217;t just skip them. The <samp>seek</samp> attribute specifies the desired size of your file, and here you can use human readable units (like 10Gb in the example).</p>
<p>So if you ever need a file of a specific size to test something, here is how you make one. How is that for a short post? What do you mean 350 words is not short? Ah, go to hell then. I tried. Next post will be verbose again. <img src='http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.terminally-incoherent.com/blog/2008/09/25/create-arbitrary-sized-sparse-files-under-windows-and-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting Up a Private Nethack Server on Ubuntu Lite</title>
		<link>http://www.terminally-incoherent.com/blog/2007/11/17/setting-up-a-private-nethack-server-on-ubuntu-lite/</link>
		<comments>http://www.terminally-incoherent.com/blog/2007/11/17/setting-up-a-private-nethack-server-on-ubuntu-lite/#comments</comments>
		<pubDate>Sat, 17 Nov 2007 16:46:33 +0000</pubDate>
		<dc:creator>Luke Maciak</dc:creator>
				<category><![CDATA[games]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.terminally-incoherent.com/blog/2007/11/17/setting-up-a-private-nethack-server-on-ubuntu-lite/</guid>
		<description><![CDATA[We already established that terminally incoherent readers love them some nethack. The nice thing about nethack is that it takes only few hundred kb on your drive, and provides you with endless tons of entertainment. But hell, you don&#8217;t even need to install it. All you need to taste the nethack goodness is telnet.
There are [...]]]></description>
			<content:encoded><![CDATA[<p>We already established that terminally incoherent readers <a href="http://www.terminally-incoherent.com/blog/2007/11/09/nethack/" class="liinternal">love them some nethack</a>. The nice thing about nethack is that it takes only few hundred kb on your drive, and provides you with endless tons of entertainment. But hell, you don&#8217;t even need to install it. All you need to taste the nethack goodness is telnet.</p>
<p>There are several public nethack servers that let you play via telnet. The biggest and most popular one is located at <a href="http://alt.org/nethack/" class="liexternal">alt.org</a>. Or at least they are the one that shows up on Google results first. You simply telnet in, create an account and play online. This is such an awesome concept that I decided I need some of that. I want my own public server! This would be a perfect new role for that funky <a href="http://www.terminally-incoherent.com/blog/2006/12/05/old-laptops/" class="liinternal">old Compaq Presario</a> sitting under my desk and <a href="http://www.terminally-incoherent.com/blog/2007/09/20/ubuntulite-problems-running-feisty-on-old-hardware/" class="liinternal">currently running Ubuntulite</a>. So I started digging around for a solution. </p>
<p>And I hit a brick wall because the documentation for this kind of stuff is scant and/or nonexistent. Nevertheless I persevered and you can see the end effect at <a href="telnet://luke.kicks-ass.org" class="liinternal">luke.kicks-ass.org</a>. Sorry for the dyndns domain name, but this is a temporary sort of a thing. For now you can simply telnet in and play. I will probably keep the machine running over the weekend unless you guys manage to crash it. <img src='http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Note: Use <a href="http://en.wikipedia.org/wiki/PuTTY" rel="nofollow" class="liwikipedia">PuTTY</a> or some real terminal client. The windows cmd.exe messes up the menu layout pretty badly. But I&#8217;m not sure if there&#8217;s anything I can do about it.</p>
<p>Once again, if you want to try out the server, just do:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">telnet luke.kicks-ass.org</pre></div></div>

<p>It&#8217;s running on port 23, and it should log you in automatically. From there you need to (r)egister an account. I don&#8217;t use the emails for anything, so when asked just type in anything as long as it has an email syntax. There is no email activation or any of that shit. Username and password are up to you. Just remember that this is telnet &#8211; so your password will be sent in plain text. Make up some silly one that you won&#8217;t be using elsewhere and you won&#8217;t cry when you lose it. When you are done it should dump you back at the initial prompt. There you can either (l)og in to play or (w)atch someone else play. Chances are no one is playing yet so log in.</p>
<p>On the next screen you will see bunch of options. Note that I left the nethack config files in bare bones state. You will probably want to use the &#8220;o&#8221; option to edit your options file to include the <samp>number_pad:2</samp> bit that makes movement little easier for people who don&#8217;t like HJKL. The editor that ships with dgamelaunch is a vim clode so just fucking deal with it. Move down to one of the uncommented OPTIONS lines add number_pad:2 at the end, press Esc, then <samp>:wq</samp> and you should be back at the prompt. <img src='http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Now all that is left is to (p)lay.</p>
<p>Let me know how the server works for you. It may be a bit slow (the box is a very old laptop siting on an asymetric residential connection) but then again, this is nethack. You don&#8217;t really need rapid speed here. If you like it I might try to figure out a way to make this a permanent fixture of the site. <img src='http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here is a screenshot of me playing from my winXP box via PuTTY by telneting to luke.kicks-ass.org:</p>
<p><a href="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/11/croppercapture51.jpg" class="imagelink" title="Playing Nethack on the New Server"><img id="image2096" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/11/croppercapture51.jpg" alt="Playing Nethack on the New Server" width="450"/></a></p>
<p>What follows below is the lengthy account of the issues I encountered while setting up this damn thing. If you don&#8217;t care about installation details, just skip down to comments. </p>
<p>So, how do you run a public nethack server? First you need the server software. Most servers out there use <a href="http://www.advogato.org/proj/dgamelaunch/" class="liexternal">DGameLaunch</a> which works, but is a major pain in the ass to use. It&#8217;s not in the repositories so you will need to download it from the website, compile and configure it yourself.  And let me tell you it&#8217;s not a picnic. First, you will need to download few dependencies. You will need ncurses development headers, a telnet server and two lexical analyzers flex and bison. You also, obviously need gcc and make to compile the code. And naturally, nethack. You may already have these things on your system &#8211; my bare bones install of Ubuntulite didn&#8217;t. Just in case run the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libncurses5-dev <span style="color: #c20cb9; font-weight: bold;">bison</span> <span style="color: #c20cb9; font-weight: bold;">flex</span> telnetd <span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #c20cb9; font-weight: bold;">make</span> nethack-console</pre></div></div>

<p>Allright, now we can get the server software and compile it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>:<span style="color: #000000; font-weight: bold;">//</span>ftp.alt.org<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>dgamelaunch<span style="color: #000000; font-weight: bold;">/</span>dgamelaunch-1.4.6.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xzvf</span> dgamelaunch-1.4.6.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> dgamelaunch-1.4.6<span style="color: #000000; font-weight: bold;">/</span>
.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>Have fun. I know I did, because the only documentation that ships with dgamelaunch is a 6 Kb README file. Out of the 117 lines of text it contains, maybe 3 or for actually mention compilation and dependencies. This means that you need to pay close attention to the output of make. Funny thing is that the configure script noticed that I don&#8217;t have bison/yacc or flex/lex but did not consider that a stop condition and gleefully generated a makefile. Of course without these apps make would die a horrible death in a flurry of semi-random error message. Same goes for the ncurses header files &#8211; it knew it was missing, but did nothing. Thanks!</p>
<p>By default, dgamelaunch will get installed into /usr/local/. Once you compile it you need to do two things. First copy the dgamelaunch.conf from the examples folder to your /etc:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> examples<span style="color: #000000; font-weight: bold;">/</span>dgamelaunch.conf <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Next you want to create chroot jail in which the server will be running. There is a script that does that which ships with dgamelaunch. Simply run it and you should be all set:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> .<span style="color: #000000; font-weight: bold;">/</span>dgl-create-chroot</pre></div></div>

<p>It should create /var/lib/dgamelaunch directory and dump bunch of files in there. In my case the script failed to do all the work so I had to do few things manually. Most of this I figured out by trial and error because the README file only gives you cryptic hints on what to do if things go sour.</p>
<p>For example, the script keeled over trying to copy appropriate libs to the chroot directory. It kept failing with an error message pointing out that it can&#8217;t find some file, but instead of printing out the file name it would print out a hex value (memory address?). I looked at the script and noticed this was the very last few lines. It also had some small comment which suggested which libraries will probably get imported.</p>
<p>I manually copied all the listed file from /lib/ to /var/lib/dgamelaunch/lib/ then tried to run the binary. It kept failing telling me about other missing files. After 3 or 4 tries I got the full complement of needed libraries. If this happens to you, here is what you should do:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dgamelaunch<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ld-linux.so.2 <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dgamelaunch<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>libc.so.6 <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dgamelaunch<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>libdl.so.6 <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dgamelaunch<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>libdl.so.2 <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dgamelaunch<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>libncurses.so.5 <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dgamelaunch<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>I also needed to populate /var/lib/dgamelaunch/etc/terminfo with files from /lib/terminfo. For some reason the terminal descriptions were not copied over to this location by the chroot script. I&#8217;m not sure this was intended behavior or just a glitch. If you are having problems running the game or the server interface take a peek in this folder. If it&#8217;s empty do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>terminfo<span style="color: #000000; font-weight: bold;">/*</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dgamelaunch<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>terminfo<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Btw, when you are testing you need to run dgamelaunch with sudo. This is actually a small tidbit of knowledge that is outlined in the README file. Once you can run the app, register and account, edit the option file, and play few rounds of the game, you can move on to the next stage. </p>
<p>Now all we need to do is set up a telnet server so that people can connect and play. Of course This is the one place where the readme actually does offer you some help. Make sure telnetd is installed, and simply copy and paste the following file into your /etc/inetd.conf:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">telnet stream tcp nowait root.root <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>tcpd <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>in.telnetd <span style="color: #660033;">-h</span> <span style="color: #660033;">-L</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>dgamelaunch <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dgamelaunch.conf</pre></div></div>

<p>This may or may not work for you. It work for me. The -L option telnetd in feisty is retarded and doesn&#8217;t allow you to use any command line parameters to the shell you are specifying with it. The README file actually mentions that  near the bottom. It also mentions that you can use an abridged version of this line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">telnet stream tcp nowait root.root <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>tcpd <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>in.telnetd <span style="color: #660033;">-h</span> <span style="color: #660033;">-L</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>dgamelaunch</pre></div></div>

<p>If you do however it is important to make sure your dgamelaunch.conf is in the root of the /etc directory. If you plan place it in a subdirectory, you have to change the make file before you compile it. Check the README file for hints on how to do this. </p>
<p>After you change the inetd.conf file you want to restart the inetd server. There are several ways to do this, but a simple way that will work on just about any platform is:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">killall</span> <span style="color: #660033;">-HUP</span> inetd</pre></div></div>

<p>This kills the process and forces it to restart and re-read it&#8217;s config file. It&#8217;s a tad brutal way to do it so don&#8217;t use it on a shared machine or one that is actually handling some critical data. What the hell are do doing installing nethack server on a critical server anyway? </p>
<p>If you do all of the above, you should have a working dgamelaunch installation, and a working telnet server. Just telnet in, and play. <img src='http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Id not, post in the comments and we can maybe figure out what is going on together.</p>
<p>tldr: dgamelaunch documentation sucks balls, but setting up the server is doable</p>
<div class="simpletags">tags: <a href="http://technorati.com/tag/nethack" rel="tag">nethack</a>, <a href="http://technorati.com/tag/nethack+server" rel="tag"> nethack server</a>, <a href="http://technorati.com/tag/dgamelaunch" rel="tag"> dgamelaunch</a>, <a href="http://technorati.com/tag/public+nethack+server" rel="tag"> public nethack server</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.terminally-incoherent.com/blog/2007/11/17/setting-up-a-private-nethack-server-on-ubuntu-lite/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>The Denoobization Script</title>
		<link>http://www.terminally-incoherent.com/blog/2007/11/15/the-denoobization-script/</link>
		<comments>http://www.terminally-incoherent.com/blog/2007/11/15/the-denoobization-script/#comments</comments>
		<pubDate>Thu, 15 Nov 2007 16:17:11 +0000</pubDate>
		<dc:creator>Luke Maciak</dc:creator>
				<category><![CDATA[humor]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.terminally-incoherent.com/blog/2007/11/15/the-denoobization-script/</guid>
		<description><![CDATA[Here is my favorite bash script which can be used to teach noobs about bash syntax, man pages and the importance of backup at the same time:

s=&#34;r&#34;; d=&#34;$s&#34;m; f=&#34;$s&#34;f; sudo $&#40;$d -$f /&#41;

If not on Ubuntu, just get rid of sudo and tell people to run it as root. Oh, and if you copied and [...]]]></description>
			<content:encoded><![CDATA[<p>Here is my favorite bash script which can be used to teach noobs about bash syntax, man pages and the importance of backup at the same time:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">s</span>=<span style="color: #ff0000;">&quot;r&quot;</span>; <span style="color: #007800;">d</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$s</span>&quot;</span>m; <span style="color: #007800;">f</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$s</span>&quot;</span>f; <span style="color: #c20cb9; font-weight: bold;">sudo</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$d</span> -<span style="color: #007800;">$f</span> <span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>If not on Ubuntu, just get rid of sudo and tell people to run it as root. Oh, and if you copied and pasted this into your  terminal to try what it does, I hope you backed up recently. I&#8217;m guessing it probably won&#8217;t delete everything (there would be some access violations and stuff) but it will probably do enough damage for you to hate me for the rest of your life.</p>
<p>Oh, and it <a href="http://blogs.sun.com/jbeck/date/20041001#rm_rf_protection" class="liexternal">won&#8217;t work on Solaris 10</a>. I guess someone at Sun fell for some incarnation of this very trick at some point. <img src='http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>Btw, has anyone ever killed a system this way? What is the most damage you ever did to a linux system by issuing a reckless command as root? </p>
<p>Also, can you beat my denoobization script? Time to show your true BOFH skills. Points will be given for the magnitude of damage it causes, obfuscation and brevity. Btw, you should be able to copy and paste it into the terminal as a single line.</p>
<div class="simpletags">tags: <a href="http://technorati.com/tag/linux" rel="tag">linux</a>, <a href="http://technorati.com/tag/rm" rel="tag"> rm</a>, <a href="http://technorati.com/tag/rm+-rf" rel="tag"> rm -rf</a>, <a href="http://technorati.com/tag/bofh" rel="tag"> bofh</a>, <a href="http://technorati.com/tag/noob" rel="tag"> noob</a>, <a href="http://technorati.com/tag/unix" rel="tag"> unix</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.terminally-incoherent.com/blog/2007/11/15/the-denoobization-script/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>How To Kill Stuff On Linux</title>
		<link>http://www.terminally-incoherent.com/blog/2007/10/05/how-to-kill-stuff-on-linux/</link>
		<comments>http://www.terminally-incoherent.com/blog/2007/10/05/how-to-kill-stuff-on-linux/#comments</comments>
		<pubDate>Fri, 05 Oct 2007 15:59:04 +0000</pubDate>
		<dc:creator>Luke Maciak</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.terminally-incoherent.com/blog/2007/10/05/how-to-kill-stuff-on-linux/</guid>
		<description><![CDATA[You are happily working on your linux box when all of a sudden something freezes and becomes unresponsive. What do you do? Let&#8217;s talk about killing today!

img &#169; Rossy ℗∑ñℊ⊍ïñ found @ evilpenguins.tribe.net
Everything really depends on situation. If it&#8217;s just a single application that decided to stop responding you can simply kill it. Now, you [...]]]></description>
			<content:encoded><![CDATA[<p>You are happily working on your linux box when all of a sudden something freezes and becomes unresponsive. What do you do? Let&#8217;s talk about killing today!</p>
<p><img id="image1996" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/10/penguin-kill.jpg" alt="Killing Stuff On Linux" /><br />
<small>img &copy; <a href="http://people.tribe.net/r0ssy" class="liexternal">Rossy ℗∑ñℊ⊍ïñ</a> found @ <a href="http://evilpenguins.tribe.net/photos/e4dee531-59e8-4072-8f27-bad5192ae65c" class="liexternal">evilpenguins.tribe.net</a></small></p>
<p>Everything really depends on situation. If it&#8217;s just a single application that decided to stop responding you can simply kill it. Now, you may think that killing is a bit harsh punishment for not talking to you &#8211; and it is. Best practice is to wait a little bit, and the app may un-freeze itself eventually. Chances are that some blocking process seized up the focus, and rendered GUI unusable for a little while. Then again, applications sometimes just freeze or get themselves into a runaway loop. And then there is not much you can do but send them SIGTERM or SIGKILL signal using <kbd>kill</kbd> or <kbd>killall</kbd>. The former takes the PID of the process as an argument, while the latter takes a name of the binnary and additionally tries to kill the whole process tree which is usually (but not always) a good idea. Note that both commands send SIGTERM by default which is essentially equivalent to nicey asking them to drop dead. If you use -9 you no longer ask &#8211; you shiv them in the heart with a rusty spork and watch them bleed to death on your new carpet. And by that I mean data loss, and other unexpected side effects so use it carefully. RTFM for all the other fun signals you can send to your processes.</p>
<p><strong><em style="color: orange;">But how do I kill something if I don&#8217;t even know whats it&#8217;s pid or the name of the binary?</em></strong></p>
<p>Good question, voice in my head. You always bring up these interesting things. There are three ways to deal with this problem. First one is to STFU, stop being such a luser and use ps, and top to figure out which application is acting up and then -9 it like a man. But if you can&#8217;t handle that, there are two other remaining alternatives for the whussies: <kbd>pkill</kbd>, and <kbd>xkill</kbd>.</p>
<p>I <a href="http://www.terminally-incoherent.com/blog/2007/08/01/pkill-an-easier-linux-kill-command/" class="liinternal">mentioned pkill before</a>, so I&#8217;m not going to repeat myself. All you need to know is that <kbd>pkill</kbd> is a smart fellow. He went to ninja school and is sneaky enough to figure out that when you tell it to kill firefox, you really mean <kbd>firefox-bin</kbd>. By that logic Kill and killall are kinda like mob hitmen &#8211; effective, but dumb as bricks. You have to tell them exactly who to hit, and how.</p>
<p>Xkill is kill&#8217;s graphically inclined cousin who specializes in killing windowed applications. When you call him, he appears as a stylish (or tacky, depending on your taste) black skull and bones cursor. Kinda like an inverse Jolly Roger. If pkill is a ninja, then xkill is a pirate of the bunch. Think Jack Sparrow &#8211; can be quite destructive if aimed well, but tends to blow shit up if you underestimate him (ie. click in the wrong place). Point him at your frozen window, hit LMB and he will do the rest. Note that if you change your mind you can cancel it by clicking anywhere with RMB.</p>
<p><strong><em style="color: orange;">What if my whole X seems to be locked up?</em></strong></p>
<p>Easy &#8211; swith to a TTY using Ctrl+Alt+F1 (or any function key from F2 to F6 for that matter)! Then use top/htop or whatever strokes your fancy to figure out which app is hugging all the CPU and eating all the memory. Kill it and chances are that all the other software will be given a breath of fresh air and will resume normal function. You can switch back to X with Ctrl+Alt+F7.</p>
<p>If that doesn&#8217;t work, and you don&#8217;t mind loosing some data, you can give X the good old 3 finger salute. And no, it&#8217;s not that one. The old Ctrl+Alt+Del salute remains a fond memory of Win-DOS 95 users whose machines had those awesome reset buttons on the case, that helped them to recover from frequent BSOD&#8217;s. Reset buttons are a thing of the past, and so is the Ctrl+Alt+Del which acts as a key shortcut to bring up task management console, or logout dialog on most modern systems. Let&#8217;s face it &#8211; pressing this key combination no longer feels like saying &#8220;Fuck You OS, eat shit and DIEEE!&#8221;. </p>
<p>The 3 finger salute I&#8217;m talking about is Ctrl+Alt+Backspace &#8211; and it&#8217;s the key combination that will kill your current X session. And it will give you as much gratification, and therapeutic frustration relief as Ctrl+Alt+Del in the good old times but without actually hosing the filesystem or making the system unstable. Think of it as a forced logout combined with a restart of the X server. 98% of the time this will do the trick and let you resume work quickly and easily.</p>
<p><strong><em style="color: orange;">What if my system is frozen solid?</em></strong></p>
<p>There is still a way to restart it gracefully using the magic <a href="http://en.wikipedia.org/wiki/Magic_SysRq_key" rel="nofollow" class="liwikipedia">SysRq key combo</a>. Simply hit Alt+PrintScrn (which is how you get SysRq key) and then type in R E I S U B with&#8230; Your nose&#8230; Or other part of your anatomy. This will trigger a nice reboot that will not corrupt any of your data, destroy the file system or wreck any other crazy damage.  In fact each of these keys issues a special SysRq command:</p>
<p><strong>R</strong> &#8211; switch the keyboard mode<br />
<strong>E</strong> &#8211; send all processes the SIGTERM singal<br />
<strong>I</strong> &#8211; sends all processes the SIGKILL signal<br />
<strong>S</strong> &#8211; Sync filesystem<br />
<strong>U</strong> &#8211; Unmount all devices<br />
<strong>B</strong> &#8211; Reboot immediately</p>
<p>Theoretically you could just do SysRq+B to do an old school, Win 95 style Alt+Ctrl+Del reboot, but it&#8217;s just as bad as hitting that power button. Your best bet is to run the whole sequence to ensure that the system shuts down in the way it would normally shut down when you issue a reboot command.</p>
<p>And it&#8217;s almost guaranteed to work even on a completely locked up system. That is, if it&#8217;s enabled on your system. If you are not sure, do a really quick test right now:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>kernel<span style="color: #000000; font-weight: bold;">/</span>sysrq</pre></div></div>

<p>If you see a 1, you are in good shape. If you see a zero, you can enable the SysRq keys by doing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>kernel<span style="color: #000000; font-weight: bold;">/</span>sysrq</pre></div></div>

<p>Better do it now before you somehow hose your system and need to use it. It&#8217;s kinda hard to issue commands when nothing responds to you. </p>
<p><strong><em style="color: orange;">How the hell do you expect me to remember this REISUB thing?</em></strong></p>
<p>Mnemonics my friend. That&#8217;s how you do it. The popular one circulating out there is <strong><span style="color: orange;">R</span>ising <span style="color: orange;">E</span>lephants <span style="color: orange;">I</span>s <span style="color: orange;">S</span>o <span style="color: orange;">U</span>tterly <span style="color: orange;">B</span>oring.</strong> If you are more of a visual person, I have another one for you. Observe:</p>
<p><img id="image1994" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/10/croppercapture32.jpg" alt="Rei Ayanami" /><img id="image1995" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/10/croppercapture34.jpg" alt="Subway Sub" /></p>
<p>Get it? It&#8217;s <strong style="color: orange;">REI</strong> Ayanami from <em>Neon Genesis Evangelion</em> and a Subway <strong style="color: orange;">SUB</strong>. It&#8217;s easier to remember if you are a fan of the show. Just think about Rei eating a sub and you are good to go. <img src='http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So there you go &#8211; plenty of ways to kill, maim and slaughter your applications in many ways. And best of all &#8211; most of these are relatively safe, and won&#8217;t break shit. At least for the most part. Remember kids &#8211; kill responsibly.</p>
<div class="simpletags">tags: <a href="http://technorati.com/tag/kill" rel="tag">kill</a>, <a href="http://technorati.com/tag/killall" rel="tag"> killall</a>, <a href="http://technorati.com/tag/pkill" rel="tag"> pkill</a>, <a href="http://technorati.com/tag/xkill" rel="tag"> xkill</a>, <a href="http://technorati.com/tag/reisub" rel="tag"> reisub</a>, <a href="http://technorati.com/tag/sysrq" rel="tag"> sysrq</a>, <a href="http://technorati.com/tag/rei+ayanami" rel="tag"> rei ayanami</a>, <a href="http://technorati.com/tag/subway" rel="tag"> subway</a>, <a href="http://technorati.com/tag/killing" rel="tag"> killing</a>, <a href="http://technorati.com/tag/linux" rel="tag"> linux</a>, <a href="http://technorati.com/tag/unix" rel="tag"> unix</a>, <a href="http://technorati.com/tag/process" rel="tag"> process</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.terminally-incoherent.com/blog/2007/10/05/how-to-kill-stuff-on-linux/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Few Useful Netcat Tricks</title>
		<link>http://www.terminally-incoherent.com/blog/2007/08/07/few-useful-netcat-tricks/</link>
		<comments>http://www.terminally-incoherent.com/blog/2007/08/07/few-useful-netcat-tricks/#comments</comments>
		<pubDate>Tue, 07 Aug 2007 16:13:50 +0000</pubDate>
		<dc:creator>Luke Maciak</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.terminally-incoherent.com/blog/2007/08/06/few-useful-netcat-tricks/</guid>
		<description><![CDATA[I always say that small, simple and self contained tools can often be more useful, and more feature rich than huge bloated frameworks. For example lets take legendary &#8220;Swiss Army Knife of Networking&#8221; &#8211; netcat. It is a single binary, which takes up about 60KB of space on your disk (give or take a few [...]]]></description>
			<content:encoded><![CDATA[<p>I always say that small, simple and self contained tools can often be more useful, and more feature rich than huge bloated frameworks. For example lets take legendary &#8220;Swiss Army Knife of Networking&#8221; &#8211; netcat. It is a single binary, which takes up about 60KB of space on your disk (give or take a few KB depending on where and how you compile it). What can it do?</p>
<p>I guess a good question is what can&#8217;t it do?</p>
<p><strong>Port Scanner</strong></p>
<p>Netcat can be a port scanner. It does not have as many features as say nmap, but if you just want to see what ports are open on a given machine, you can simply do:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">nc <span style="color: #339933;">-</span>v <span style="color: #339933;">-</span>w <span style="color: #cc66cc;">1</span> localhost <span style="color: #339933;">-</span>z <span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">3000</span></pre></div></div>

<p>The command above will scan all the ports in the range 1-3000 on localhost.</p>
<p><strong>File Transfer</strong></p>
<p>Let&#8217;s say you want to transfer a big zip file from machine A to machine B but neither one has FTP, and using email or IM is out of the question due to file size, or other restrictions. What do you do? You can use netcat as a makeshift file transfer software.</p>
<p>On machine B do the following, where 1337 is some unused port on which you want to send the file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nc <span style="color: #660033;">-lp</span> <span style="color: #000000;">1337</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file.zip</pre></div></div>

<p>Assuming that the IP of machine B is 10.48.2.40 go to machine A and do:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nc <span style="color: #660033;">-w</span> <span style="color: #000000;">1</span> 10.48.2.40 <span style="color: #000000;">1337</span> <span style="color: #000000; font-weight: bold;">&lt;</span> file.zip</pre></div></div>

<p>That&#8217;s it. The file will be magically transfered over the network socket.</p>
<p><strong>Chat Server</strong></p>
<p>Have you even needed an improvised one-on-one chat? Netcat can do that too. You simply start listening to connections on some port like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nc <span style="color: #660033;">-lp</span> <span style="color: #000000;">1337</span></pre></div></div>

<p>Then on another machine simply connect to that port:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nc 10.48.2.40 <span style="color: #000000;">1337</span></pre></div></div>

<p>Now start typing on either machine. When you press enter, the line will immediately show up on the other machine. </p>
<p><strong>Telnet Server</strong></p>
<p>Nectat can also be used to set up a telnet server in a matter of seconds. You can specify the shell (or for that matter any executable) you want netcat to run at a successful connection with the -e parameter:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nc <span style="color: #660033;">-lp</span> <span style="color: #000000;">1337</span> <span style="color: #660033;">-e</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span></pre></div></div>

<p>On windows you can use:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nc <span style="color: #660033;">-lp</span> <span style="color: #000000;">1337</span> <span style="color: #660033;">-e</span> cmd.exe</pre></div></div>

<p>Then on a client machine simply connect to port 1337 and you will get full access to the shell, with the permissions of the user who ran nc on the server.</p>
<p><strong>Spoofing HTTP Headers</strong></p>
<p>You can use netcat to connect to a server using completely spoofed headers. You can actually type out your user agent, referrer and etc. It&#8217;s useful when you want to generate bunch of hits that can be easily found in the logs or something like that:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nc google.com <span style="color: #000000;">80</span>
GET <span style="color: #000000; font-weight: bold;">/</span> HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.1</span>
Host: google.com
User-Agent: NOT-YOUR-BUSINESS
Referrer: YOUR-MOM.COM</pre></div></div>

<p>Note that your request won&#8217;t be sent until you generate a blank line. So hit return twice when your are done typing. You will get a response of headers and HTML streaming down your screen:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: PREF=ID=79f8f28c854d90ec:TM=1186369443:LM=1186369443:S=UIiTvi68MtmbcmGl; expires=Sun, 1
-Jan-2038 19:14:07 GMT; path=/; domain=.google.com
Server: GWS/2.1
Transfer-Encoding: chunked
Date: Mon, 06 Aug 2007 03:04:03 GMT
&nbsp;
738</pre></div></div>

<p>I deleted the HTML that followed the response &#8211; but you get the idea. It is also a good way of looking at headers. Some sites have nice surprises there (like slashdot&#8217;s X-Bender and X-Fry headers). Seriously, check them out!</p>
<p><strong>Web Server</strong></p>
<p>I think this is my favorite trick. Did you ever need to set up simple makeshift webserver that would serve a single page? I know I did. In the past when my web server at work melted down, I set up laptop with this simple script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">true</span>; <span style="color: #000000; font-weight: bold;">do</span> nc <span style="color: #660033;">-l</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-q</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&lt;</span> error.html; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>The error.html page was just a very simple error message notifying our users about the outage, and giving them an estimate of when it would be fixed. It took me 3 minutes to set up, and probably saved us many angry support calls.</p>
<p><strong>Cloning Hard Drive Partitions Over the Network</strong></p>
<p>This trick was submitted by Craig in the comments. On a system you want to clone do:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;"><span style="color: #000000; font-weight: bold;">if</span></span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda <span style="color: #000000; font-weight: bold;">|</span> nc 192.168.0.1 <span style="color: #000000;">9000</span></pre></div></div>

<p>Where 9000 is some random port. On the receiving side di:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nc <span style="color: #660033;">-l</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">9000</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">of</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda</pre></div></div>

<p>Of course you need to have the cloned partitions unmounted on both systems. So if you are cloning / you will have to boot from a live distro like Knoppix. Note that you can use this technique to clone NTFS partitions as well &#8211; just need to use a live Linux distro on both sides.</p>
<p><strong>Summary</strong></p>
<p>Despite being able to do all that netcat still conforms to the Unix philosophy of doing one thing, and doing it well. Netcat was designed for a single purpose &#8211; to read and write data packets over network sockets. And because of it&#8217;s singular purpose it can be used in such a myriad of ways.</p>
<p>It is ironic, but it is of ten the case that the more features you add to your application, the more specialized it gets. And of course, GUI is the ultimate functionality killer. If netcat had a GUI I doubt it would be half as useful as it is right now.</p>
<p>I&#8217;ve been told that <a href="http://www.dest-unreach.org/socat/" class="liexternal">socat</a> is a more powerful netcat fork which has even more functionality. Personally, I haven&#8217;t played with it at all. It does seem to have a different syntax, and it is not as mature or well known, and popular as it&#8217;s predecessor.</p>
<div class="simpletags">tags: <a href="http://technorati.com/tag/netcat" rel="tag">netcat</a>, <a href="http://technorati.com/tag/socat" rel="tag"> socat</a>, <a href="http://technorati.com/tag/network" rel="tag"> network</a>, <a href="http://technorati.com/tag/netcat+tricks" rel="tag"> netcat tricks</a>, <a href="http://technorati.com/tag/tricks" rel="tag"> tricks</a>, <a href="http://technorati.com/tag/unix+tricks" rel="tag"> unix tricks</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.terminally-incoherent.com/blog/2007/08/07/few-useful-netcat-tricks/feed/</wfw:commentRss>
		<slash:comments>49</slash:comments>
		</item>
		<item>
		<title>Remapping the Caps Lock Key</title>
		<link>http://www.terminally-incoherent.com/blog/2007/08/02/remapping-the-caps-lock-key/</link>
		<comments>http://www.terminally-incoherent.com/blog/2007/08/02/remapping-the-caps-lock-key/#comments</comments>
		<pubDate>Thu, 02 Aug 2007 16:20:25 +0000</pubDate>
		<dc:creator>Luke Maciak</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.terminally-incoherent.com/blog/2007/08/02/remapping-the-caps-lock-key/</guid>
		<description><![CDATA[Here is a question: when was the last time you used the Caps Lock key on purpose? When was the last time you went &#8220;hey, I wish I could type in ALL CAPS ALL THE TIME&#8221;! Chances are that unless you are a Nigerian prince in a dire need of a money transfer, your use [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a question: when was the last time you used the Caps Lock key on purpose? When was the last time you went &#8220;hey, I wish I could type in ALL CAPS ALL THE TIME&#8221;! Chances are that unless you are a Nigerian prince in a dire need of a money transfer, your use of Caps Lock is very limited.</p>
<p>In fact, I&#8217;m willing to bet that you hit that key by accident much more often, than on purpose. So why not get rid of it. And I don&#8217;t mean physically remove it &#8211; that&#8217;s just stupid. I mean, remap it to something more useful. </p>
<div align="center"><img id="image1812" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/07/croppercapture2.jpg" alt="No More Caps Lock" /></div>
<p>Since I&#8217;m a vim user, I decided to remap my Caps Lock to the Escape key. This way I can have an easily accessible <kbd>Esc</kbd> under my pinky. This way switching back to normal mode is just single movement. I don&#8217;t have to lift my left hand from the home row to hit the actual Esc, and I don&#8217;t have to do a two hand motion to use the <kbd>Ctrl+[</kbd> equivalent. Here is how you do it.</p>
<p>First open up your <kbd>~/.Xmodmap</kbd> file and add the following lines:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">remove Lock = Caps_Lock
keysym Caps_Lock = Escape</pre></div></div>

<p>Then activate your changes by doing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">xmodmap</span> ~<span style="color: #000000; font-weight: bold;">/</span>.Xmodmap</pre></div></div>

<p>If you want to map Caps Lock to a different key, simply replace <kbd>Ecape</kbd> in the sample above with something else like:</p>
<ul>
<li><kbd>Control_L</kbd> or <kbd>Control_R</kbd> for either left or right <kbd>Ctrl</kbd> key</li>
<li><kbd>Alt_L</kbd> or <kbd>Alt_R</kbd> for <kbd>Alt</kbd> or <kbd>AltGr</kbd> keys</li>
<li><kbd>Super_L</kbd> or <kbd>Super_R</kbd> for the respective <em>"Windows Logo"</em> keys</li>
<li><kbd>Shift_L</kbd> or <kbd>Shift_R</kbd> for respective shift keys</li>
</ul>
<p>Assigning it to AltGr is also an attractive idea for me, since the Caps Lock position is a bit more accessible than the usual AltGr which I use for typing Polish accented letters. I don't really see what would be the point of mapping it to Shift, but hey - maybe someone will find that useful.</p>
<p>You can find the rest of key mappings by using the <kbd>xev</kbd> utility. Just run it, and start pressing letters and you will see key codes and names for your keys. You can use the same technique to remap almost every single key on the keyboard to whatever you like. <img src='http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_mrgreen.gif' alt=':mrgreen:' class='wp-smiley' /> </p>
<div class="simpletags">tags: <a href="http://technorati.com/tag/keymap" rel="tag">keymap</a>, <a href="http://technorati.com/tag/key+mapping" rel="tag"> key mapping</a>, <a href="http://technorati.com/tag/remapping+keys" rel="tag"> remapping keys</a>, <a href="http://technorati.com/tag/caps+lock" rel="tag"> caps lock</a>, <a href="http://technorati.com/tag/remapping+caps+lock" rel="tag"> remapping caps lock</a>, <a href="http://technorati.com/tag/escape" rel="tag"> escape</a>, <a href="http://technorati.com/tag/caps+lock+to+escape" rel="tag"> caps lock to escape</a>, <a href="http://technorati.com/tag/esc" rel="tag"> esc</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.terminally-incoherent.com/blog/2007/08/02/remapping-the-caps-lock-key/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>A day without X</title>
		<link>http://www.terminally-incoherent.com/blog/2007/05/21/a-day-without-x/</link>
		<comments>http://www.terminally-incoherent.com/blog/2007/05/21/a-day-without-x/#comments</comments>
		<pubDate>Mon, 21 May 2007 18:55:02 +0000</pubDate>
		<dc:creator>Luke Maciak</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.terminally-incoherent.com/blog/2007/05/21/a-day-without-x/</guid>
		<description><![CDATA[Would you be able to survive one full day without using the X server? Linux offers us a wide assortment of CLI based tools which use curses and/or framebuffer for functional user interfaces. There is no reason why you shouldn&#8217;t be able look up stuff online, read your email, look at pictures, watch movies and [...]]]></description>
			<content:encoded><![CDATA[<p>Would you be able to survive one full day without using the X server? Linux offers us a wide assortment of CLI based tools which use curses and/or framebuffer for functional user interfaces. There is no reason why you shouldn&#8217;t be able look up stuff online, read your email, look at pictures, watch movies and listen to music as you are trying to configure X.</p>
<p>I was inspired by <a href="http://kmandla.wordpress.com/2007/05/17/more-terminal-programs-you-should-be-using-like-a-pro/" class="liexternal">this post</a> on <em>Motho ke motho ka botho</em> and decided to compile a list of useful command line applications myself. I will break them down into categories so that we can cover all the bases. If I&#8217;m missing something, or if I omitted some cool applications please let me know.</p>
<p><strong>Web Browsing</strong></p>
<p>The biggest problem in living without X is web browsing. You will be limited to text browsers, which generally do not support CSS and do not play nice with AJAX. The good news is, that most of the AJAX heavy web-pages now have <em>mobile</em> versions which are surprisingly text-browser friendly.</p>
<p>There are quite a few text browsers out there but I will recommend one:</p>
<p><em>Elinks</em> <a href="http://elinks.or.cz/" class="liexternal">[elinks.or.cz]</a></p>
<p>Why elinks? Because it supports both frames and tables, displays nice colorful output, and works great with mouse. Of course you can also use <a href="http://lynx.browser.org/" class="liexternal">Lynx</a>, <a href="http://links.sourceforge.net/" class="liexternal">Links</a>, or <a href="http://w3m.sourceforge.net/" class="liexternal">w3m</a> but in my experience elinks beats all of them hands down. Here is how my page looks in Elinks:</p>
<p><a href="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/elinks.jpg" class="imagelink" title="Screenshot of Elinks"><img id="image1602" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/elinks.jpg" alt="Screenshot of Elinks" width="450"/></a></p>
<p>There also seems to be a framebuffer browser out there called <a href="http://www.nocrew.org/software/zen/" class="liexternal">Zen</a> but it is a bit unstable no longer in active development.</p>
<p><strong>Email</strong></p>
<p>If you are a gmail user like me, you are in luck. Google has a javascript-less version of their interface which actually works beautifully in elinks:</p>
<p><a href="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/elinks2.jpg" class="imagelink" title="Gmail in Elinks"><img id="image1603" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/elinks2.jpg" alt="Gmail in Elinks" width="450"/></a></p>
<p>Neat, eh? For everything else there is Mutt:</p>
<p><em>Mutt</em> <a href="http://www.mutt.org/" class="liexternal">[mutt.org]</a></p>
<p><a href="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/mutt.jpg" class="imagelink" title="Mutt"><img id="image1604" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/mutt.jpg" alt="Mutt" width="450"/></a></p>
<p>I previously covered Mutt several times, showing you how to <a href="http://www.terminally-incoherent.com/blog/2006/09/27/using-imap-with-mutt/" class="liinternal">set it up for IMAP</a> and how to send out emails without full blown sendmail or exim setup <a href="http://www.terminally-incoherent.com/blog/2006/09/29/mutt-with-ssmtp/" class="liinternal">just using basic SSMTP</a>. There is also <a href="http://www.washington.edu/pine/" class="liexternal">Pine</a> which is a damn fine mail client too &#8211; if you can deal with editing your messages in pico.</p>
<p><strong>Chat</strong></p>
<p>Chatting without X is pretty easy. It depends on what you are into though. For example, if you are a GTalk user I can recommend the excellent Freetalk which <a href="http://www.terminally-incoherent.com/blog/2007/03/06/freetalk-a-console-based-jabber-client/" class="liinternal">I covered before</a>:</p>
<p><em>Freetalk</em> <a href="http://www.gnu.org/software/freetalk/" class="liexternal">[gnu.org/software/freetalk]</a></p>
<p><img id="image1431" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/03/freetalk.jpg" alt="Freetalk"></p>
<p>If you are on AIM, then naim will probably be the tool for you:</p>
<p><em>Naim</em> <a href="http://naim.n.ml.org/" class="liexternal">[naim.n.ml.org]</a></p>
<p><a href="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/naim.jpg" class="imagelink" title="Naim"><img id="image1605" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/naim.jpg" alt="Naim" width="450"/></a></p>
<p>Naim is a little bit funky but once you get used to it just works. It also supports ICQ and IRC protocols. Of course if you want full blown IRC support, there is probably no better client than irssi:</p>
<p><em>IRSSI</em> <a href="http://www.irssi.org/" class="liexternal">[irssi.org]</a></p>
<p><a href="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/irc.jpg" class="imagelink" title="IRSSI"><img id="image1606" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/irc.jpg" alt="IRSSI"  width="450"/></a></p>
<p>It is a bare bones but full featured client. I don&#8217;t use irc that much, so I can&#8217;t tell you how good it is, but it seems perfectly functional &#8211; especially if you are a hard core irc junky.</p>
<p><strong>Reading RSS</strong></p>
<p>If you are like me, you subscribe to way to many RSS feeds. Unfortunately neither Google Reader nor Bloglines works in elinks (or for that matter any text based browser) so we have to rely on local clients if we want to survive without X. I recommend raggle:</p>
<p><em>Raggle</em> <a href="http://www.raggle.org/" class="liexternal">[raggle.org]</a></p>
<p><a href="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/raggle.jpg" class="imagelink" title="Raggle"><img id="image1608" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/raggle.jpg" alt="Raggle" width="450"/></a></p>
<p>Raggle has a clean and intuitive interface, is fast and takes up almost no memory. Perfect for a day without X. Go ahead, import your OPML file using a command line switch, and give it a go. You can also try <a href="http://synflood.at/newsbeuter.html" class="liexternal">Newsbeuter</a>.</p>
<p>Btw, that feed list in the screenshot is the default set you get after installation. My feed list is way bigger. ;P</p>
<p><strong>File Management</strong></p>
<p>When you are not browsing, chatting, reading feed or writing emails you probably move around files on your hard drive. <em>Midnight Commander</em> will make this task easier with the classic <em>Norton Commander</em> like interface:</p>
<p><em>Midnight Commander</em> <a href="http://www.ibiblio.org/mc/" class="liexternal">[ibiblio.org/mc]</a></p>
<p><a href="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/mc.jpg" class="imagelink" title="Midnight Commander"><img id="image1607" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/mc.jpg" alt="Midnight Commander" width="450"/></a></p>
<p>You young whipper-snappers probably have no clue what Norton Commander was &#8211; but I grew up on it. Whenever I use MC I feel nostalgic for the good old days.</p>
<p><strong>Viewing Images</strong></p>
<p>So let&#8217;s say you are living your one day without X and someone sends you an awesome picture. For example it might be a picture of a cat with a caption (ZOMG! Invisible bike!). Or maybe it&#8217;s one of those demotivational posters. Hell, it can even be some <a href="http://www.codinghorror.com/blog/archives/000347.html" class="liexternal">dancing bunnies</a>!</p>
<p>So what do you do? You open it with a framebuffer image viewer like zgv of course:</p>
<p><em>ZGV</em> <a href="http://www.svgalib.org/rus/zgv/" class="liexternal">[svgalib.org/rus/zgv]</a></p>
<p>I have no screenshot for this one because you can&#8217;t run it in X, but I can confirm it works. So you will never be without your cat macros!</p>
<p><strong>Watching Video</strong></p>
<p>Sure Luke, but how do I watch my p0rnz you ask? I haven&#8217;t personally tested it, but it seems that both <a href="http://www.mplayerhq.hu/" class="liexternal">Mplayer</a> and <a href="http://www.videolan.org/" class="liexternal">VLC</a> are capable of framebuffer output. How well do they actually work in that mode &#8211; beats me. Maybe at some point I will test them out, but at this point I don&#8217;t have any solid recommendations beyond that.</p>
<p><strong>Text Editing</strong></p>
<p>If you use Linux, you should already have a near religious attachment to a text editor that can be used without X. There are essentially 4 kinds of Linux users: vim/vi users, emacs users, users who can use both editors, but neither of them well, and n00bs. And guess what &#8211; if you think that you don&#8217;t fit in any of these categories, you are a n00b. Personally &#8211; I use both, but I&#8217;m more familiar with vim than anything else. Here are my recommendations:</p>
<p><em>VIM</em> <a href="http://www.vim.org/" class="liexternal">[vim.org]</a><br />
<em>Emacs</em> <a href="http://www.gnu.org/software/emacs/" class="liexternal">[gnu.org/software/emacs]</a></p>
<p><strong>Playing Music</strong></p>
<p>The fact that you are not running X should not prevent you from listening to your favorite t00nz. Cplay is a lightweight audio player that is perfect for our X-less day:</p>
<p><em>Cplay</em> <a href="http://mask.tf.hut.fi/~flu/cplay/" class="liexternal">[mask.tf.hut.fi/~flu/cplay/]</a></p>
<p><a href="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/cplay.jpg" class="imagelink" title="Cplay"><img id="image1609" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/cplay.jpg" alt="Cplay" width="450"/></a></p>
<p>If you struggling with it, there is an awesome <a href="http://kmandla.wordpress.com/2007/05/01/howto-use-cplay-like-a-pro/" class="liexternal">overview of cplay</a> here.</p>
<p>Btw, you can always control your audio volume with alsamixer (if you have ALSA, and you probably do &#8211; you have alsamixer installed).</p>
<p><strong>P2P</strong></p>
<p>Luke! I has no Toonz! How I get some without X?</p>
<p>Well, it&#8217;s easy my friend. You can do it with rtorrent<sup>1</sup>:</p>
<p><em>RTorrent</em> <a href="http://libtorrent.rakshasa.no/" class="liexternal">[libtorrent.rakshasa.no]</a></p>
<p><a href="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/rtorrent.jpg" class="imagelink" title="RTorrent"><img id="image1610" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/rtorrent.jpg" alt="RTorrent" width="450"/></a></p>
<p>It&#8217;s yet another nifty curses application with negligible memory footprint. RTorrent can easily compete with the windows based uTorrent for size and memory. Unfortunately it is somewhat counter intuitive using Emacs like key bindings. The learning curve is a bit steep, so here is a <a href="http://kmandla.wordpress.com/2007/05/02/howto-use-rtorrent-like-a-pro/" class="liexternal">nice primer</a> to get you started.</p>
<p><strong>Window Management</strong></p>
<p>Yes, you heard me right &#8211; window management. The fact that we are not using X does not mean that we can&#8217;t have windows. <em>Twin</em> is a nifty curses app which will open sub-terminals inside a curses environment:</p>
<p><em>Twin</em> <a href="http://twin.sourceforge.net/" class="liexternal">[twin.sourceforge.net]</a></p>
<p><a href="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/twin.jpg" class="imagelink" title="Twin"><img id="image1611" src="http://www.terminally-incoherent.com/blog/wp-content/uploads/2007/05/twin.jpg" alt="Twin" width="450"/></a></p>
<p>Twin actually stands for <em>Textmode Window Environment</em> which is exactly what it is. As you can see from the screenshot, it will allow you to have elinks, mutt, raggle and essentially any other application I mentioned here today open on the same tty. How awesome is that? It removes one of the very annoying issues that we face when working without X &#8211; the inability to have multiple &#8220;windows&#8221; open on the same screen-space at the same time.</p>
<p>Will I actually attempt to survive a day without X? Maybe I will at some point. And if I do, I will definitely blog about it, and tell you about my experience. But it won&#8217;t be today because I actually have some relatively time sensitive work to do. <img src='http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Maybe we can all try this together? Let&#8217;s set a date (preferably on the weekend so we don&#8217;t struggle at work) and let&#8217;s try to survive a day without X. Let&#8217;s make it an annual linux geek holiday or something. <img src='http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_mrgreen.gif' alt=':mrgreen:' class='wp-smiley' /> </p>
<p><small><sup>1</sup> &#8211; I neither endorse nor condone downloading music. If you are downloading legally, then more power to you. If you are sharing without permission &#8211; make sure you don&#8217;t get caught.</small></p>
<p><strong>Note:</strong></p>
<p>If you want to translate this text, please go ahead as long as you give me credit and link back to this post. This work is published under Creative Commons, Non-commercial, Share-alike license.</p>
<div align="center"><a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><br />
<img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png" /></a><br /><small>This <span xmlns:dc="http://purl.org/dc/elements/1.1/" href="http://purl.org/dc/dcmitype/Text" rel="dc:type">work</span> is licensed under a<br />
<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" rel="license" class="liexternal">Creative Commons Attribution-Noncommercial-Share Alike 3.0 License</a></small>.</div>
<div class="post-update"><strong>Update 05/22/2007 10:10:11 AM</strong></p>
<p>Y HALO THAR Digg users! Thrilled to have ya here. <img src='http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_mrgreen.gif' alt=':mrgreen:' class='wp-smiley' /> </div>
<div class="simpletags">tags: <a href="http://technorati.com/tag/x" rel="tag">x</a>, <a href="http://technorati.com/tag/a+day+without+x" rel="tag"> a day without x</a>, <a href="http://technorati.com/tag/curses" rel="tag"> curses</a>, <a href="http://technorati.com/tag/ncurses" rel="tag"> ncurses</a>, <a href="http://technorati.com/tag/rtorrent" rel="tag"> rtorrent</a>, <a href="http://technorati.com/tag/cplay" rel="tag"> cplay</a>, <a href="http://technorati.com/tag/twin" rel="tag"> twin</a>, <a href="http://technorati.com/tag/elinks" rel="tag"> elinks</a>, <a href="http://technorati.com/tag/raggle" rel="tag"> raggle</a>, <a href="http://technorati.com/tag/vim" rel="tag"> vim</a>, <a href="http://technorati.com/tag/emacs" rel="tag"> emacs</a>, <a href="http://technorati.com/tag/zvg" rel="tag"> zvg</a>, <a href="http://technorati.com/tag/mplayer" rel="tag"> mplayer</a>, <a href="http://technorati.com/tag/vlc" rel="tag"> vlc</a>, <a href="http://technorati.com/tag/midnight+commander" rel="tag"> midnight commander</a>, <a href="http://technorati.com/tag/mutt" rel="tag"> mutt</a>, <a href="http://technorati.com/tag/freetalk" rel="tag"> freetalk</a>, <a href="http://technorati.com/tag/naim" rel="tag"> naim</a>, <a href="http://technorati.com/tag/irssi" rel="tag"> irssi</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.terminally-incoherent.com/blog/2007/05/21/a-day-without-x/feed/</wfw:commentRss>
		<slash:comments>190</slash:comments>
		</item>
		<item>
		<title>Awk One Liners</title>
		<link>http://www.terminally-incoherent.com/blog/2007/03/30/awk-one-liners/</link>
		<comments>http://www.terminally-incoherent.com/blog/2007/03/30/awk-one-liners/#comments</comments>
		<pubDate>Fri, 30 Mar 2007 05:16:38 +0000</pubDate>
		<dc:creator>Luke Maciak</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[awk]]></category>

		<guid isPermaLink="false">http://www.terminally-incoherent.com/blog/2007/03/30/awk-one-liners/</guid>
		<description><![CDATA[I&#8217;ve been doing this stuff all day, so let me show you few nifty awk tricks. For these examples lets assume we have a tab delimited file with n columns and m rows.
To take an average of each row (average all the values from each column of a given row do the following:
awk '{sum=0; for(i=1; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing this stuff all day, so let me show you few nifty awk tricks. For these examples lets assume we have a tab delimited file with n columns and m rows.</p>
<p>To take an average of each row (average all the values from each column of a given row do the following:</p>
<p><code>awk '{sum=0; for(i=1; i&lt;=NF; i++){sum+=$i}; sum/=NF; print sum}' file</code></p>
<p>The <kbd>NF</kbd> variable is a reserved awk word which expands to the number of fields (or columns) in the current row. If you want to take an average of all the columns do:</p>
<p><code>awk '{for(i=1; i&lt;=NF; i++){sum[i]+=$i}} END {for(i=1; i&lt;=NF; i++){printf  sum[i]/NR "\t"}}' file</code></p>
<p>The <kbd>NR</kbd> variable is another awk built-in, that gives you number of records (or rows) read. You can exploit <kbd>NR</kbd> To add line numbers to your file do:</p>
<p><code>awk '{print NR, $0}' file</code></p>
<p>Of course the same can be accomplished by:</p>
<p><code>cat -n file</code></p>
<p>To find the number of lines in a file you can do:</p>
<p><code>awk 'END {print NR}' file</code></p>
<p>If you want to find the combined number of lines in all the files passed in on the command line do:</p>
<p><code>awk 'END {print FNR}' file1 file2 file3 ...</code></p>
<p>A lot of data manipulation can be done with some awk magic, and simple unix commands such as grep, paste, wc and etc..</p>
<div class="simpletags">tags: <a href="http://technorati.com/tag/awk" rel="tag">awk</a>, <a href="http://technorati.com/tag/unix" rel="tag"> unix</a>, <a href="http://technorati.com/tag/linux" rel="tag"> linux</a>, <a href="http://technorati.com/tag/text+processing" rel="tag"> text processing</a>, <a href="http://technorati.com/tag/text+manipulation" rel="tag"> text manipulation</a>, <a href="http://technorati.com/tag/data+processing" rel="tag"> data processing</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.terminally-incoherent.com/blog/2007/03/30/awk-one-liners/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Adding new column to a text file</title>
		<link>http://www.terminally-incoherent.com/blog/2007/03/27/adding-new-column-to-a-text-file/</link>
		<comments>http://www.terminally-incoherent.com/blog/2007/03/27/adding-new-column-to-a-text-file/#comments</comments>
		<pubDate>Tue, 27 Mar 2007 19:01:53 +0000</pubDate>
		<dc:creator>Luke Maciak</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.terminally-incoherent.com/blog/2007/03/27/adding-new-column-to-a-text-file/</guid>
		<description><![CDATA[The output of some of the tests I do in my research produces pages upon pages of log files detailing what is happening to my data. This was very useful during debugging, and now it just helps me to gather and analyze data about the test runs. Since the actual output is human
readable, I usually [...]]]></description>
			<content:encoded><![CDATA[<p>The output of some of the tests I do in my research produces pages upon pages of log files detailing what is happening to my data. This was very useful during debugging, and now it just helps me to gather and analyze data about the test runs. Since the actual output is human<br />
readable, I usually need to extract the data itself out of the log files using few simple awk scripts. What I end up with are basic files with a single numeric value on each line. I graph these files using gnuplot.</p>
<p>Sometimes the stuff I want to graph is spread over several files that need to be merged. I&#8217;m posting this here because the other day saw someone opening bunch of these files and copying them one by one into Star Office spreadsheet to make a composite graph of all the data. Ugh&#8230;</p>
<p>That is way to much work. Not even mentioning that Star Office takes like a full minute to open, while flashing you with some ugly splash screen. I hate fucking splash screens. But I digress. There is a much simpler and easier way of merging simple list files on the command line.</p>
<p>Let&#8217;s assume we have two files. Our first file will look like this:</p>
<p><kbd>file1</kbd><small><code>11<br />
11<br />
111<br />
1<br />
111<br />
1<br />
111<br />
11</code></small></p>
<p>Our second file (file2) will be tab delimited list looking like this:</p>
<p><kbd>file2</kbd><small><code>22		3333<br />
222		33<br />
2		3<br />
2222		33333<br />
22		333<br />
2		3333<br />
222</code></small></p>
<p>We want to merge them both and create a file with three columns. How do you do it? There is nothing simpler than using the unix <kbd>paste</kbd> command:</p>
<p><code>$paste file1 file2 > file3</code></p>
<p>The output of this will look as follows:</p>
<p><kbd>file3</kbd><small><code>11		22		3333<br />
11		222		33<br />
111		2		3<br />
1		2222		33333<br />
111		22		333<br />
1		2		3333<br />
111		222<br />
11</code></small></p>
<p>There is one small issue that you need to watch out for &#8211; when you &#8220;paste&#8221; together two files with different rows (lines), you need to be really careful. For example, see what happens when I do the following:</p>
<p><code>$paste file2 file1 > file4</code></p>
<p>The output will look like this:</p>
<p><kbd>file4</kbd><small><code>22		3333		11<br />
222		33		11<br />
2		3		111<br />
2222		33333		1<br />
22		333		111<br />
2		3333		1<br />
222				111<br />
		11</code></small></p>
<p>Note how in the last row, the value ended up in the second column instead of the third. This is because <kbd>paste</kbd> doesn&#8217;t actually know about columns. It just glues together all the lines from the input files and puts tab in between them. You have to remember this little caveat when you paste together many files.</p>
<p>The quick workaround here is to put the &#8220;bigger&#8221; file as the first one in the command, and thus making it appear as the leftmost column. It&#8217;s probably best to pad the smaller file with an appropriate number of tabs. For example if one of your files has 25 more lines than the other one you can do:</p>
<p><code>for i in `seq 1  25`; do echo -e '\t' >> file2; done</code></p>
<p>This might be enough to make paste to do what you want it to do. For safety, paste to standard output first, before you write it to a file to make sure it looks right.</p>
<p>Oh, and if you messed up the loop, you can easily delete all the blank lines at the end with vim. Open the file, and type in <kbd>\^\n\|^\t</kbd> and hit enter to find the first line that either starts with a newline or a tab. Then press <kbd>dG</kbd> to delete everything below that line.</p>
<div class="simpletags">tags: <a href="http://technorati.com/tag/paste" rel="tag">paste</a>, <a href="http://technorati.com/tag/bash" rel="tag"> bash</a>, <a href="http://technorati.com/tag/unix" rel="tag"> unix</a>, <a href="http://technorati.com/tag/linux" rel="tag"> linux</a>, <a href="http://technorati.com/tag/text+files" rel="tag"> text files</a>, <a href="http://technorati.com/tag/columns" rel="tag"> columns</a>, <a href="http://technorati.com/tag/files" rel="tag"> files</a>, <a href="http://technorati.com/tag/lines" rel="tag"> lines</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.terminally-incoherent.com/blog/2007/03/27/adding-new-column-to-a-text-file/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Free Solaris 10 DVD&#8217;s Came in the Mail Today</title>
		<link>http://www.terminally-incoherent.com/blog/2007/03/25/the-free-solaris-10-dvds-came-in-the-mail-today/</link>
		<comments>http://www.terminally-incoherent.com/blog/2007/03/25/the-free-solaris-10-dvds-came-in-the-mail-today/#comments</comments>
		<pubDate>Sun, 25 Mar 2007 05:23:00 +0000</pubDate>
		<dc:creator>Luke Maciak</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.terminally-incoherent.com/blog/2007/03/25/the-free-solaris-10-dvds-came-in-the-mail-today/</guid>
		<description><![CDATA[I posted about Sun offering to send you Solaris 10 DVD kit free of charge few weeks ago. Today I got the DVD&#8217;s in the mail:

Awesome! Now if I only had a machine on which I could install it.   Oh well, there&#8217;s always VmWare&#8230;.
Also, I still didn&#8217;t get the Open Solaris kit.
tags: solaris, [...]]]></description>
			<content:encoded><![CDATA[<p>I posted about Sun offering to send you Solaris 10 DVD kit free of charge <a href="http://www.terminally-incoherent.com/blog/2007/03/05/get-opensolaris-cds-shipped-to-you-for-free/" class="liinternal">few weeks ago</a>. Today I got the DVD&#8217;s in the mail:</p>
<p><a href="http://www.flickr.com/photos/maciak/433177782/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/186/433177782_ca97811d2f_t.jpg" width="100" height="75" alt="The Free Solaris 10 DVD's Came in the Mail Today" /></a><a href="http://www.flickr.com/photos/maciak/433180191/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/184/433180191_2700a57a52_t.jpg" width="100" height="75" alt="The Free Solaris 10 DVD's Came in the Mail Today" /></a><a href="http://www.flickr.com/photos/maciak/433180169/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/182/433180169_850fcffe19_t.jpg" width="100" height="75" alt="The Free Solaris 10 DVD's Came in the Mail Today" /></a></p>
<p>Awesome! Now if I only had a machine on which I could install it. <img src='http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  Oh well, there&#8217;s always VmWare&#8230;.</p>
<p>Also, I still didn&#8217;t get the Open Solaris kit.</p>
<div class="simpletags">tags: <a href="http://technorati.com/tag/solaris" rel="tag">solaris</a>, <a href="http://technorati.com/tag/solaris+10" rel="tag"> solaris 10</a>, <a href="http://technorati.com/tag/free+solaris+10" rel="tag"> free solaris 10</a>, <a href="http://technorati.com/tag/solaris+10+dvd+kit" rel="tag"> solaris 10 dvd kit</a>, <a href="http://technorati.com/tag/sun" rel="tag"> sun</a>, <a href="http://technorati.com/tag/sun+microsystems" rel="tag"> sun microsystems</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.terminally-incoherent.com/blog/2007/03/25/the-free-solaris-10-dvds-came-in-the-mail-today/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
