<?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>subprocess &#187; Bash Tips</title>
	<atom:link href="http://subprocess.net/category/tips/bash-tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://subprocess.net</link>
	<description>linux geek/dad</description>
	<lastBuildDate>Wed, 28 Apr 2010 15:12:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Bash Tip #2</title>
		<link>http://subprocess.net/2008/03/13/bash-tip-2/</link>
		<comments>http://subprocess.net/2008/03/13/bash-tip-2/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 23:34:51 +0000</pubDate>
		<dc:creator>thepet</dc:creator>
				<category><![CDATA[Bash Tips]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://subprocess.net/2008/03/13/bash-tip-2/</guid>
		<description><![CDATA[Getting around
Sure&#8230; there&#8217;s &#8220;cd&#8221; to change directories and tab completion.  But there&#8217;s more than that.  Here&#8217;s some other tips for getting around quickly in a Bash shell.
First, with &#8220;cd&#8221; there are some built in shortcuts.  Most know of &#8220;~&#8221;.  &#8220;~&#8221; expands to the current users homedir.

cd ~
cd ~/.kde
cd ~/Desktop

There&#8217;s also &#8220;-&#8221;.  [...]]]></description>
			<content:encoded><![CDATA[<h3>Getting around</h3>
<p>Sure&#8230; there&#8217;s &#8220;cd&#8221; to change directories and tab completion.  But there&#8217;s more than that.  Here&#8217;s some other tips for getting around quickly in a Bash shell.</p>
<p><span id="more-13"></span>First, with &#8220;cd&#8221; there are some built in shortcuts.  Most know of &#8220;~&#8221;.  &#8220;~&#8221; expands to the current users homedir.</p>
<ul>
<li>cd ~</li>
<li>cd ~/.kde</li>
<li>cd ~/Desktop</li>
</ul>
<p>There&#8217;s also &#8220;-&#8221;.  &#8220;-&#8221; expands to the variable of $OLDPWD, which is always the previous directory you were just in.</p>
<ol>
<li>cd /usr/local (change to /usr/local)</li>
<li>cd ~ (change to users home dir)</li>
<li>cd &#8211;  (pops you back to /usr/local)</li>
</ol>
<p>Bash bang commands can be used for shortcuts too.</p>
<ul>
<li>!! = last line in history</li>
<li>!* =  all args from last line in history</li>
<li>!$ =  last arg from last line in history</li>
<li>!^ = first arg from last line in history</li>
</ul>
<p>I really only use !$ with the cd command. Here&#8217;s some examples, although some not really useful.  Just to give you an idea of what it does:</p>
<ol>
<li>which php (maybe it outputs /usr/local/bin/php)</li>
<li>`!!` /path/to/php_script.php (executes php on the script)</li>
</ol>
<ol>
<li>ls /usr/local/src</li>
<li>cd !$ (cd&#8217;s to /usr/local/src)</li>
</ol>
<ol>
<li>ls *.gz *.txt *.bz2 (do a quick scan on the files listed, confirm they&#8217;re the right ones)</li>
<li>rm !* (remove &#8216;em all)</li>
</ol>
<p>There&#8217;s also the Alt-. (that&#8217;s alt + period) shortcut.  This will cycle through the last arg of all commands in your bash history.  Try it out, just keep hitting alt-. over and over.  Can be quite useful.</p>
<p>&#8220;pushd&#8221; and &#8220;popd&#8221;.  These are great for using in scripts.  &#8220;pushd&#8221; puts a directory on a stack and moves you to that directory.  &#8220;popd&#8221; pops your current directory off the stack and moves you to the directory under it.  Example:</p>
<p>hadley@rhadley-laptop:~$ pwd<br />
/home/rhadley<br />
rhadley@rhadley-laptop:~$ pushd /usr/<br />
/usr ~<br />
rhadley@rhadley-laptop:/usr$ pushd /usr/local/<br />
/usr/local /usr ~<br />
rhadley@rhadley-laptop:/usr/local$ pushd /etc/<br />
/etc /usr/local /usr ~<br />
rhadley@rhadley-laptop:/etc$ popd<br />
/usr/local /usr ~<br />
rhadley@rhadley-laptop:/usr/local$ popd<br />
/usr ~<br />
rhadley@rhadley-laptop:/usr$ popd<br />
~<br />
rhadley@rhadley-laptop:~$ popd<br />
bash: popd: directory stack empty<br />
rhadley@rhadley-laptop:~$</p>
<p>Well&#8230; my brain is fried and it&#8217;s too late in the day for extra caffeine, so that&#8217;ll have to be it.  But, look <a href="http://ubuntu.wordpress.com/2006/01/28/turn-on-bash-smart-completion/" target="_blank">here</a> for tips on making your tab completion more powerful.  It&#8217;ll even complete command line arguments for commands that support it.</p>
]]></content:encoded>
			<wfw:commentRss>http://subprocess.net/2008/03/13/bash-tip-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bash Tip #1</title>
		<link>http://subprocess.net/2008/03/03/bash-tip-1/</link>
		<comments>http://subprocess.net/2008/03/03/bash-tip-1/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 04:30:39 +0000</pubDate>
		<dc:creator>thepet</dc:creator>
				<category><![CDATA[Bash Tips]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Linux Bash Tips]]></category>

		<guid isPermaLink="false">http://subprocess.net/2008/03/03/bash-tip-1/</guid>
		<description><![CDATA[ Reverse Incremental Searching
Bash Tip #1: Reverse Incremental Searching.  Quickly jumping through your bash history is super easy to do if you know about reverse incremental searching.  I was shocked when I found out this existed with being a Bash lover for so long and not knowing of it.
To try it out:

Open a [...]]]></description>
			<content:encoded><![CDATA[<h3> Reverse Incremental Searching</h3>
<p>Bash Tip #1: Reverse Incremental Searching.  Quickly jumping through your bash history is super easy to do if you know about reverse incremental searching.  I was shocked when I found out this existed with being a Bash lover for so long and not knowing of it.</p>
<p><span id="more-5"></span>To try it out:</p>
<ol>
<li>Open a bash prompt on a server that you have a good size history on.</li>
<li>Press ctrl-r.</li>
<li>Type what you want to search for.</li>
</ol>
<p>As an example, say you run a web server and periodically you login and update the awstats data.  You know, on days when you know traffic is up and you don&#8217;t want to wait for the next cron&#8217;d awstats update.  And since you have it cron&#8217;d you haven&#8217;t bothered with setting up a script to do these periodic updates, so you&#8217;re lazy and just type in the awstats command by hand.  Here&#8217;s what I do:</p>
<ol>
<li> SSH to the web server.</li>
<li>Press ctrl-r.</li>
<li>Type: update.</li>
<li>Bash will then show you the last command you entered with the word &#8220;update&#8221; in it.</li>
<li>If it&#8217;s not the right command, just press ctrl-r until you find the right command.</li>
<li>Once you&#8217;re on the right command, just press enter.</li>
</ol>
<p>It&#8217;s kind of like having mini scripts saved in your history.  You just have to know what to reverse search for in order to bring it up the fastest.</p>
<p>Another example:  You just compiled php on a server the other day and it turns out the developers needed gd support compiled in.  Since you know the ./configure line is still somewhere in your history:</p>
<ol>
<li>SSH to the server with php installed on it.</li>
<li>cd to to the php src dir.</li>
<li>Press ctrl-r.</li>
<li>Type this (or as much as you need to for configure lines to show): ./config</li>
<li>If it&#8217;s the wrong ./configure line then press ctrl-r until you find the right line.</li>
<li>Once you find the right line press ctrl-e.  This should jump you to the end of that line and pop you out of reverse incremental search mode.</li>
<li>Add &#8211;with-gd and hit enter.</li>
</ol>
<p>Once you get hooked you feel uncomfortable in other shells that lack it.</p>
]]></content:encoded>
			<wfw:commentRss>http://subprocess.net/2008/03/03/bash-tip-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
