<?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>Make Tech Easier&#187; cli</title>
	<atom:link href="http://maketecheasier.com/tag/cli/feed" rel="self" type="application/rss+xml" />
	<link>http://maketecheasier.com</link>
	<description>Uncomplicating the complicated, making life easier</description>
	<lastBuildDate>Fri, 25 May 2012 21:30:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to Multitask at the Linux Command Line with Screen</title>
		<link>http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28</link>
		<comments>http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28#comments</comments>
		<pubDate>Thu, 28 Apr 2011 14:58:17 +0000</pubDate>
		<dc:creator>Joshua Price</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://maketecheasier.com/?p=32311</guid>
		<description><![CDATA[I&#8217;ll admit up front &#8211; it&#8217;s embarrassingly late for me to have discovered screen. Friends and coworkers have been suggesting it to me for years, but it wasn&#8217;t until recently that I had a concrete need for it. Now I wish I&#8217;d had it all along. In short, screen gives... <p><div style="float:left;margin-bottom:10px"><a href="http://api.tweetmeme.com/share?url=http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28&amp;service=bit.ly" target="_blank"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28" style="border:none;margin-right:5px" width="51" height="61"></a><a href="http://digg.com/tools/diggthis/login?url=http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28" target="_blank"><img src="http://images.maketecheasier.com/diggme.png" style="border:none;margin-right:5px" ></a><a href="http://www.facebook.com/sharer.php?u=http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28" target="_blank"><img src="http://images.maketecheasier.com/fb.jpg" style="border:none;margin-right:5px" ></a><a href="http://www.google.com/reader/link?url=http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28&amp;title=How+to+Multitask+at+the+Linux+Command+Line+with+Screen&amp;srcTitle=MakeTechEasier.com" target="_blank"><img src="http://images.maketecheasier.com/gbuzz-feed.png" style="border:none;margin-right:5px" ></a><a href="http://www.stumbleupon.com/submit?url=http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28" target="_blank"><img src="http://images.maketecheasier.com/stumble.png"></a></div>
<div style="clear:both"></div>
<strong><a href="http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28">How to Multitask at the Linux Command Line with Screen</a></strong> originally published on <a href="http://maketecheasier.com">Make Tech Easier</a> (<a href="http://feedproxy.google.com/MakeTechEasier">RSS</a>)
<br/>
Follow us at <a href="http://www.facebook.com/MakeTechEasier">Facebook</a> | <a href="http://twitter.com/MakeTechEasier">Twitter</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://imagecdn.maketecheasier.com/2011/04/screencli-small.png" alt="screencli-small" title="screencli-small" width="199" height="167" class="alignleft size-full wp-image-32337" />I&#8217;ll admit up front &#8211; it&#8217;s embarrassingly late for me to have discovered <em>screen</em>. Friends and coworkers have been suggesting it to me for years, but it wasn&#8217;t until recently that I had a concrete need for it. Now I wish I&#8217;d had it all along. In short, <em>screen</em> gives you the equivalent of the &#8220;workspaces&#8221; you find in Gnome, KDE, and other desktop environments, but for the command line. It may not sound like much, but like the graphical equivalent, you begin to see the power after a few uses. Today we&#8217;re going to cover some <em>screen</em> basics useful for your home desktop but <strong>especially</strong> useful if you use remote access tools like SSH.<br />
<span id="more-32311"></span></p>
<h3>Overview</h3>
<p>Let&#8217;s say you&#8217;re at the command line, and you&#8217;re running a long process like a kernel recompile. On some machines, that can take up to an hour. An average user might sit and wait. A clever user might background the job, or use the function keys to open a new TTY login. A <em>screen</em> user, however, has already thought ahead. Had <em>screen</em> been launched first (or automatically &#8211; more on that later) that user would just hit the proper key combo to create a new shell. And another, and another, if desired. Each one operates independently of the others and all output will remain on the appropriate <em>screen</em> session.  </p>
<p>Some of you who like to use the <em>ALT-CTRL-(F1 through F4)</em> method may wonder how <em>screen</em> is any better. Several reasons actually, some of which would be:</p>
<ol>
<li>Not limited to number of function keys</li>
<li>Ability to name each screen</li>
<li>Ability to detach/reattach screen sessions</li>
<li>&#8220;Status Bar&#8221; support</li>
<li>Multi-user shared screens</li>
<li>Split screens</li>
</ol>
<p>A LOTS more.  </p>
<h3>Getting Started</h3>
<p>As <em>screen</em> is included in nearly every major Linux distro, this guide will not cover installation. The simplest way to launch <em>screen</em> is to just open a terminal and type</p>

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

<p>You might get a welcome screen, but otherwise you may not notice anything different. It just looks like a normal terminal right?  </p>
<p><img src="http://imagecdn.maketecheasier.com/2011/04/screencli-normal.png" alt="screencli-normal" title="screencli-normal" width="590" height="218" class="aligncenter size-full wp-image-32318" /></p>
<p>What you&#8217;re actually seeing is the default screen session, and you can think of it as a layer over your shell. Should you exit or detach the session, you&#8217;d be returned to your normal <em>screen</em>-less shell.  </p>
<h3>Adding and Navigating Screens</h3>
<p>For starters, you&#8217;ll need to know one major key combo. This is the &#8220;magic&#8221; key combo that lets you access all the individual commands. What is this magical combination?  <em>Ctrl-A</em>.  For example, <em>Ctrl-A</em> followed by <em>c</em> will create a new screen. <em>Ctrl-A</em> and <em>n</em> will move to the next screen in line (if one exists). The following includes many of the most common action keys (all keys are case-sensitive):</p>
<ul>
<li>c &#8211; Create a new screen</li>
<li>n &#8211; Move to next screen</li>
<li>p &#8211; Move to previous screen</li>
<li>S &#8211; Split screen into stacked regions</li>
<li>| &#8211; Split to side-by-side regions (might not work on all systems)</li>
<li>d &#8211; Detach screen</li>
<li>A &#8211; Set screen title</li>
</ul>
<h3>Attaching/Detaching Screens</h3>
<p>While there are many great uses for screen, this function could be called screen&#8217;s bread and butter. The ability to detach a screen, leaving it running, and pick it back up later is invaluable.  </p>
<p>Let&#8217;s say you&#8217;re running the <a href="http://maketecheasier.com/complete-guide-to-running-a-minecraft-server/2011/04/21">Minecraft server from last week</a>, and it&#8217;s running on an old PC under your bed. Normally if you wanted to, say, enter commands at the server console, you&#8217;d have to pull out the machine, dig out a keyboard and monitor, run your commands, and push it all back. Had the server software been started in a screen session, you can just SSH into the server, re-attach the screen, and do what you need. When done, detach the screen, and the server will keep running<em> even after you close the SSH session</em>. Days/weeks/months later, you can log back into the server and reattach that screen to enter new commands.  </p>
<h3>.screenrc</h3>
<p>Finally, we could not cover screen without at least a brief mention of the <em>~/.screenrc</em> file. There are many many uses for this file, but as this is an introductory guide, we will not cover all possible options. Instead, we&#8217;ll just point out the well-loved <em>hardstatus</em> setting.  </p>
<p>This option gives you a fantastically useful info bar that will persist across all <em>screen</em> sessions. Typically, it&#8217;s placed at the bottom and holds info such as time, hostname, and title/number of the current screen.  </p>
<p>You can find example hardstatus codes all over the net with your preferred search engine, but here are a few to get you started. </p>
<h3>#1</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hardstatus alwayslastline
hardstatus string <span style="color: #ff0000;">'%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'</span></pre></div></div>

<p><img src="http://imagecdn.maketecheasier.com/2011/04/screencli-hs1.png" alt="screencli-hs1" title="screencli-hs1" width="570" height="170" class="aligncenter size-full wp-image-32331" /></p>
<h3>#2</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hardstatus alwayslastline
hardstatus string <span style="color: #ff0000;">&quot;%{+b Rk}(%{-b g}<span style="color: #007800;">$LOGNAME</span>@%H%{+b R}) (%{-b g}%C %a%{+b R}) %{-b g} %n %t %h&quot;</span></pre></div></div>

<p><img src="http://imagecdn.maketecheasier.com/2011/04/screencli-hs2.png" alt="screencli-hs2" title="screencli-hs2" width="564" height="168" class="aligncenter size-full wp-image-32334" /></p>
<h3>#3</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hardstatus alwayslastline
hardstatus string <span style="color: #ff0000;">'%{= M} %H%{= G} %l %= %{= w}%-w%{+b r}%n*%t%{-b r}%{w}%+w %= %{c}%d %D %{B}%c '</span></pre></div></div>

<p><img src="http://imagecdn.maketecheasier.com/2011/04/screencli-hs3.png" alt="screencli-hs3" title="screencli-hs3" width="566" height="168" class="aligncenter size-full wp-image-32335" /><br />
<h3 class='related_post_title'>Related Posts:</h3>
<ul class='related_post'>
<li><a href='http://maketecheasier.com/supercharge-shell-with-bashish/2011/01/27' title='How to Supercharge Your Shell with Bashish [Linux]'>How to Supercharge Your Shell with Bashish [Linux]</a></li>
<li><a href='http://maketecheasier.com/make-iphone-secure-after-jailbreak/2010/07/26' title='How to Make Your iPhone Secure After the Jailbreak'>How to Make Your iPhone Secure After the Jailbreak</a></li>
<li><a href='http://maketecheasier.com/mastering-the-bash-history/2009/05/20' title='Mastering the Bash History'>Mastering the Bash History</a></li>
<li><a href='http://maketecheasier.com/sudo-vs-su-linux-mte-explains/2012/04/24' title='Sudo vs Su [Linux] (MTE Explains)'>Sudo vs Su [Linux] (MTE Explains)</a></li>
</ul>
<p><div style="float:left;margin-bottom:10px"><a href="http://api.tweetmeme.com/share?url=http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28&amp;service=bit.ly" target="_blank"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28" style="border:none;margin-right:5px" width="51" height="61"></a><a href="http://digg.com/tools/diggthis/login?url=http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28" target="_blank"><img src="http://images.maketecheasier.com/diggme.png" style="border:none;margin-right:5px" ></a><a href="http://www.facebook.com/sharer.php?u=http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28" target="_blank"><img src="http://images.maketecheasier.com/fb.jpg" style="border:none;margin-right:5px" ></a><a href="http://www.google.com/reader/link?url=http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28&amp;title=How+to+Multitask+at+the+Linux+Command+Line+with+Screen&amp;srcTitle=MakeTechEasier.com" target="_blank"><img src="http://images.maketecheasier.com/gbuzz-feed.png" style="border:none;margin-right:5px" ></a><a href="http://www.stumbleupon.com/submit?url=http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28" target="_blank"><img src="http://images.maketecheasier.com/stumble.png"></a></div>
<div style="clear:both"></div>
<strong><a href="http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28">How to Multitask at the Linux Command Line with Screen</a></strong> originally published on <a href="http://maketecheasier.com">Make Tech Easier</a> (<a href="http://feedproxy.google.com/MakeTechEasier">RSS</a>)
<br/>
Follow us at <a href="http://www.facebook.com/MakeTechEasier">Facebook</a> | <a href="http://twitter.com/MakeTechEasier">Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maketecheasier.com/multitask-at-linux-command-line/2011/04/28/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Fetching Files with wget</title>
		<link>http://maketecheasier.com/fetching-files-with-wget/2010/12/23</link>
		<comments>http://maketecheasier.com/fetching-files-with-wget/2010/12/23#comments</comments>
		<pubDate>Thu, 23 Dec 2010 13:00:56 +0000</pubDate>
		<dc:creator>Joshua Price</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[FTP]]></category>
		<category><![CDATA[wget]]></category>

		<guid isPermaLink="false">http://maketecheasier.com/?p=26374</guid>
		<description><![CDATA[Perhaps your X server has crashed. Or you&#8217;re working on a shell script. Or you&#8217;re SSHed into a headless server. For one reason or another, if you need to fetch a file and a web browser&#8217;s not an option, you might want to look into wget. If you&#8217;ve used the... <p><div style="float:left;margin-bottom:10px"><a href="http://api.tweetmeme.com/share?url=http://maketecheasier.com/fetching-files-with-wget/2010/12/23&amp;service=bit.ly" target="_blank"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://maketecheasier.com/fetching-files-with-wget/2010/12/23" style="border:none;margin-right:5px" width="51" height="61"></a><a href="http://digg.com/tools/diggthis/login?url=http://maketecheasier.com/fetching-files-with-wget/2010/12/23" target="_blank"><img src="http://images.maketecheasier.com/diggme.png" style="border:none;margin-right:5px" ></a><a href="http://www.facebook.com/sharer.php?u=http://maketecheasier.com/fetching-files-with-wget/2010/12/23" target="_blank"><img src="http://images.maketecheasier.com/fb.jpg" style="border:none;margin-right:5px" ></a><a href="http://www.google.com/reader/link?url=http://maketecheasier.com/fetching-files-with-wget/2010/12/23&amp;title=Fetching+Files+with+wget&amp;srcTitle=MakeTechEasier.com" target="_blank"><img src="http://images.maketecheasier.com/gbuzz-feed.png" style="border:none;margin-right:5px" ></a><a href="http://www.stumbleupon.com/submit?url=http://maketecheasier.com/fetching-files-with-wget/2010/12/23" target="_blank"><img src="http://images.maketecheasier.com/stumble.png"></a></div>
<div style="clear:both"></div>
<strong><a href="http://maketecheasier.com/fetching-files-with-wget/2010/12/23">Fetching Files with wget</a></strong> originally published on <a href="http://maketecheasier.com">Make Tech Easier</a> (<a href="http://feedproxy.google.com/MakeTechEasier">RSS</a>)
<br/>
Follow us at <a href="http://www.facebook.com/MakeTechEasier">Facebook</a> | <a href="http://twitter.com/MakeTechEasier">Twitter</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://imagecdn.maketecheasier.com/2010/12/wget-small.png" alt="" title="wget-small" width="128" height="128" class="alignleft size-full wp-image-26379" />Perhaps your X server has crashed.  Or you&#8217;re working on a shell script.  Or you&#8217;re SSHed into a headless server.  For one reason or another, if you need to fetch a file and a web browser&#8217;s not an option, you might want to look into wget.  If you&#8217;ve used the Linux shell much and worked with scripts or package installers, there&#8217;s a good chance you&#8217;ve seen wget in action.  At the simplest level, it does just what the name implies and gets a file from the web (or FTP).  Underneath that, though, is some clever functionality.<br />
<span id="more-26374"></span></p>
<h3>The Basics</h3>
<p>As noted above, wget is most commonly used to quickly grab a file from somewhere on the web.  </p>
<p><pre lang="bash">wget http://mydomain.com/file.zip</pre></p>
<p>Which would simply grab the file and save it to the current directory.  </p>
<p>If you want to save to a different filename or different location, you use the -O flag.</p>
<p><pre lang="bash">#Remember it&#8217;s a capital &quot;O&quot; not zero or small &quot;o&quot;<br />
wget http://download.maketecheasier.com/Firefox_shortcut_keys.pdf -O Documents/ffkeys.pdf</pre></p>
<p><img src="http://imagecdn.maketecheasier.com/2010/12/wget-dashO.png" alt="" title="wget-dashO" width="514" height="277" class="aligncenter size-full wp-image-26375" /></p>
<p>You may be downloading multiple files, in which case you may want to specify a location for all downloads.  Just use the<em> -P</em> flag (or  <em>&#8211;directory-prefix=LOCATION</em>) to specify where they go.  </p>
<p>As you can see, that&#8217;s a lot of output.  Let&#8217;s try the <em>-q</em> option to clean it up, making it more suitable for scripts.  </p>
<p><pre lang="bash">wget -q http://mydomain.com/file.zip</pre></p>
<p><img src="http://imagecdn.maketecheasier.com/2010/12/wget-dashq.png" alt="" title="wget-dashq" width="516" height="149" class="aligncenter size-full wp-image-26376" /></p>
<p>Similarly, you can use the <em>-nv</em> option for just a <em>little</em> output, but not as much as the default.  </p>
<h3>Fancy stuff</h3>
<p>What if your download failed, and you want to resume?  What if the file already exists, and you don&#8217;t want to overwrite it?  There are options to handle those as well as several other situations.  </p>
<p>To resume a broken download, you&#8217;d use the <em>-c</em> flag (or <em>&#8211;continue</em>)</p>
<p>If you need to make sure your command (or script) doesn&#8217;t overwrite any existing files, use the <em>-nc</em> option (for no-clobber)</p>
<p><img src="http://imagecdn.maketecheasier.com/2010/12/wget-dashnc.png" alt="" title="wget-dashnc" width="518" height="74" class="aligncenter size-full wp-image-26377" /></p>
<p>There are times when you can&#8217;t be certain if filenames will be case-sensitive on both ends, but the <em>&#8211;ignore-case</em> flag will negate that problem.  </p>
<p>To limit the download rate, use the &#8211;limit-rate=RATE option, as demonstrated below.  </p>
<p><pre lang="bash">wget &#8211;limit-rate=20000 http://ftp.us.debian.org/debian-cd/5.0.7/amd64/iso-cd/debian-507-amd64-netinst.iso</pre></p>
<p><img src="http://imagecdn.maketecheasier.com/2010/12/wget-limit.png" alt="" title="wget-limit" width="514" height="227" class="aligncenter size-full wp-image-26378" /></p>
<h3>FTP Options</h3>
<p>As noted earlier, wget supports FTP as well.  If you just specify a FTP site, like </p>
<p><pre lang="bash">wget ftp://ftp.us.debian.org/debian-cd/5.0.7/amd64/iso-cd/debian-507-amd64-netinst.iso</pre></p>
<p>wget will assume you want an anonymous login.  If that&#8217;s not the case, you can manually specify things like username and password with the following flags:</p>
<ul>
<li>&#8211;ftp-user=USER         Specifies the username for login</li>
<li>&#8211;ftp-password=PASS     Specifies password</li>
<li>&#8211;no-passive-ftp        Disables passive transfer mode.</li>
</ul>
<p>As well as a few others for advanced use cases.  </p>
<h3>Timeouts, Retries, and Failed Downloads</h3>
<p>Finally, wget comes with several options relating to server connection problems and timeouts.  Not all failures can be dealt with of course, but the following flags are all intended to help deal with server issues:</p>
<ul>
<li>&#8211;tries=NUMBER            Specify number of times to retry download</li>
<li>&#8211;retry-connrefused       Retry download even if connection is refused by server.</li>
<li>&#8211;continue                      Resumes an incomplete download, used as <em>-c</em> above</li>
<li>&#8211;timeout=SECONDS     Global setting &#8211; how long to wait before timeouts</li>
<li>&#8211;wait=SECONDS          How long to wait between successful downloads (if repeating)</li>
</ul>
<h3>Conclusion</h3>
<p>For such a simple, basic, built-in utility, wget has a surprising amount to offer.  Next time you find yourself writing an internet-aware shell script, or needing to get that missing driver file on your broken computer, give wget a shot.  If you&#8217;ve got any interesting stories about how wget has got you out of a jam, let us know in the comments below.  </p>
<h3 class='related_post_title'>Related Posts:</h3>
<ul class='related_post'>
<li><a href='http://maketecheasier.com/10-more-funny-andor-useless-linux-commands/2012/05/10' title='10 More Funny and/or Useless Linux Commands'>10 More Funny and/or Useless Linux Commands</a></li>
<li><a href='http://maketecheasier.com/beginners-guide-to-sed-linux/2012/03/29' title='Beginner&#8217;s Guide to Sed [Linux]'>Beginner&#8217;s Guide to Sed [Linux]</a></li>
<li><a href='http://maketecheasier.com/install-a-minimal-ubuntu-on-old-laptop/2012/02/24' title='How to Install A Minimal (And Non-Bloated) Ubuntu On Your Old Laptop'>How to Install A Minimal (And Non-Bloated) Ubuntu On Your Old Laptop</a></li>
<li><a href='http://maketecheasier.com/knowing-linux-system-via-the-command-line/2012/02/23' title='Knowing Your Linux System Via the Command Line'>Knowing Your Linux System Via the Command Line</a></li>
</ul>
<p><div style="float:left;margin-bottom:10px"><a href="http://api.tweetmeme.com/share?url=http://maketecheasier.com/fetching-files-with-wget/2010/12/23&amp;service=bit.ly" target="_blank"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://maketecheasier.com/fetching-files-with-wget/2010/12/23" style="border:none;margin-right:5px" width="51" height="61"></a><a href="http://digg.com/tools/diggthis/login?url=http://maketecheasier.com/fetching-files-with-wget/2010/12/23" target="_blank"><img src="http://images.maketecheasier.com/diggme.png" style="border:none;margin-right:5px" ></a><a href="http://www.facebook.com/sharer.php?u=http://maketecheasier.com/fetching-files-with-wget/2010/12/23" target="_blank"><img src="http://images.maketecheasier.com/fb.jpg" style="border:none;margin-right:5px" ></a><a href="http://www.google.com/reader/link?url=http://maketecheasier.com/fetching-files-with-wget/2010/12/23&amp;title=Fetching+Files+with+wget&amp;srcTitle=MakeTechEasier.com" target="_blank"><img src="http://images.maketecheasier.com/gbuzz-feed.png" style="border:none;margin-right:5px" ></a><a href="http://www.stumbleupon.com/submit?url=http://maketecheasier.com/fetching-files-with-wget/2010/12/23" target="_blank"><img src="http://images.maketecheasier.com/stumble.png"></a></div>
<div style="clear:both"></div>
<strong><a href="http://maketecheasier.com/fetching-files-with-wget/2010/12/23">Fetching Files with wget</a></strong> originally published on <a href="http://maketecheasier.com">Make Tech Easier</a> (<a href="http://feedproxy.google.com/MakeTechEasier">RSS</a>)
<br/>
Follow us at <a href="http://www.facebook.com/MakeTechEasier">Facebook</a> | <a href="http://twitter.com/MakeTechEasier">Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maketecheasier.com/fetching-files-with-wget/2010/12/23/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mastering the Bash History</title>
		<link>http://maketecheasier.com/mastering-the-bash-history/2009/05/20</link>
		<comments>http://maketecheasier.com/mastering-the-bash-history/2009/05/20#comments</comments>
		<pubDate>Wed, 20 May 2009 12:32:08 +0000</pubDate>
		<dc:creator>Joshua Price</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[history]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://maketecheasier.com/?p=4706</guid>
		<description><![CDATA[The Bourne Again Shell, better known as bash, is the default for most Linux distributions. It&#8217;s extremely powerful as far as command shells go, and holds all kinds of nifty tricks for those willing to learn. One of the best features is, in my opinion, the command history system. There... <p><div style="float:left;margin-bottom:10px"><a href="http://api.tweetmeme.com/share?url=http://maketecheasier.com/mastering-the-bash-history/2009/05/20&amp;service=bit.ly" target="_blank"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://maketecheasier.com/mastering-the-bash-history/2009/05/20" style="border:none;margin-right:5px" width="51" height="61"></a><a href="http://digg.com/tools/diggthis/login?url=http://maketecheasier.com/mastering-the-bash-history/2009/05/20" target="_blank"><img src="http://images.maketecheasier.com/diggme.png" style="border:none;margin-right:5px" ></a><a href="http://www.facebook.com/sharer.php?u=http://maketecheasier.com/mastering-the-bash-history/2009/05/20" target="_blank"><img src="http://images.maketecheasier.com/fb.jpg" style="border:none;margin-right:5px" ></a><a href="http://www.google.com/reader/link?url=http://maketecheasier.com/mastering-the-bash-history/2009/05/20&amp;title=Mastering+the+Bash+History&amp;srcTitle=MakeTechEasier.com" target="_blank"><img src="http://images.maketecheasier.com/gbuzz-feed.png" style="border:none;margin-right:5px" ></a><a href="http://www.stumbleupon.com/submit?url=http://maketecheasier.com/mastering-the-bash-history/2009/05/20" target="_blank"><img src="http://images.maketecheasier.com/stumble.png"></a></div>
<div style="clear:both"></div>
<strong><a href="http://maketecheasier.com/mastering-the-bash-history/2009/05/20">Mastering the Bash History</a></strong> originally published on <a href="http://maketecheasier.com">Make Tech Easier</a> (<a href="http://feedproxy.google.com/MakeTechEasier">RSS</a>)
<br/>
Follow us at <a href="http://www.facebook.com/MakeTechEasier">Facebook</a> | <a href="http://twitter.com/MakeTechEasier">Twitter</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-4801" src="http://imagecdn.maketecheasier.com/2009/05/bash-history-terminal.png" alt="bash-history-terminal" width="200" height="178" />The <em>Bourne Again Shell</em>, better known as <em>bash</em>, is the default for most Linux distributions.  It&#8217;s extremely powerful as far as command shells go, and holds all kinds of nifty tricks for those willing to learn.  One of the best features is, in my opinion, the command history system.</p>
<p>There are many options to use with the bash history, some of them I use nearly every time I open a command shell.  Today I&#8217;ll be covering some of the most useful aspects of the history, but I certainly won&#8217;t be able to cover them all.<br />
<span id="more-4706"></span></p>
<h3>Up/Down Arrows</h3>
<p>Many of you probably know this one, but for anyone who doesn&#8217;t, it&#8217;ll make your life a lot easier.  Any time you&#8217;re in the command shell, simply use the up and down arrows on your keyboard to move through the list of previously entered commands.  Next time you enter a long command that turns out to have a typo, you don&#8217;t have to retype the whole thing just hit the up arrow and make whatever edits are needed.</p>
<h3>!!</h3>
<p>A similar feature to the one listed above is the double bang (!!).  Those characters entered in the shell represent the last typed command.  Let&#8217;s say you&#8217;re trying to run a command only to find out that you need root privileges to do it.  Instead of retyping the whole command, you can simply enter</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></pre></div></div>

<p>Bash will substitute the !! for the previous command, as in the example below.</p>
<p><img class="aligncenter size-full wp-image-4772" src="http://imagecdn.maketecheasier.com/2009/05/bash-history-bangbang.png" alt="bash-history-bangbang" width="367" height="103" /></p>
<p>This also works further backward, you can do something like</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">!</span>-<span style="color: #000000;">5</span></pre></div></div>

<p>to recall the command 5 entries back in the history.</p>
<h3>!(word)</h3>
<p>Perhaps a few days ago you typed a long, complex command into your shell, for example a series of options for &#8220;wterm&#8221;.  You can find and re-enter than command by using the history&#8217;s built in search.  You simply add the first few letters of the command after the ! and bash will find it.</p>
<p><img class="aligncenter size-full wp-image-4778" src="http://imagecdn.maketecheasier.com/2009/05/bash-history-bangword.png" alt="Example of !(word)" width="464" height="95" /></p>
<p><em>Be careful with this one.  You may end up running something other than what you expected.  Don&#8217;t use this for potentially dangerous commands like &#8220;rm&#8221; or &#8220;fdisk&#8221;. </em></p>
<h3>!?(word)</h3>
<p>This is similar to the last feature in that it searches the history for the word entered, but unlike !(word) this will find the word anywhere in the command, not just the beginning.</p>
<p><img class="aligncenter size-full wp-image-4781" src="http://imagecdn.maketecheasier.com/2009/05/bash-history-bangquestion.png" alt="bash-history-bangquestion" width="454" height="70" /></p>
<p><em>Be careful with this one.  You may end up running something other than what you expected.  Don&#8217;t use this for potentially dangerous commands like &#8220;rm&#8221; or &#8220;fdisk&#8221;. </em></p>
<h3>Ctrl-R</h3>
<p>This one may be my personal favorite history tool.  It&#8217;s a bit like the <em>!?</em> item above, but interactive.  In your command shell, hit <em>Ctrl-R</em>, and it will begin a search.  As you type, bash will search the history and show you the results as you type.  When it shows the command you want, simply hit enter and it will run that command.  This can be safer than things like <em>!?</em> because you can see what the command will be before you run it, so you don&#8217;t have to guess or rely on memory.</p>
<p><img class="aligncenter size-full wp-image-4789" src="http://imagecdn.maketecheasier.com/2009/05/bash-history-ctrl-r.png" alt="Example of Ctrl-R in the shell" width="515" height="37" /></p>
<h3>Manual Search</h3>
<p>Perhaps you don&#8217;t like the way Ctrl-R works, or you want to see ALL the commands you typed, or just the ones that contain a particular word.  The <em>history</em> command will show you your full command history, along with the history number of each command (hold that thought, we&#8217;ll cover those numbers in a moment).</p>
<p>You can also specify the number of items the <em>history</em> command will show.  To see the last 10 entries in the history, you could type</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">history</span> <span style="color: #000000;">10</span></pre></div></div>

<p>To see all history entries that contain a particular word, you can use <em>grep </em>to filter the results, like below.</p>
<p><img class="aligncenter size-full wp-image-4794" src="http://imagecdn.maketecheasier.com/2009/05/bash-history-grep.png" alt="Example of using grep to filter history list" width="351" height="122" /></p>
<h3>!(number)</h3>
<p>When you use the <em>history</em> command to view your command history list, you&#8217;ll notice each item in the list has a number associated with it.  You can use that to recall that particular command.  For example, item 87 could be run again by entering</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">!</span><span style="color: #000000;">87</span></pre></div></div>

<p>into your shell.</p>
<h3>Word replacement</h3>
<p>This one&#8217;s pretty great.  How many times have you written out some big long command only to realize you put, say, <em>hdd</em> when you wanted <em>hdc</em>?  Well bash has you covered.  You can replace a word in the previous command with another using &#8220;^&#8221;, as in the example below</p>
<p><img class="aligncenter size-full wp-image-4798" src="http://imagecdn.maketecheasier.com/2009/05/bash-history-wordreplacement1.png" alt="Example of word replacement with &quot;^&quot;" width="540" height="104" /></p>
<h3>Managing Your History</h3>
<p>By default, the history is saved in ~/.bash_history.  You can deal with this file however you see fit, but there are some useful things you could try to manage it automatically.  Namely, setting the environment variables <strong>HISTSIZE</strong> and <strong>HISTFILESIZE</strong>.  To set the number of entries that can be saved in the history file to 1000, enter</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTFILESIZE</span>=<span style="color: #000000;">1000</span></pre></div></div>

<p>into your shell.  This will limit the file to 1000 entries.  If you want to make this change permanent, put that export command into your .bashrc or .bash_profile file.</p>
<p><!--adsense#468x60--><br />
<h3 class='related_post_title'>Related Posts:</h3>
<ul class='related_post'>
<li><a href='http://maketecheasier.com/write-linux-shell-scripts/2011/06/30' title='The Beginner Guide to Writing Linux Shell Scripts'>The Beginner Guide to Writing Linux Shell Scripts</a></li>
<li><a href='http://maketecheasier.com/8-useful-and-interesting-bash-prompts/2009/09/04' title='8 Useful and Interesting Bash Prompts'>8 Useful and Interesting Bash Prompts</a></li>
<li><a href='http://maketecheasier.com/making-the-linux-command-line-a-little-friendlier/2009/03/19' title='Making The Linux Command Line A Little Friendlier'>Making The Linux Command Line A Little Friendlier</a></li>
<li><a href='http://maketecheasier.com/remove-recent-history-lists-in-ubuntu/2012/02/20' title='How to Remove Recent History Lists In Ubuntu 11.10'>How to Remove Recent History Lists In Ubuntu 11.10</a></li>
</ul>
<p><div style="float:left;margin-bottom:10px"><a href="http://api.tweetmeme.com/share?url=http://maketecheasier.com/mastering-the-bash-history/2009/05/20&amp;service=bit.ly" target="_blank"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://maketecheasier.com/mastering-the-bash-history/2009/05/20" style="border:none;margin-right:5px" width="51" height="61"></a><a href="http://digg.com/tools/diggthis/login?url=http://maketecheasier.com/mastering-the-bash-history/2009/05/20" target="_blank"><img src="http://images.maketecheasier.com/diggme.png" style="border:none;margin-right:5px" ></a><a href="http://www.facebook.com/sharer.php?u=http://maketecheasier.com/mastering-the-bash-history/2009/05/20" target="_blank"><img src="http://images.maketecheasier.com/fb.jpg" style="border:none;margin-right:5px" ></a><a href="http://www.google.com/reader/link?url=http://maketecheasier.com/mastering-the-bash-history/2009/05/20&amp;title=Mastering+the+Bash+History&amp;srcTitle=MakeTechEasier.com" target="_blank"><img src="http://images.maketecheasier.com/gbuzz-feed.png" style="border:none;margin-right:5px" ></a><a href="http://www.stumbleupon.com/submit?url=http://maketecheasier.com/mastering-the-bash-history/2009/05/20" target="_blank"><img src="http://images.maketecheasier.com/stumble.png"></a></div>
<div style="clear:both"></div>
<strong><a href="http://maketecheasier.com/mastering-the-bash-history/2009/05/20">Mastering the Bash History</a></strong> originally published on <a href="http://maketecheasier.com">Make Tech Easier</a> (<a href="http://feedproxy.google.com/MakeTechEasier">RSS</a>)
<br/>
Follow us at <a href="http://www.facebook.com/MakeTechEasier">Facebook</a> | <a href="http://twitter.com/MakeTechEasier">Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maketecheasier.com/mastering-the-bash-history/2009/05/20/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (Feed is rejected)
Page Caching using disk: enhanced
Content Delivery Network via Amazon Web Services: CloudFront: cdn.maketecheasier.com

Served from: maketecheasier.com @ 2012-05-25 15:12:16 -->
