<?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>binpoint.com &#187; Arb Unix Cmds</title>
	<atom:link href="http://binpoint.com/category/unix/auc/feed/" rel="self" type="application/rss+xml" />
	<link>http://binpoint.com</link>
	<description>A Security Blog (Stirred with Geek Life)</description>
	<lastBuildDate>Wed, 09 Jun 2010 02:02:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>AUC #2: ls</title>
		<link>http://binpoint.com/2009/05/auc-2-ls/</link>
		<comments>http://binpoint.com/2009/05/auc-2-ls/#comments</comments>
		<pubDate>Tue, 05 May 2009 00:30:12 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Arb Unix Cmds]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[ls]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://binpoint.com/?p=429</guid>
		<description><![CDATA[AUC 2 &#8211; Arbitrary Unix Command #2 I thought it might be useful to cover some obscure unix commands that you may find useful in your day to day system administration. My primary work machine is a Macbook Pro these days, so I&#8217;ll lean towards cover commands that come with OS X. Most unix operating [...]


Related posts:<ol><li><a href='http://binpoint.com/2009/03/auc-1-paste/' rel='bookmark' title='Permanent Link: AUC #1: paste'>AUC #1: paste</a></li>
<li><a href='http://binpoint.com/2009/03/complete-unix-cron-job-crib-sheet/' rel='bookmark' title='Permanent Link: Complete Unix Cron Job Crib Sheet'>Complete Unix Cron Job Crib Sheet</a></li>
<li><a href='http://binpoint.com/2010/06/quick-note-on-sorting-john-pot-files/' rel='bookmark' title='Permanent Link: Quick note on sorting john.pot files'>Quick note on sorting john.pot files</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><strong><img class="alignleft size-full wp-image-342" style="margin: 5px;" title="auc2" src="http://binpoint.com/wp-content/uploads/2009/03/auc2.png" alt="auc2" width="190" height="114" />AUC 2 &#8211; Arbitrary Unix Command #2</strong><br />
I thought it might be useful to cover some obscure unix commands that you may find useful in your day to day system administration. My primary work machine is a Macbook Pro these days, so I&#8217;ll lean towards cover commands that come with OS X. Most unix operating systems will likely have the commands I cover.</p>
<p><span id="more-429"></span>Today I wanted to talk about a command that we use every day: ls. Yes, this isn&#8217;t a very arbitrary pick, but I decided sharing useful commands to be more important than obscure.</p>
<p>If you aren&#8217;t a regular unix user, the command &#8216;ls&#8217; is equivalent to the Windows &#8216;dir&#8217; command when using cmd.exe.</p>
<p><img class="size-full wp-image-431 alignnone" title="uac2-a" src="http://binpoint.com/wp-content/uploads/2009/05/uac2-a.jpg" alt="uac2-a" width="385" height="103" /></p>
<p>It is so frequently used that nearly 10% of my bash history contains &#8216;ls&#8217;. When considering the unix mantra that every command should do only one thing, but do it well, ls is surprisingly robust.</p>
<p><img class="alignnone size-full wp-image-432" title="auc2-b" src="http://binpoint.com/wp-content/uploads/2009/05/auc2-b.jpg" alt="auc2-b" width="508" height="213" /></p>
<p>While you may be quite familiar with this command, I always recommend checking the man page for a unix command as command switches may differ depending on your system (ie: gnu commands) and more importantly you may learn something new and useful. You can do so by typing:</p>
<blockquote><p>man ls</p></blockquote>
<p><img class="alignnone size-full wp-image-433" title="auc2-c" src="http://binpoint.com/wp-content/uploads/2009/05/auc2-c.jpg" alt="auc2-c" width="501" height="278" /></p>
<p>This should look familiar. The <em>-l</em> switch produces a vertical list (just like <em>dir /p </em>in cmd.exe.) The <em>-a</em> switch includes hidden files, which are typically preceded by a period. I won&#8217;t go into detail on how to read the permissions as the internet has many such <a href="http://en.wikipedia.org/wiki/File_system_permissions#Notation_of_traditional_Unix_permissions" target="_blank">guides</a>.</p>
<p><img class="alignnone size-full wp-image-434" title="auc2-d" src="http://binpoint.com/wp-content/uploads/2009/05/auc2-d.jpg" alt="auc2-d" width="156" height="229" /></p>
<p>Lets say you are interested in only file names of a particular directory. The <em>-1</em> switch will declutter the output quite nicely and only spit out a list of filenames and not any of the meta information such as file permissions, file ownership, size, and last file modify time.</p>
<p><img class="alignnone size-full wp-image-435" title="auc2-e" src="http://binpoint.com/wp-content/uploads/2009/05/auc2-e.jpg" alt="auc2-e" width="500" height="196" /></p>
<p>Ok. So what? Perhaps you are interested in performing a command against every file (not directory) in your current working directory. The first of the two commands above produces a single line of output, space delimited list of filenames. (I have see Internet postings frowning upon the use of <em>xargs</em> to convert newlines into spaces as I have, but still need to discover a better way.)</p>
<p>The second command builds upon the first by embedding it in backticks (usually shared with the tilde key) in use with a <em>for</em> loop. The command string inside the backticks is executed first and produces a space seperated list for the <em>x</em> variable in the <em>for</em> loop to iterate through. The result is a copy and paste-able start for a bash script. I&#8217;ve used the <em>head</em> command here as a placeholder example.</p>
<p><img class="alignnone size-full wp-image-436" title="auc2-f" src="http://binpoint.com/wp-content/uploads/2009/05/auc2-f.jpg" alt="auc2-f" width="157" height="305" /></p>
<p>Another useful application of <em>ls</em> is to produce a full, recursive directory listing.</p>
<p><img class="alignnone size-full wp-image-437" title="auc2-g" src="http://binpoint.com/wp-content/uploads/2009/05/auc2-g.jpg" alt="auc2-g" width="500" height="226" /></p>
<p>Saving the best for last is my favorite <em>ls</em> command. The <em>-t</em> switch sorts by modify time, newest at top and the <em>-r</em> switch reverses the order. This is the perfect way to quickly find your recent files. It&#8217;s such a time saver, I rarely use <em>ls -al</em> anymore in favor of the above.</p>
<p>Until next time!</p>


<p>Related posts:<ol><li><a href='http://binpoint.com/2009/03/auc-1-paste/' rel='bookmark' title='Permanent Link: AUC #1: paste'>AUC #1: paste</a></li>
<li><a href='http://binpoint.com/2009/03/complete-unix-cron-job-crib-sheet/' rel='bookmark' title='Permanent Link: Complete Unix Cron Job Crib Sheet'>Complete Unix Cron Job Crib Sheet</a></li>
<li><a href='http://binpoint.com/2010/06/quick-note-on-sorting-john-pot-files/' rel='bookmark' title='Permanent Link: Quick note on sorting john.pot files'>Quick note on sorting john.pot files</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://binpoint.com/2009/05/auc-2-ls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AUC #1: paste</title>
		<link>http://binpoint.com/2009/03/auc-1-paste/</link>
		<comments>http://binpoint.com/2009/03/auc-1-paste/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 00:23:34 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Arb Unix Cmds]]></category>

		<guid isPermaLink="false">http://binpoint.com/2009/03/auc-1-paste/</guid>
		<description><![CDATA[AUC 1 &#8211; Arbitrary Unix Command #1 I thought it might be useful to cover some obscure unix commands that you may find useful in your day to day system administration. My primary work machine is a Macbook Pro these days, so I&#8217;ll lean towards cover commands that come with OS X. Most unix operating [...]


Related posts:<ol><li><a href='http://binpoint.com/2009/05/auc-2-ls/' rel='bookmark' title='Permanent Link: AUC #2: ls'>AUC #2: ls</a></li>
<li><a href='http://binpoint.com/2009/03/complete-unix-cron-job-crib-sheet/' rel='bookmark' title='Permanent Link: Complete Unix Cron Job Crib Sheet'>Complete Unix Cron Job Crib Sheet</a></li>
<li><a href='http://binpoint.com/2008/06/detectin-bad-tcp-sessions/' rel='bookmark' title='Permanent Link: Detecting bad TCP sessions'>Detecting bad TCP sessions</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><strong><img class="alignleft size-full wp-image-342" style="margin: 5px;" title="auc2" src="http://binpoint.com/wp-content/uploads/2009/03/auc2.png" alt="auc2" width="190" height="114" />AUC 1 &#8211; Arbitrary Unix Command #1</strong><br />
I thought it might be useful to cover some obscure unix commands that you may find useful in your day to day system administration. My primary work machine is a Macbook Pro these days, so I&#8217;ll lean towards cover commands that come with OS X. Most unix operating systems (OpenBSD, FreeBSD, Linux, Solaris) will likely have the commands I cover as well so only the Microsoft-only folks will be left out. (sorry)</p>
<p><span id="more-337"></span>Up first is the command that took my 15 minutes to remember at work today when I wanted to take a list with one column and seperate it into a list with two columns. Here, a visual will make this easier to explain:</p>
<p><img style="margin: 5px;" title="List of foo" src="http://binpoint.com/wp-content/uploads/2009/03/terminal-vim-8024.png" alt="List of foo" width="185" height="168" /></p>
<p>This is a list of a person and their favorite fruit. You want to convert this into a table like this:</p>
<p><img style="margin: 5px" title="Useful lookup table" src="http://binpoint.com/wp-content/uploads/2009/03/terminal-bash-8024.png" alt="Useful lookup table" /></p>
<p>But your table is 100,000 lines long and you don&#8217;t want to do it by hand, or mess with any complex regular expressions in sed, awk or a scripting language.</p>
<p>The unix command <em>paste </em>does exactly this. Here&#8217;s how simple the syntax is:</p>
<blockquote><p>cat 100k_file | paste &#8211; - &gt; lookup_table</p></blockquote>
<p>Now that&#8217;s pretty simple. Just change the number of &#8220;-&#8221;&#8216;s to how many columns you want.</p>
<p><em>paste</em> can do some other things but this is how I found it to be useful. If you have another tip on paste, the comment box below awaits.</p>


<p>Related posts:<ol><li><a href='http://binpoint.com/2009/05/auc-2-ls/' rel='bookmark' title='Permanent Link: AUC #2: ls'>AUC #2: ls</a></li>
<li><a href='http://binpoint.com/2009/03/complete-unix-cron-job-crib-sheet/' rel='bookmark' title='Permanent Link: Complete Unix Cron Job Crib Sheet'>Complete Unix Cron Job Crib Sheet</a></li>
<li><a href='http://binpoint.com/2008/06/detectin-bad-tcp-sessions/' rel='bookmark' title='Permanent Link: Detecting bad TCP sessions'>Detecting bad TCP sessions</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://binpoint.com/2009/03/auc-1-paste/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
