<?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>PawEng &#187; Shell</title>
	<atom:link href="http://paweng.com/category/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://paweng.com</link>
	<description>Software, hardware, and the internet</description>
	<lastBuildDate>Mon, 03 Aug 2009 00:22:00 +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>UbiquityAnywhere &#8212; Quick Access to Ubiquity From Anywhere in Windows</title>
		<link>http://paweng.com/2009/03/22/ubiquityanywhere-quick-access-to-ubiquity-from-anywhere-in-windows/</link>
		<comments>http://paweng.com/2009/03/22/ubiquityanywhere-quick-access-to-ubiquity-from-anywhere-in-windows/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 15:52:50 +0000</pubDate>
		<dc:creator>PawEng</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[PawEng Software]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://paweng.com/?p=602</guid>
		<description><![CDATA[Ubiquity is Mozilla&#8217;s new tool that adds a command line to Firefox. We reported on it back in August 2008. Since then there have been a number of enhancement and upgrades to it. It is a very useful tool. In fact, it is so useful that I often wish I could use it from anywhere [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://labs.mozilla.com/projects/ubiquity/">Ubiquity</a> is Mozilla&#8217;s new tool that adds a command line to Firefox. We <a href="http://paweng.com/2008/08/27/ubiquity-supercharge-your-firefox-with-a-command-line/">reported on it</a> back in August 2008. Since then there have been a number of enhancement and upgrades to it. It is a very useful tool. In fact, it is so useful that I often wish I could use it from anywhere in Windows &#8212; and not just from within Firefox.</p>
<p>Enter <a href="http://paweng.com/files/UbiquityAnywhere.exe">UbiquityAnywhere</a>. I created this small tool (using <a href="http://www.autohotkey.com/">AutoHotkey</a>) to give quick access to Ubiquity. UbiquityAnywhere provides two new hotkeys:</p>
<p>WIN + Q: Switch to Firefox (start it if necessary) and bring up Ubiquity.</p>
<p>WIN + W: Switch back to the application that was active when you pressed WIN + Q.</p>
<p><a href="http://paweng.com/files/UbiquityAnywhere.exe">UbiquityAnywhere</a> is a 200 kb download. It works on Windows, and requires <a href="http://firefox.com">Firefox</a> with the <a href="https://addons.mozilla.org/en-US/firefox/addon/9527">Ubiquity</a> add-on to be installed. UbiquityAnywhere assumes that you access Ubiquity with the default CTRL + SPACE key.</p>
<p><a href="http://paweng.com/files/UbiquityAnywhere.exe">UbiquityAnywhere</a> is copyrighted software (Copyright 2009 PawEng, LLC), but you may use it for free. You may not, however, distribute UbiquityAnywhere; instead, provide a link to this page. UbiquityAnywhere comes with absolutely no warranty whatsoever.</p>
<hr />
<p><small>Copyright <a href="http://paweng.com">PawEng, LLC</a>, 2009. |
<a href="http://paweng.com/2009/03/22/ubiquityanywhere-quick-access-to-ubiquity-from-anywhere-in-windows/">Permalink</a> |
</small></p>

<script src="http://feeds.feedburner.com/~s/paweng?i=<?php the_permalink() ?>" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://paweng.com/2009/03/22/ubiquityanywhere-quick-access-to-ubiquity-from-anywhere-in-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Purge Temporary Files</title>
		<link>http://paweng.com/2009/01/22/purge-temporary-files/</link>
		<comments>http://paweng.com/2009/01/22/purge-temporary-files/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 00:15:45 +0000</pubDate>
		<dc:creator>PawEng</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://paweng.com/?p=497</guid>
		<description><![CDATA[Many Linux / Unix programs create temporary files with names like &#8220;#file#&#8221; or &#8220;file~&#8221;. If a program crashes, you may be left with &#8220;core&#8221; files. These files serve a purpose, but quite often it is useful to remove them. I have been using the script below for a decade or more to keep my directories [...]]]></description>
			<content:encoded><![CDATA[<p>Many Linux / Unix programs create temporary files with names like &#8220;#file#&#8221; or &#8220;file~&#8221;. If a program crashes, you may be left with &#8220;core&#8221; files. These files serve a purpose, but quite often it is useful to remove them. I have been using the script below for a decade or more to keep my directories clean.</p>
<p><code>#!/bin/sh<br />
#<br />
# Remove temporary files<br />
#<br />
# Usage: purge [-r]<br />
#<br />
if [ "$1" = "-r" ]<br />
then<br />
  find . \( -name '#*#' -o -name '*~' -o -name '.*~' -o -name 'core' \<br />
            -o -name '*.spell' \) -print -exec rm -f {} \;<br />
else<br />
  FILES="#*# *~ .*~ core *.spell"<br />
  /bin/rm -f $FILES<br />
fi<br />
</code></p>
<p>Copy the code above to a file named &#8220;purge&#8221;, and give the file execute permissions:</p>
<p><code>% chmod a+x purge</code></p>
<p>Now write &#8220;purge&#8221; at the prompt to clean the current directory, and &#8220;purge -r&#8221; to clean recursively down into sub-directories.</p>
<hr />
<p><small>Copyright <a href="http://paweng.com">PawEng, LLC</a>, 2009. |
<a href="http://paweng.com/2009/01/22/purge-temporary-files/">Permalink</a> |
</small></p>

<script src="http://feeds.feedburner.com/~s/paweng?i=<?php the_permalink() ?>" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://paweng.com/2009/01/22/purge-temporary-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Run Linux Under Windows</title>
		<link>http://paweng.com/2009/01/04/run-linux-under-windows/</link>
		<comments>http://paweng.com/2009/01/04/run-linux-under-windows/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 15:27:19 +0000</pubDate>
		<dc:creator>PawEng</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Howto]]></category>

		<guid isPermaLink="false">http://paweng.com/?p=450</guid>
		<description><![CDATA[Now that computers have become so powerful, it is possible to simultaneously run multiple operating systems on a single computer. I like to use Windows as my main operation system, but sometimes I need access to a Linux system. Dual-booting Windows an Linux is possible, but often I want to juggle back and forth between [...]]]></description>
			<content:encoded><![CDATA[<p>Now that computers have become so powerful, it is possible to simultaneously run multiple operating systems on a single computer. I like to use Windows as my main operation system, but sometimes I need access to a Linux system. Dual-booting Windows an Linux is possible, but often I want to juggle back and forth between the two. Constantly rebooting is too painful.</p>
<p>My solution is to run Linux on a virtual computer. I downloaded <a href="http://www.microsoft.com/windows/products/winfamily/virtualpc/default.mspx">Microsoft Virtual PC 2007</a> and installed it. It is free software, and it allows you to create virtual computers on your Windows machine. There are other virtual computer solutions, but Virtual PC works for me.</p>
<p>The next step is to use Virtual PC to create a virtual Linux computer. I decided to go with <a href="http://www.debian.org/">Debian Linux</a>. It is a very stable Linux distribution. I don&#8217;t care about always getting the latest and greatest, but I do insist on stability. I downloaded the Debian 4.0 distribution CD image. I chose the 180 MB net install image available <a href="http://www.debian.org/distrib/netinst">here</a>.</p>
<p>I followed the step by step instructions by Bil Simser to create my virtual Debian Linux box: <a href="http://weblogs.asp.net/bsimser/archive/2008/11/26/visual-debian-installation-walkthrough-using-virtual-pc.aspx">Visual Debian Installation Walkthrough using Virtual PC</a>. He describes how to get a console / shell version of Linux up and running. Like him, I am not interested in the graphical desktop of Linux.</p>
<p>Once my virtual Linux box was up and running, installed <a href="http://en.wikipedia.org/wiki/Samba_(software)">Samba</a> on it. Samba allows you to access your Linux file system from within Windows. I followed the instructions on <a href="http://www.arkinex.com">Arkinex</a> for <a href="http://www.arkinex.com/guides/28/installing-and-configuring-samba-on-debian-4-etch/">Installing and Configuring Samba on Debian 4</a>.</p>
<p>Debian comes with a nice package installation system. To update my Debian computer, I simply type:</p>
<p><code>$ su -<br />
$ apt-get update<br />
$ apt-get -u dist-upgrade<br />
$ exit<br />
</code></p>
<p>I often need more than just one interactive shell at a time. You can log in to your virtual computer using a terminal program like <a href="http://www.putty.org/">putty</a>. Or you can use the <i>screen</i> command, which is a full-screen window manager that multiplexes a physical terminal between several processes. Basically, it lets you use multiple interactive shells in a single window. Read this <a href="http://www.linuxdynasty.org/screen-howto-part-1.html">quick tutorial</a> if you don&#8217;t know the <i>screen</i> command.</p>
<p>To install <i>screen</i> on your Debian virtual computer, write:</p>
<p><code>$ su -<br />
$ apt-get -u install screen<br />
$ exit<br />
</code></p>
<hr />
<p><small>Copyright <a href="http://paweng.com">PawEng, LLC</a>, 2009. |
<a href="http://paweng.com/2009/01/04/run-linux-under-windows/">Permalink</a> |
</small></p>

<script src="http://feeds.feedburner.com/~s/paweng?i=<?php the_permalink() ?>" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://paweng.com/2009/01/04/run-linux-under-windows/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cheat Sheets</title>
		<link>http://paweng.com/2008/11/24/cheat-sheets/</link>
		<comments>http://paweng.com/2008/11/24/cheat-sheets/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 01:38:38 +0000</pubDate>
		<dc:creator>PawEng</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://paweng.com/?p=353</guid>
		<description><![CDATA[Scott Klarr has collected a huge number of cheat sheets for everything from programming to Photoshop. They are organized in groups, and some groups like the Linux / Unix group contain more than 70 cheat sheets. The groups include: C, C++, C# Gimp Windows Networking Linux / Unix Designer color charts Vi &#038; Vim Emacs [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.scottklarr.com/tag/cheat-sheets/">Scott Klarr</a> has collected a huge number of cheat sheets for everything from programming to Photoshop. They are organized in groups, and some groups like the <a href="http://www.scottklarr.com/topic/115/linux-unix-cheat-sheets---the-ultimate-collection/">Linux / Unix group</a> contain more than 70 cheat sheets. The groups include:</p>
<ul>
<li>C, C++, C#</li>
<li>Gimp</li>
<li>Windows</li>
<li>Networking</li>
<li>Linux / Unix</li>
<li>Designer color charts</li>
<li>Vi &#038; Vim</li>
<li>Emacs</li>
<li>Photoshop</li>
<li>Perl</li>
<li>Regular Expressions</li>
<li>MySQL</li>
<li>PHP</li>
<li>CSS</li>
<li>Javascript / Ajax</li>
<li>Html</li>
</ul>
<p>The cheat sheets are available at <a href="http://www.scottklarr.com/tag/cheat-sheets/">Scott Klarr&#8217;s Cheat Sheet</a> page.</p>
<hr />
<p><small>Copyright <a href="http://paweng.com">PawEng, LLC</a>, 2008. |
<a href="http://paweng.com/2008/11/24/cheat-sheets/">Permalink</a> |
</small></p>

<script src="http://feeds.feedburner.com/~s/paweng?i=<?php the_permalink() ?>" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://paweng.com/2008/11/24/cheat-sheets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grep and Awk to Extract Text</title>
		<link>http://paweng.com/2008/09/10/grep-and-awk-to-extract-text/</link>
		<comments>http://paweng.com/2008/09/10/grep-and-awk-to-extract-text/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 02:06:11 +0000</pubDate>
		<dc:creator>PawEng</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://paweng.com/?p=154</guid>
		<description><![CDATA[Once you start using the command line, it is amazing how many things you can do that were difficult in a GUI system. A common task is to extract data from text files. The text files may be the output of some program, or they may be written documents like saved emails. Here are some [...]]]></description>
			<content:encoded><![CDATA[<p>Once you start using the <a href="http://paweng.com/2008/08/05/i-left-my-shell-in-the-sun-and-now-it-is-all-gui/">command line</a>, it is amazing how many things you can do that were difficult in a GUI system. A common task is to extract data from text files. The text files may be the output of some program, or they may be written documents like saved emails. Here are some of my favorite commands for working with text files.</p>
<p>The <a href="http://en.wikipedia.org/wiki/Grep">grep</a> command is used to find lines of interest in a text file. For example, to search a set of log files for errors, you can write:</p>
<p><code>grep -i error *.log</code></p>
<p>This will return all the lines containing the word &#8220;error&#8221; in the files with extension &#8220;log&#8221;. The -i option make the search case insensitive.</p>
<p>If you need a bit of context around your search use the -A (after) and -B (before) options to grep. It will return a number of lines before and after the lines that match. For example:</p>
<p><code>grep -A 3 -B 2 -i error *.log</code></p>
<p>You can also reverse a search &#8212; find lines that do not match &#8212; by using the -v option:</p>
<p><code>grep -i error *.log | grep -v "false alarm"</code></p>
<p>This will first find the errors in the log files, and then ignore the lines containing &#8220;false alarm&#8221;.</p>
<p>Sometimes you need a bit more flexibility. This is where the <a href="http://en.wikipedia.org/wiki/Awk">awk</a> command comes in. For example, assume you have the file <a href="http://www.textfiles.com/humor/JOKES/english.txt">english.txt</a> on your computer. The file contains English language signs from around the world. Assume we want to see all the signs from Tokyo. We use the awk &#8216;/pattern1/,/pattern2/&#8217; command to extract everything between pattern1 and pattern2:</p>
<p><code>awk '/Tokyo.*:\r$/,/^\r$/' english.txt</code></p>
<p>The first pattern is /Tokyo.*:/r$/. It is a <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> that matches any line that contains &#8220;Tokyo&#8221; somewhere on the line and ends with a colon. The \r is because the file has Dos/Windows newlines &#8212; simply remove the \r if the file has Unix/Linux newlines.</p>
<p>The second pattern is /^\r$/. it is a regular expression that matches blank lines. Again, remove the \r if you use a file with Unix/Linux newlines.</p>
<p>The result is:</p>
<blockquote><p>In a Tokyo hotel:<br />
 Is forbidden to steal hotel towels please. If you are not a person<br />
 to do such a thing is please not to read notis.</p>
<p>In a Tokyo bar:<br />
 Special cocktails for the ladies with nuts.</p>
<p>In a Tokyo shop:<br />
 Our nylons cost more than common, but you&#8217;ll find they are best in<br />
 the long run.</p>
<p>From a brochure of a car rental firm in Tokyo:<br />
 When passenger of foot heave in sight, tootle the horn. Trumpet him<br />
 melodiously at first, but if he still obstacles your passage<br />
 then tootle him with vigor.</p></blockquote>
<p>The awk command can do many more things. If you regularly work with text files, it is worth taking a closer look at it.</p>
<hr />
<p><small>Copyright <a href="http://paweng.com">PawEng, LLC</a>, 2008. |
<a href="http://paweng.com/2008/09/10/grep-and-awk-to-extract-text/">Permalink</a> |
</small></p>

<script src="http://feeds.feedburner.com/~s/paweng?i=<?php the_permalink() ?>" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://paweng.com/2008/09/10/grep-and-awk-to-extract-text/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unix Command Line Calculator</title>
		<link>http://paweng.com/2008/08/15/unix-command-line-calculator/</link>
		<comments>http://paweng.com/2008/08/15/unix-command-line-calculator/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 22:29:41 +0000</pubDate>
		<dc:creator>PawEng</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Calculator]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://paweng.com/?p=95</guid>
		<description><![CDATA[I spend a lot of time on a Linux / Unix command line. Often I need to do a quick calculation. I don&#8217;t want to hunt around for a fancy calculator program. I want something that works right from the command line. The bc program is a command line calculator for Linux / Unix. It [...]]]></description>
			<content:encoded><![CDATA[<p>I spend a lot of time on a Linux / Unix command line. Often I need to do a quick calculation. I don&#8217;t want to hunt around for a fancy calculator program. I want something that works right from the command line.</p>
<p>The <strong>bc</strong> program is a command line calculator for Linux / Unix. It is an arbitrary precision calculator, and it can even be programmed in a simple language. Read the <a href="http://linux.about.com/od/commands/l/blcmdl1_bc.htm">man page</a> for a complete list of what it can do.</p>
<p>Now, most of the time I just need a simple calculation done. For this purpose I have written a small program called &#8216;c&#8217; (for calculate):</p>
<p><code>#!/usr/local/bin/tcsh -f<br />
echo "$*" | bc -l</code></p>
<p>Yes, it is just two lines. You could also define it as an alias in tcsh:</p>
<p><code>alias c 'echo \!* | bc -l'</code></p>
<p>Or as a function in bash:</p>
<p><code>function c() { echo "$*" | bc -l; }</code></p>
<p>Now, to do a simple calculation on the command line, you just write:</p>
<p><code>c "1+2*3"</code></p>
<p>And you get the result 7.</p>
<p>It will also allow you to do more advanced math. For example, &#8220;s&#8221; for sine, &#8220;c&#8221; for cosine, and &#8220;e&#8221; for the exponential function, and &#8220;l&#8221; for the natual logarithm:</p>
<p><code>c "e(5)"<br />
c "s(0)"<br />
c "c(3.1415)"<br />
c "l(e(5))"</code></p>
<p>I believe the <strong>bc</strong> program is part of <a href="http://cygwin.com/">Cygwin</a> (the Linux / Unix environment for Microsoft Windows), so you should be able to get it to run on your Windows computer as well. </p>
<hr />
<p><small>Copyright <a href="http://paweng.com">PawEng, LLC</a>, 2008. |
<a href="http://paweng.com/2008/08/15/unix-command-line-calculator/">Permalink</a> |
</small></p>

<script src="http://feeds.feedburner.com/~s/paweng?i=<?php the_permalink() ?>" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://paweng.com/2008/08/15/unix-command-line-calculator/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>I left my shell in the sun and now it is all GUI</title>
		<link>http://paweng.com/2008/08/05/i-left-my-shell-in-the-sun-and-now-it-is-all-gui/</link>
		<comments>http://paweng.com/2008/08/05/i-left-my-shell-in-the-sun-and-now-it-is-all-gui/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 02:25:24 +0000</pubDate>
		<dc:creator>PawEng</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://paweng.com/?p=49</guid>
		<description><![CDATA[It seems that everything is GUI these days. Everything has to have a graphical user interface. Sure, it looks great, but is it really user-friendly? Do you really get more done with a GUI than with a command-line interface? The saying goes that when you sell software you show the managers the graphical version, but [...]]]></description>
			<content:encoded><![CDATA[<p>It seems that everything is GUI these days. Everything has to have a graphical user interface. Sure, it looks great, but is it really user-friendly? Do you really get more done with a GUI than with a command-line interface? The saying goes that when you sell software you show the managers the graphical version, but you give the engineers the command-line version.</p>
<p>A GUI is great if you don&#8217;t know a program. It shows you right there what you can do. Unfortunately, it normally requires a lot of mouse clicks; even the simplest things now require use of the mouse. And it is difficult to make different GUI programs talk to each other.</p>
<p>A good shell and some command-line tools, on the other hand, may have a steeper learning curve, but once you master them, you can do very powerful things very quickly.</p>
<p>Consider this situation: You have a number of .jpg files in multiple directories. You want to copy them all into a single directory. How would you do it in Windows? You would probably have to look in each directory and copy them separately. If you have hundreds of directories, this becomes tedious. Below I will show you how to do this with a single command in a shell.</p>
<p>I work a lot on Linux and Unix systems, and here I use the tcsh shell. If you have a Windows PC, you can download <a href="http://www.cygwin.com">Cygwin</a>. It is a Linux-like environment for Windows, and it gives you a bash shell and a set of Unix command-line tools.</p>
<h3>Completion</h3>
<p>So, what can you do with the command-line? One of the best things is completion: When you are typing in a command or a file or directory name, you can press the TAB key and the shell automatically completes as much as it can. This makes typing much faster and much less error prone. For example, try typing the following command:</p>
<p><code>more some-very-long-directory-name/some-very-long-file-name.txt</code></p>
<p>I bet it was slow and that you made at least one mistake. With completion you only have to type:</p>
<p><code>more s[TAB]s[TAB]</code></p>
<p>The first TAB key expands &#8220;s&#8221; to &#8220;some-very-long-directory-name/&#8221;, and the second time I hit TAB I get &#8220;some-very-long-file-name.txt&#8221;. In both cases I assume there is only one directory or file with a name starting with &#8220;s&#8221;. If &#8220;s&#8221; is not unique, TAB will simply expand as much as it can. And if I press TAB an extra time, the shell will show me which options are available.</p>
<h3>Gluing Commands Together</h3>
<p>On the command-line you can directly use the output of one command as the input to another command by simply placing a &#8216;|&#8217; (pipe) character between the commands. For example:</p>
<p><code>cat foo.txt | grep "something interesting" | head</code></p>
<p>Here, &#8220;cat foo.txt&#8221; will show the content of the file foo.txt, but because of the pipe, the output will not go to the screen but rather directly to the next command &#8212; in this case grep. The grep command will look for lines containing &#8220;something interesting&#8221;. Those lines are the input to the &#8220;head&#8221; command, which will display the first 10 lines of its input.</p>
<p>Another way of gluing together commands is using the back-tick operator. The shell executes what is in back-ticks, and replaces it with its output.</p>
<p><code>grep "something interesting" `cat filelist.txt`</code></p>
<p>Here the shell first executes &#8220;cat filelist.txt&#8221;. Assuming filelist.txt contains a list of files A.txt, B.txt, and C.txt, the shell replaces `cat filelist.txt` with the files:</p>
<p><code>grep "something interesting" A.txt B.txt C.txt</code></p>
<p>The grep command now looks for &#8220;something interesting&#8221; in those three files.</p>
<h3>Command-line Tools</h3>
<p>The &#8220;find&#8221; command is very powerful. It allows you to find files and optionally process them. For example, you can easily find all .jpg files in the current directory and its sub-directories, and copy them the directory /tmp:</p>
<p><code>find . -name '*.jpg' -exec cp \{\} /tmp \;</code></p>
<p>The find command will find all files matching &#8216;*.jpg&#8217;, and execute (-exec) the copy (cp) command on each of them. The \{\} expands to each file name in turn, and the \; indicates that -exec option is done.</p>
<p>The above find command calls cp for each file. If you have thousands of files, then there is a more efficient way of doing it: Use the xargs command.</p>
<p><code>find . -name '*.jpg' -print0 | xargs -0 -I cp \{\} /tmp</code></p>
<p>First the find command finds all files matching &#8216;*.jpg&#8217;. Then it passes the list of files to the xargs command. Xargs breaks the list up into pieces that will fit on the command line, and calls cp. Again, \{\} is replaced with file names, but this time each cp command will copy multiple files at once. The -print0 option to find, and the -0 option to xargs are needed to prevent problems with file names containing white spaces. The -I option to xargs tells it to insert the file names at the location of \{\} rather than at the end of the line.</p>
<h3>Final Words</h3>
<p>If this is the first time you see Unix command lines, then it probably looks like gobbledygook. It is not easy to read until you learn how to decipher the code. But once you learn it, you have a powerful set of tools at your disposal.</p>
<p>University of Cambridge has a leaflet describing  <a href="http://www.cam.ac.uk/cs/docs/leaflets/u5/">Thirty Useful Unix Commands</a>. There are many more commands out there, but these ones are good to know.</p>
<hr />
<p><small>Copyright <a href="http://paweng.com">PawEng, LLC</a>, 2008. |
<a href="http://paweng.com/2008/08/05/i-left-my-shell-in-the-sun-and-now-it-is-all-gui/">Permalink</a> |
</small></p>

<script src="http://feeds.feedburner.com/~s/paweng?i=<?php the_permalink() ?>" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://paweng.com/2008/08/05/i-left-my-shell-in-the-sun-and-now-it-is-all-gui/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
