<?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>/home/spsneo/blog &#187; Man pages</title>
	<atom:link href="http://spsneo.com/blog/category/linux/man-pages/feed/" rel="self" type="application/rss+xml" />
	<link>http://spsneo.com/blog</link>
	<description>Trying to move every bit to cloud.</description>
	<lastBuildDate>Fri, 19 Aug 2011 16:43:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Bash History Tips and Tricks</title>
		<link>http://spsneo.com/blog/2009/09/19/bash-history-tips-and-tricks/</link>
		<comments>http://spsneo.com/blog/2009/09/19/bash-history-tips-and-tricks/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 18:48:35 +0000</pubDate>
		<dc:creator>spsneo</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Man pages]]></category>
		<category><![CDATA[History]]></category>

		<guid isPermaLink="false">http://spsneo.com/blog/?p=96</guid>
		<description><![CDATA[Bash supports history expansion feature which can be very useful for powerful command-line users. According to bash manual page - History  expansions introduce words from the history list into the input stream, making it easy to repeat commands, insert the &#8230; <a href="http://spsneo.com/blog/2009/09/19/bash-history-tips-and-tricks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Bash supports history expansion feature which can be very useful for powerful command-line users.</p>
<p>According to bash manual page -</p>
<blockquote><p>History  expansions introduce words from the history list into the input stream, making it easy to repeat commands, insert the arguments to a previous command into the current input line, or fix errors in previous commands quickly.</p></blockquote>
<p>History expansion is composed of three parts -</p>
<ul>
<li><strong>Event Designators:</strong> It is a reference to an entry in the history list.</li>
<li><strong>Word Designators:</strong> It is used to select a word from the event.</li>
<li><strong>Modifiers:</strong> Modifies the word selected by the word designator or the action of the command.</li>
</ul>
<p>All the three parts are optional and are separated from each other by a : (colon). There can be multiple modifiers each separated by a : (colon).</p>
<p>Now I will explain each part one by one.</p>
<p><strong>Event Designators:</strong></p>
<ol>
<li><strong>! </strong>Start a history substitution, except when followed by a <strong>blank, </strong>newline, carriage return,  = or (</li>
<li><strong>!n </strong>It refers to n&#8217;th command in the history. So if you just type in<br />
<code>!68</code> at the command prompt, 68th command in your history list will be executed.</li>
<li><strong>!-n</strong> It refers to n&#8217;th command in the history from last. So if you just type in !-1 at the command prompt, last command will be executed.<strong> </strong></li>
<li><strong>!!</strong> is an alias for !-1.  Example:<br />
<code>$apt-get install gnome-ppp    //Permission Denied. You need to be sudo to do this!<br />
$sudo !!                      // This is equivalent to sudo apt-get install gnome-ppp</code><strong> </strong></li>
<li><strong>!<span style="text-decoration: underline;">string</span> </strong>It refers to the most recent command in the history starting with <span style="text-decoration: underline;">string</span>. It is again an useful expansion when you don&#8217;t remember the arguments to a command which you have executed earlier.</li>
<li><strong>!?<span style="text-decoration: underline;">string</span>[?] </strong>It refers to the most recent command containing <span style="text-decoration: underline;">string</span>. The trailing <strong>? </strong>may be omitted if <span style="text-decoration: underline;">string</span> is immediately followed by a newline.</li>
</ol>
<p><strong>Word Designators:</strong></p>
<ol>
<li><strong><span style="text-decoration: underline;">n</span> </strong>The <span style="text-decoration: underline;">n</span>th word, count starting from 0. 0th word normally refers to the command. Example:<br />
<code>$sudo cat /etc/resolv.conf     //Instead you want to edit the resolv.conf file<br />
$sudo vi !!:2                       //This is equivalent to sudo vi /etc/resolv.conf</code><strong> </strong></li>
<li><strong> ^ </strong>This refers to 1st word. This is equivalent to <strong>:1 </strong>as refered above. The only .advantage is that you can omit : (colon) when you use ^. Example:<br />
<code> $cat ~/.bashrc<br />
$vi !!^        //This is equivalent to "vi !!:1" that is vi ~/.bashrc<br />
</code></li>
<li>$ This refers to the last word.</li>
<li><span style="text-decoration: underline;"><strong>x</strong></span><strong>-<span style="text-decoration: underline;">y</span> </strong>This refers to a range of words; &#8216;<strong>-<span style="text-decoration: underline;">y</span></strong>&#8216; is equivalent to &#8217;0-y&#8217;.</li>
<li><strong>* </strong>This refers to all the words except the 0th one. This is helpful when you have to execute a command with all the arguments passed to the last command.</li>
<li><span style="text-decoration: underline;"><strong>x</strong></span><strong>* </strong>This is an alias for <span style="text-decoration: underline;">x</span>-$ .</li>
</ol>
<p>Note: If a word designator is used without an event specification, the last command in the history is used as the event. Example -<br />
<code>$cat ~/.bashrc<br />
$vi !:1</code> // This is equivalent to vi !!:1 or vi ~/.bashrc</p>
<p><strong>Modifiers:</strong></p>
<ol>
<li><strong>h</strong> This removes the trailing file name component, leaving the head. Example:<br />
<code>$cat /home/spsneo/.bashrc<br />
$ls !!:1:h </code>//This expands to <code>ls /home/spsneo</code>Explanation: !! refers to the last command and then :1 refers to the 1st word of the last command and then :h removes the trailing file name component i.e., .bashrc . Hence the expansion.</li>
<li><strong>t</strong> This removes all leading file name components, leaving the tail.</li>
<li><strong>r </strong>This removes the trailing suffix of the form <span style="text-decoration: underline;"><strong>.xxx</strong></span> , leaving the basename.</li>
<li><strong>p </strong>Print the new command but do not execute it.</li>
<li><strong>s/<span style="text-decoration: underline;">old</span>/<span style="text-decoration: underline;">new</span></strong> This substitutes the first occurrence of <span style="text-decoration: underline;">old</span> with <span style="text-decoration: underline;">new</span>. Example:<br />
<code>$cat /etc/resolv.conf<br />
$!!:s/resolv/yum</code> //This expands to <code>cat /etc/yum.conf</code><strong><code><br />
</code></strong></li>
<li><strong>g </strong>This is used in conjunction with &#8220;<strong>:s</strong>&#8221; modifier. This causes changes to be applied over the entire event line rather than just the first occurrence. Example:<br />
<code>$cat test.cpp test.h<br />
$!!:gs/test/source/ </code> //This expands to <code>cat source.cpp source.hh</code></li>
</ol>
<p>This is all I have to share about bash history expansion.</p>
<p>Do post comments if you find any mistake or if you want any further clarifications. One can also go through the bash manual pages for more options.</p>
]]></content:encoded>
			<wfw:commentRss>http://spsneo.com/blog/2009/09/19/bash-history-tips-and-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Colourful man pages in Ubuntu</title>
		<link>http://spsneo.com/blog/2008/07/21/colourful-man-pages-in-ubuntu/</link>
		<comments>http://spsneo.com/blog/2008/07/21/colourful-man-pages-in-ubuntu/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 14:10:22 +0000</pubDate>
		<dc:creator>spsneo</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Man pages]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://spsneo.com/blog/?p=17</guid>
		<description><![CDATA[Linux man pages are the most important resource for a Linux freak. By default man pages are formatted using the &#8216;less&#8217; utility. &#8216;less&#8217; shows the man pages in black &#38; white, something like this : If you use &#8216;most&#8217; utility &#8230; <a href="http://spsneo.com/blog/2008/07/21/colourful-man-pages-in-ubuntu/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Linux man pages are the most important resource for a Linux freak. By default man pages are formatted using the &#8216;less&#8217; utility. &#8216;less&#8217; shows the man pages in black &amp; white, something like this :</p>
<p><a href="http://spsneo.com/blog/wp-content/uploads/2008/07/screenshot13.png"><img class="alignnone size-medium wp-image-18" title="man pages (grayscale)" src="http://spsneo.com/blog/wp-content/uploads/2008/07/screenshot13-300x208.png" alt="grayscale man pages" width="300" height="208" /></a></p>
<p>If you use &#8216;most&#8217; utility to format man pages, you will get a properly colour-formatted man pages. Take a look at man pages configured on my system :</p>
<p><a href="http://spsneo.com/blog/wp-content/uploads/2008/07/screenshot21.png"><img class="alignnone size-medium wp-image-19" title="color man pages" src="http://spsneo.com/blog/wp-content/uploads/2008/07/screenshot21-300x208.png" alt="color man pages" width="300" height="208" /></a></p>
<p>Do you like this one ?? Read on how to configure &#8216;most&#8217; as your man pages viewer.</p>
<p>Step 1: Install the package &#8216;most&#8217;</p>
<p>$ sudo aptitude install most</p>
<p>Step 2: Configure &#8216;most&#8217; as your man page viewer using update-alternatives :</p>
<p><code>$ sudo update-alternatives --config pager</code></p>
<p><a href="http://spsneo.com/blog/wp-content/uploads/2008/07/screenshot3.png"><img class="alignnone size-medium wp-image-20" title="update-alternatives" src="http://spsneo.com/blog/wp-content/uploads/2008/07/screenshot3-300x207.png" alt="update-alternatives" width="300" height="207" /></a></p>
<p>Enter the number corresponding to /usr/bin/most , here in this screenshot its 5.</p>
<p>Yeah, its done. Nothing more to do !!</p>
<p>Have fun.</p>
<p>Let me know if you find any difficulty doing this.</p>
<p>P.S: This can be done in Fedora as well as other linux also. In Fedora I guess you will have to use the command  /usr/sbin/alternatives instead of update-alternatives as root. Somebody try out in Fedora and let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://spsneo.com/blog/2008/07/21/colourful-man-pages-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

