<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7259080474015777403</id><updated>2012-02-11T20:04:16.472-08:00</updated><category term='TweetDeck'/><category term='Unix'/><category term='GDM'/><category term='pgrep'/><category term='Cygwin'/><category term='C'/><category term='ps'/><category term='Toolbox'/><category term='awk'/><category term='encrypt'/><category term='popd'/><category term='Creative'/><category term='cut'/><category term='grep'/><category term='OpenSUSE'/><category term='Solaris'/><category term='top'/><category term='AMD'/><category term='background'/><category term='DDG'/><category term='Go'/><category term='CLI'/><category term='CSS'/><category term='Lllano'/><category term='gdb'/><category term='Find'/><category term='Epiphany'/><category term='W3'/><category term='FreeBSD'/><category term='Bobcat'/><category term='Gnome'/><category term='D'/><category term='pagers'/><category term='pushd'/><category term='Bulldozer'/><category term='Dillo'/><category term='Fusion'/><category term='Linux'/><category term='Sound'/><category term='zsh'/><category term='builtins'/><category term='history'/><category term='dirs'/><category term='X-FI'/><category term='gcc'/><category term='HP-UX'/><category term='Bash'/><category term='egrep'/><category term='AIX'/><category term='Login'/><title type='text'>printf("Totally out of ideas.\n");</title><subtitle type='html'>The rantings of a pseudo-code(r).</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>32</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-7404714352643523780</id><published>2011-05-03T17:31:00.000-07:00</published><updated>2011-05-03T17:34:23.518-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Login'/><category scheme='http://www.blogger.com/atom/ns#' term='GDM'/><category scheme='http://www.blogger.com/atom/ns#' term='Gnome'/><category scheme='http://www.blogger.com/atom/ns#' term='background'/><title type='text'>Change GDM login background image on OpenSUSE 11.4</title><content type='html'>First, let me start off by saying I truly dislike Gnome, and the attitude by the Gnome devs that somehow giving people options is a bad thing. &amp;nbsp;Why is it that I cannot easily change the background image of the Gnome login screen? &amp;nbsp;Why do I have to use hacks like &lt;a href="http://totally-out-of-ideas.blogspot.com/2010/11/how-to-change-gnome-login-background.html"&gt;this one&lt;/a&gt;? &amp;nbsp;Why do the hacks always have to change? &amp;nbsp;Anyway, for Gnome 2.32.1 which shipped with OpenSUSE 11.4 the way to change the login background image is like this:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;As root:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;mv &lt;span class="Apple-style-span" style="color: red;"&gt;your_new_image.jpg&lt;/span&gt; /usr/share/pixmaps/backgrounds/gnome/background-default.jpg&lt;br /&gt;&lt;br /&gt;Where&amp;nbsp;&lt;span class="Apple-style-span" style="color: red;"&gt;your_new_image.jpg&amp;nbsp;&lt;/span&gt; is the image you want to be the new background image.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-7404714352643523780?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/7404714352643523780/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2011/05/change-gdm-login-background-image-on.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/7404714352643523780'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/7404714352643523780'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2011/05/change-gdm-login-background-image-on.html' title='Change GDM login background image on OpenSUSE 11.4'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-8863460204666001464</id><published>2011-04-16T11:56:00.001-07:00</published><updated>2011-04-16T11:56:13.332-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cygwin'/><category scheme='http://www.blogger.com/atom/ns#' term='top'/><title type='text'>Cygwin top</title><content type='html'>If you want to use top in Cygwin, you will need to install the procps package. &amp;nbsp;I have spoken.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-8863460204666001464?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/8863460204666001464/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2011/04/cygwin-top.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/8863460204666001464'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/8863460204666001464'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2011/04/cygwin-top.html' title='Cygwin top'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-4157094429667546414</id><published>2011-04-15T19:25:00.000-07:00</published><updated>2011-04-15T19:25:52.574-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='CSS'/><category scheme='http://www.blogger.com/atom/ns#' term='W3'/><title type='text'>W3 CSS3 validation</title><content type='html'>I was fiddling around with some text-shadow stuff&amp;nbsp;(which is part of the CSS3 draft)&amp;nbsp;on the &lt;a href="http://www3.sympatico.ca/rsquared/gdb/index.html"&gt;gdb tutorial&lt;/a&gt;. &amp;nbsp;When I validated the CSS at&amp;nbsp;&lt;a href="http://www.w3.org/"&gt;W3C&lt;/a&gt;, I noticed that the validator, by default, chooses CSS level 2.1 instead of CSS level 3. &amp;nbsp;You can manually select CSS3 in the drop down menu &lt;a href="http://jigsaw.w3.org/css-validator/#validate_by_uri+with_options"&gt;here&lt;/a&gt;, but I want to be able to click on the link from each of my pages. &amp;nbsp;After all, the reason I have the valid HTML5 and CSS images on every page is to have a handy way to validate each one quickly and easily. &amp;nbsp;Anyway, the fix is pretty simple, which I found in &lt;a href="http://www.impressivewebs.com/css-opacity-reference/"&gt;this post&lt;/a&gt;. &amp;nbsp;Change the link for the CSS validator to this:&lt;br /&gt;&lt;br /&gt;http://jigsaw.w3.org/css-validator/check/referer&lt;span class="Apple-style-span" style="color: red;"&gt;?profile=css3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The part you need to add is in red.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-4157094429667546414?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/4157094429667546414/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2011/04/w3-css3-validation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/4157094429667546414'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/4157094429667546414'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2011/04/w3-css3-validation.html' title='W3 CSS3 validation'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-3600573315737289064</id><published>2011-02-05T16:06:00.000-08:00</published><updated>2011-02-05T16:06:56.495-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Gnome'/><category scheme='http://www.blogger.com/atom/ns#' term='TweetDeck'/><title type='text'>Getting TweetDeck (Adobe Air) to use your default browser in Gnome</title><content type='html'>This has been a bit of an issue in the past.  See &lt;a href="http://lifehacker.com/5382391/make-tweetdeck-and-other-air-apps-use-your-chosen-browser"&gt;this&lt;/a&gt; lifehacker article, which was inspired by &lt;a href="http://www.roytanck.com/2009/08/26/getting-adobe-air-to-use-the-default-browser-under-ubuntu/"&gt;Roy Tanck's blog post&lt;/a&gt;. &amp;nbsp;Currently, I am using Adobe Air 2.5.1 on OpenSUSE 11.3 - i386 (Yes, I have a crappy Atom powered&amp;nbsp;net book). &amp;nbsp;Every time I would open a link in TweetDeck, it would open in Firefox rather than Chromium. &amp;nbsp;To make matters worse, the place in Chromium where I could set it as the default browser, the button is grayed out, and it says "Chromium cannot determine or set the default browser." &amp;nbsp;Bummer. &amp;nbsp;But fear not, as the solution is somewhat simple. &amp;nbsp;If you have the "custom menu bar" (not the default one which ships with OpenSUSE) you can do System-&amp;gt;System-&amp;gt;Preferred Applications, and change the default browser there. &amp;nbsp;Alternatively, you could run "gnome-default-applications-properties" in your shell to get the dialogue box opened up. &amp;nbsp;Once I got it open, on the "Internet" tab, I dropped down the menu under "Web Browser" and selected "Custom". &amp;nbsp;Then I put in /usr/bin/Chromium. &amp;nbsp;You would obviously replace that command with the browser you want to use. &amp;nbsp;And that's it! &amp;nbsp;I didn't even have to restart TweetDeck. &amp;nbsp;It just worked from there on out.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-3600573315737289064?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/3600573315737289064/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2011/02/getting-tweetdeck-adobe-air-to-use-your.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/3600573315737289064'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/3600573315737289064'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2011/02/getting-tweetdeck-adobe-air-to-use-your.html' title='Getting TweetDeck (Adobe Air) to use your default browser in Gnome'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-7254422073694694695</id><published>2011-01-02T18:40:00.000-08:00</published><updated>2011-01-02T22:56:41.027-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Gnome'/><category scheme='http://www.blogger.com/atom/ns#' term='Epiphany'/><category scheme='http://www.blogger.com/atom/ns#' term='DDG'/><title type='text'>How to change Epiphany default search from Google to DuckDuckGo (Gnome)</title><content type='html'>I have been playing around with two new toys lately: &amp;nbsp;The &lt;a href="http://projects.gnome.org/epiphany/"&gt;Epiphany&lt;/a&gt; web browser, and &lt;a href="http://duckduckgo.com/"&gt;DuckDuckGo&lt;/a&gt; search. &amp;nbsp;I might write more on these another time, but for now I want to show you how you can change the default setting for search (in Epiphany) from Google to DuckDuckGo, by using gconf-editor in Gnome:&lt;br /&gt;&lt;br /&gt;Fire up a shell, and enter:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;gconf-editor&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A dialogue box will pop up. &amp;nbsp;Click on apps -&amp;gt; epiphany -&amp;gt; general&lt;br /&gt;&lt;br /&gt;You will see a list of things on the right. &amp;nbsp;Scroll down until you see 'url_search'. &amp;nbsp;Click that, then right click, and select 'edit key'. &amp;nbsp;In the new dialogue box that comes up, paste the following into the 'Value' field:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;http://duckduckgo.com/?q=%s&amp;amp;ie=UTF-8&amp;amp;oe=UTF-8&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Click, 'OK', and then close gconf-editor. &amp;nbsp;Now when you open up Epiphany and do a search, you should be looking at a result page from DDG, instead of Google.&lt;br /&gt;&lt;br /&gt;Happy DDG'ing!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-7254422073694694695?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/7254422073694694695/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2011/01/how-to-change-epiphany-default-search.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/7254422073694694695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/7254422073694694695'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2011/01/how-to-change-epiphany-default-search.html' title='How to change Epiphany default search from Google to DuckDuckGo (Gnome)'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-1218971276226656778</id><published>2011-01-02T06:09:00.000-08:00</published><updated>2011-01-02T06:19:11.380-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AMD'/><category scheme='http://www.blogger.com/atom/ns#' term='Fusion'/><title type='text'>Humorous AMD Video</title><content type='html'>With &lt;a href="http://www.cesweb.org/default.asp"&gt;CES&lt;/a&gt; looming, and &lt;a href="http://blogs.amd.com/press/2010/11/17/amd-fusion-apu-win-ces-innovations-2011-award/"&gt;news&lt;/a&gt; of AMD winning the&amp;nbsp;&lt;span class="Apple-style-span" style="line-height: 15px;"&gt;&lt;span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"&gt;International CES Innovations 2011 Design and Engineering Award for its &lt;a href="http://sites.amd.com/us/fusion/apu/Pages/fusion.aspx"&gt;Fusion APU&lt;/a&gt;, I have to say I am pretty excited to see Fusion finally coming to fruition. &amp;nbsp;Anyway, since Fusion is upon us, here is a funny new promotional video from AMD about fusion; watch for AMD President &amp;amp; CEO &lt;a href="http://www.amd.com/us/aboutamd/corporate-information/executives/Pages/dirk-meyer.aspx"&gt;Dirk Meyer&lt;/a&gt; at the end:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="line-height: 15px;"&gt;&lt;span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 15px;"&gt;&lt;object height="385" width="640"&gt;&lt;param name="movie" value="http://www.youtube.com/v/qUrXyDlfdXQ?fs=1&amp;amp;hl=en_US"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/qUrXyDlfdXQ?fs=1&amp;amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-1218971276226656778?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/1218971276226656778/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2011/01/humorous-amd-video.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/1218971276226656778'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/1218971276226656778'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2011/01/humorous-amd-video.html' title='Humorous AMD Video'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-768145537917200102</id><published>2010-12-21T21:33:00.000-08:00</published><updated>2010-12-26T22:03:41.119-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='gdb'/><title type='text'>GDB Tutorial</title><content type='html'>As far as GDB tutorials go, I think that Peter Salzman had one of the best. &amp;nbsp;Unfortunately, he let his site go down some time in 2008. &amp;nbsp;Now there is a site which has resurrected his old body of work - &lt;a href="http://www3.sympatico.ca/rsquared/gdb/"&gt;&lt;i&gt;Using The GNU GDB Debugger&lt;/i&gt;&lt;/a&gt;. &amp;nbsp;It is essentially the same as it was, with some bits reorganized. &amp;nbsp;It looks pretty good. &amp;nbsp;Check it out!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-768145537917200102?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/768145537917200102/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/12/gdb-tutorial.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/768145537917200102'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/768145537917200102'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/12/gdb-tutorial.html' title='GDB Tutorial'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-3108168845981767176</id><published>2010-12-18T15:02:00.000-08:00</published><updated>2010-12-18T15:06:34.286-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='FreeBSD'/><category scheme='http://www.blogger.com/atom/ns#' term='pgrep'/><category scheme='http://www.blogger.com/atom/ns#' term='AIX'/><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='Unix'/><category scheme='http://www.blogger.com/atom/ns#' term='HP-UX'/><category scheme='http://www.blogger.com/atom/ns#' term='Solaris'/><title type='text'>Comparison of four Unix pgrep utilities</title><content type='html'>Recently I was writing a script to kill programs by name; I admit this to my embarrassment, for although it was a nice learning experience in terms of shell programming skills, it was a complete reinventing of the wheel. &amp;nbsp;And not even a good wheel - more like a flat tire. &amp;nbsp;I can say this, because I am comparing my work to the standard Unix pgrep(1) utility. &amp;nbsp;At any rate, as I was studying the FreeBSD and Linux man pages for pgrep, I found it somewhat difficult to get the big picture regarding what options were available in both versions. &amp;nbsp;To the end of clarifying matters, I compiled a &lt;a href="http://www3.sympatico.ca/rsquared/pgrep/"&gt;table&lt;/a&gt; which compares all of the switches for the FreeBSD, Linux, Solaris 10, and HP-UX 11i versions of pgrep. &amp;nbsp;I added the HP-UX column at the request of a friend, who also asked for a column with the AIX options. &amp;nbsp;Unfortunately, I was not able to locate a man page for pgrep on the AIX system. &amp;nbsp;It seems to me that pgrep may not ship as a part of the standard AIX distribution. &amp;nbsp;It's too bad that I don't have access to an AIX machine, as I would implement a version on that system.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-3108168845981767176?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/3108168845981767176/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/12/comparison-of-four-unix-pgrep-utilities.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/3108168845981767176'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/3108168845981767176'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/12/comparison-of-four-unix-pgrep-utilities.html' title='Comparison of four Unix pgrep utilities'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-469030450509985501</id><published>2010-12-18T12:56:00.000-08:00</published><updated>2011-03-11T15:14:19.979-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Dillo'/><title type='text'>How to build Dillo on OpenSUSE 11.3</title><content type='html'>&lt;a href="http://www.dillo.org/"&gt;Dillo&lt;/a&gt; is a small, fast, and light browser. &amp;nbsp;In order to build it on OpenSUSE, you will need some pre-requisites. &amp;nbsp;This article will cover how to get the source code for Dillo (and associated libraries), as well as the software build tools you will use to compile the Dillo browser. &lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;First, open a terminal, and make yourself a work directory, and cd into it: (Note that the dollar sign '$' indicates a shell prompt, so you don't type that part in)&lt;br /&gt;&lt;br /&gt;&lt;code&gt; $ cd tmp&lt;br /&gt;$ mkdir build&lt;br /&gt;$ cd build&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Then the you will want to get the &lt;a href="http://www.dillo.org/download/"&gt;source&lt;/a&gt; for dillo. &amp;nbsp;You will also need to get the &lt;a href="http://www.fltk.org/software.php"&gt;source&lt;/a&gt; for FLTK2.&lt;br /&gt;&lt;br /&gt;Iin your terminal, do:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$ wget -c&amp;nbsp;http://www.dillo.org/download/dillo-2.2.tar.bz2&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You should now have a copy of dillo-2.2.tar.bz2&lt;br /&gt;&lt;br /&gt;Now do:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$&amp;nbsp;wget -c http://ftp.funet.fi/pub/mirrors/ftp.easysw.com/pub/fltk/snapshots/fltk-2.0.x-r7725.tar.bz2&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;When the download is completed, you will have the FLTK2 bzip file. &amp;nbsp;Unpack them:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$ tar -xvjf &amp;nbsp;dillo-2.2.tar.bz2&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;When that is finished, do:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;tar -xvjf fltk-2.0.x-r7725.tar.bz2&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;At this point you should have a directory for dillo, and one for FLTK2:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$ ls&lt;br /&gt;$ dillo-2.2 &amp;nbsp;dillo-2.2.tar.bz2&lt;br /&gt;fltk-2.0.x-r7725 &amp;nbsp;fltk-2.0.x-r7725.tar.bz2&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Change directory into the fltk-2.0 directory (We need to build that first)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$ cd&amp;nbsp;fltk-2.0.x-r7725/&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Before we do anything else, we need to install some tools, or you will never be able to build the source. &amp;nbsp;In the terminal, first change to root (su root) then&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$&amp;nbsp;zypper install gcc gcc-c++ autoconf automake make flex bison libjpeg-devel libpng14-devel zlib-devel Mesa Mesa-devel xorg-X11-devel&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;It will ask you if you want to install these things - it might recommend other things - just hit 'y' and enter.&lt;br /&gt;&lt;br /&gt;Once the tools are installed, you can hit ctrl-d to drop back down to your regular user account.  Now we are ready to build. &amp;nbsp;If you have more than one processor, the make utility can use them all. &amp;nbsp;Even if you have only a single core machine, you can still tell make to use "two" versions of itself. &amp;nbsp;For every core you have available, do a number one higher than that. &amp;nbsp;So for example with a dual core, do make -j3, on a quad core, do make -j5 and so on. &amp;nbsp;If you have a single core machine, do:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$ make -j2&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;If you have a fast quad core system, it should take less than a minute. &amp;nbsp;If you have a single core machine, it will take considerably longer.  Once the build is done (it should end with something like this - with no error messages&lt;br /&gt;&lt;br /&gt;&lt;code&gt;Linking timer...&lt;br /&gt;Linking utf...&lt;br /&gt;Linking fullscreen...&lt;br /&gt;Linking valuators...&lt;br /&gt;Linking list...&lt;br /&gt;Linking wizard...&lt;br /&gt;$&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Then su into root again, and type&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$ make install&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;If all goes well, you now have a working version of FLTK2. &amp;nbsp;Now we need to build dillo. &amp;nbsp;So, drop back into regular user status by hitting ctrl-d then:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$ cd ../dillo-2.2&lt;/code&gt;&lt;br /&gt;$ ./configure&lt;br /&gt;&lt;br /&gt;Once again, use the make -j2 (or whichever -j number you used before):&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$ make -j2&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;When it is done building (you get your prompt back, and there are no errors just before it), then su into root one more time, and do:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$ make install-strip&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;When it is done installing, hit ctrl-d to drop out of root, and you can run dillo by typing dillo in the terminal, and hitting enter. &amp;nbsp;That's it - you are done! &amp;nbsp;Enjoy the blazing fast speed of dillo!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-469030450509985501?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/469030450509985501/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/12/how-to-build-dillo-on-opensuse-113.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/469030450509985501'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/469030450509985501'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/12/how-to-build-dillo-on-opensuse-113.html' title='How to build Dillo on OpenSUSE 11.3'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-4772056758775420706</id><published>2010-11-28T08:59:00.000-08:00</published><updated>2011-05-03T17:35:49.640-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Login'/><category scheme='http://www.blogger.com/atom/ns#' term='GDM'/><category scheme='http://www.blogger.com/atom/ns#' term='Gnome'/><category scheme='http://www.blogger.com/atom/ns#' term='background'/><title type='text'>How to change Gnome login background image.</title><content type='html'>Update:  For OpenSUSE 11.4, see &lt;a href="http://totally-out-of-ideas.blogspot.com/2011/05/change-gdm-login-background-image-on.html"&gt;this post&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;As root&lt;/span&gt;, enter the following into your shell:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;gconftool-2 --direct \&lt;br /&gt;  --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \&lt;br /&gt;  --type string \&lt;br /&gt;  --set /desktop/gnome/background/picture_filename &lt;span class="Apple-style-span" style="color: red;"&gt;some_picture_filename.png&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Of course you will need to change the bit in red, "some_picture_filename.png" to the one that you want as your background image on the login screen.&lt;br /&gt;&lt;br /&gt;It seems that the method for doing this has been evolving. &amp;nbsp;What worked even six months ago does not appear to work now. &amp;nbsp;As of this writing, I am using Gnome 2.30.0 with OpenSUSE. &amp;nbsp;I found the information&amp;nbsp;&lt;a href="https://bbs.archlinux.org/viewtopic.php?id=94536"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-4772056758775420706?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/4772056758775420706/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/11/how-to-change-gnome-login-background.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/4772056758775420706'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/4772056758775420706'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/11/how-to-change-gnome-login-background.html' title='How to change Gnome login background image.'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-4716937444234153534</id><published>2010-11-06T06:48:00.000-07:00</published><updated>2010-11-06T06:48:14.534-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Lllano'/><category scheme='http://www.blogger.com/atom/ns#' term='AMD'/><category scheme='http://www.blogger.com/atom/ns#' term='Bulldozer'/><category scheme='http://www.blogger.com/atom/ns#' term='Bobcat'/><title type='text'>Excellent AMD Bulldozer Blog</title><content type='html'>Many of us have been patiently waiting for the release of the AMD Bulldozer processor.  As the date draws nearer, more details about the chip are starting&amp;nbsp;to emerge. Today I came across this interesting blog,&amp;nbsp;&lt;i&gt;&lt;a href="http://citavia.blog.de/"&gt;Patent based research regarding AMD's future MPUs&lt;/a&gt;&lt;/i&gt;.  The title gives a little idea of what the blog is about, but keep in mind that there is more there than patent research. Indeed, there is a lot of info there. &amp;nbsp;The author also comments on the AMD Llano and Bobcat processors. &amp;nbsp;Check it out for yourself!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-4716937444234153534?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/4716937444234153534/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/11/excellent-amd-bulldozer-blog.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/4716937444234153534'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/4716937444234153534'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/11/excellent-amd-bulldozer-blog.html' title='Excellent AMD Bulldozer Blog'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-1029872949272162165</id><published>2010-09-14T17:37:00.000-07:00</published><updated>2010-09-16T17:15:13.401-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='gcc'/><title type='text'>Misconceptions</title><content type='html'>Last night I was fiddling around with some really simple code; the object of my program was to test a positive integer, to see if it was odd or even, and then print the result. &amp;nbsp;There is more than one way to do this, some being more expensive than others. &amp;nbsp;I thought I would run some tests to see what sort of differences, with regard to program execution time, I could come up with. &amp;nbsp;I had three methods of checking for whether a number was odd or even.&lt;a name='more'&gt;&lt;/a&gt;&amp;nbsp;The first one uses the venerable modulus operator (%), as displayed below:&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;mod.c&lt;/b&gt;&lt;/blockquote&gt;&lt;pre class="hl"&gt;&lt;span class="hl ppc"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl ppc"&gt;#include &amp;lt;limits.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="hl kwb"&gt;int&lt;/span&gt; &lt;span class="hl kwd"&gt;main&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl kwb"&gt;void&lt;/span&gt;&lt;span class="hl opt"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwb"&gt;int&lt;/span&gt; i&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="hl kwa"&gt;for&lt;/span&gt; &lt;span class="hl opt"&gt;(&lt;/span&gt;i &lt;span class="hl opt"&gt;=&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; i &lt;span class="hl opt"&gt;&amp;lt;&lt;/span&gt; INT_MAX&lt;span class="hl opt"&gt;; ++&lt;/span&gt;i&lt;span class="hl opt"&gt;) {&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl kwa"&gt;if&lt;/span&gt; &lt;span class="hl opt"&gt;(&lt;/span&gt;i &lt;span class="hl opt"&gt;%&lt;/span&gt; &lt;span class="hl num"&gt;2&lt;/span&gt; &lt;span class="hl opt"&gt;==&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;) {&lt;/span&gt;&lt;br /&gt;            &lt;span class="hl kwd"&gt;printf&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl str"&gt;"%d is even.&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;"&lt;/span&gt;&lt;span class="hl opt"&gt;,&lt;/span&gt; i&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl opt"&gt;}&lt;/span&gt; &lt;span class="hl kwa"&gt;else&lt;/span&gt; &lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span class="hl kwd"&gt;printf&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl str"&gt;"%d is odd.&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;"&lt;/span&gt;&lt;span class="hl opt"&gt;,&lt;/span&gt; i&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   &lt;span class="hl kwa"&gt;return&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre class="hl"&gt;&lt;/pre&gt;Next, I tried a bit mask. &amp;nbsp;Basically, all it does is bitwise&amp;nbsp;&lt;i&gt;and&lt;/i&gt; (&amp;amp;) the first bit of the integer and 1:&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;bit.c&lt;/b&gt;&lt;/blockquote&gt;&lt;pre class="hl"&gt;&lt;span class="hl ppc"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl ppc"&gt;#include &amp;lt;limits.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="hl kwb"&gt;int&lt;/span&gt; &lt;span class="hl kwd"&gt;main&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl kwb"&gt;void&lt;/span&gt;&lt;span class="hl opt"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwc"&gt;register&lt;/span&gt; &lt;span class="hl kwb"&gt;int&lt;/span&gt; i&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="hl kwa"&gt;for&lt;/span&gt; &lt;span class="hl opt"&gt;(&lt;/span&gt;i &lt;span class="hl opt"&gt;=&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; i &lt;span class="hl opt"&gt;&amp;lt;&lt;/span&gt; INT_MAX&lt;span class="hl opt"&gt;; ++&lt;/span&gt;i&lt;span class="hl opt"&gt;) {&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl kwa"&gt;if&lt;/span&gt; &lt;span class="hl opt"&gt;(&lt;/span&gt;i &lt;span class="hl opt"&gt;&amp;amp;&lt;/span&gt; &lt;span class="hl num"&gt;1&lt;/span&gt;&lt;span class="hl opt"&gt;) {&lt;/span&gt;&lt;br /&gt;            &lt;span class="hl kwd"&gt;printf&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl str"&gt;"%d is even.&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;"&lt;/span&gt;&lt;span class="hl opt"&gt;,&lt;/span&gt; i&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl opt"&gt;}&lt;/span&gt; &lt;span class="hl kwa"&gt;else&lt;/span&gt; &lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span class="hl kwd"&gt;printf&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl str"&gt;"%d is odd.&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;"&lt;/span&gt;&lt;span class="hl opt"&gt;,&lt;/span&gt; i&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="hl kwa"&gt;return&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;span class="hl opt"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;Finally, I exploited the fact the integer division truncates any remainder of a number:&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;int.c&amp;nbsp;&lt;/b&gt;&lt;/blockquote&gt;&lt;pre class="hl"&gt;&lt;span class="hl ppc"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl ppc"&gt;#include &amp;lt;limits.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="hl kwb"&gt;int&lt;/span&gt; &lt;span class="hl kwd"&gt;main&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl kwb"&gt;void&lt;/span&gt;&lt;span class="hl opt"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwc"&gt;register&lt;/span&gt; &lt;span class="hl kwb"&gt;int&lt;/span&gt; i&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="hl kwa"&gt;for&lt;/span&gt; &lt;span class="hl opt"&gt;(&lt;/span&gt;i &lt;span class="hl opt"&gt;=&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; i &lt;span class="hl opt"&gt;&amp;lt;&lt;/span&gt; INT_MAX&lt;span class="hl opt"&gt;; ++&lt;/span&gt;i&lt;span class="hl opt"&gt;) {&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl kwa"&gt;if&lt;/span&gt; &lt;span class="hl opt"&gt;((&lt;/span&gt;i &lt;span class="hl opt"&gt;/&lt;/span&gt; &lt;span class="hl num"&gt;2&lt;/span&gt;&lt;span class="hl opt"&gt;) *&lt;/span&gt; &lt;span class="hl num"&gt;2&lt;/span&gt; &lt;span class="hl opt"&gt;==&lt;/span&gt; i&lt;span class="hl opt"&gt;) {&lt;/span&gt;&lt;br /&gt;            &lt;span class="hl kwd"&gt;printf&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl str"&gt;"%d is even.&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;"&lt;/span&gt;&lt;span class="hl opt"&gt;,&lt;/span&gt; i&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl opt"&gt;}&lt;/span&gt; &lt;span class="hl kwa"&gt;else&lt;/span&gt; &lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span class="hl kwd"&gt;printf&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl str"&gt;"%d is odd.&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;"&lt;/span&gt;&lt;span class="hl opt"&gt;,&lt;/span&gt; i&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="hl kwa"&gt;return&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;/pre&gt;I compiled each one with gcc -O2, and these were my times:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;time ./mod &amp;gt; /dev/null&lt;br /&gt;./mod &amp;gt; /dev/null  299.43s user 1.34s system 62% cpu 8:02.40 total&lt;br /&gt;&lt;br /&gt;time ./bit &amp;gt; /dev/null&lt;br /&gt;./bit &amp;gt; /dev/null  298.97s user 1.87s system 83% cpu 5:59.71 total&lt;br /&gt;&lt;br /&gt;time ./int &amp;gt; /dev/null&lt;br /&gt;./int &amp;gt; /dev/null  304.14s user 1.57s system 61% cpu 8:16.85 total&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;These times are not all that useful, as each program did not get the same amount of cpu. &amp;nbsp;Things got a little more interesting though when I recompiled with gcc -O3, and made sure the programs could each get pretty much all of the cpu for the entirety of their run times:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;time ./mod &amp;gt; /dev/null         &lt;br /&gt;./mod &amp;gt; /dev/null  296.04s user 1.00s system 99% cpu 4:58.53 total&lt;br /&gt;&lt;br /&gt;time ./int &amp;gt; /dev/null&lt;br /&gt;./int &amp;gt; /dev/null  297.81s user 1.04s system 99% cpu 5:00.46 total&lt;br /&gt;&lt;br /&gt;time ./bit &amp;gt; /dev/null         &lt;br /&gt;./bit &amp;gt; /dev/null  292.43s user 1.16s system 99% cpu 4:54.79 total&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Really not much difference in time at all between the three - they all took around five minutes.  Without looking at the assembly for each program, these results might seem a little surprising, especially for mod.c, and bit.c.  But look at the assembly for the two (and you won't be surprised about the execution time any longer):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;.file   "mod.c"&lt;br /&gt;        .section        .rodata.str1.1,"aMS",@progbits,1&lt;br /&gt;.LC0:&lt;br /&gt;        .string "%d is even.\n"&lt;br /&gt;.LC1:&lt;br /&gt;        .string "%d is odd.\n"&lt;br /&gt;        .text&lt;br /&gt;        .p2align 4,,15&lt;br /&gt;.globl main&lt;br /&gt;        .type   main, @function&lt;br /&gt;main:&lt;br /&gt;.LFB11:&lt;br /&gt;        .cfi_startproc&lt;br /&gt;        pushq   %rbx&lt;br /&gt;        .cfi_def_cfa_offset 16&lt;br /&gt;        xorl    %ebx, %ebx&lt;br /&gt;        .cfi_offset 3, -16&lt;br /&gt;        jmp     .L4&lt;br /&gt;        .p2align 4,,10&lt;br /&gt;        .p2align 3&lt;br /&gt;.L8:&lt;br /&gt;        movl    %ebx, %esi&lt;br /&gt;        xorl    %eax, %eax&lt;br /&gt;        movl    $.LC0, %edi&lt;br /&gt;        addl    $1, %ebx&lt;br /&gt;        call    printf&lt;br /&gt;        cmpl    $2147483647, %ebx&lt;br /&gt;        je      .L7&lt;br /&gt;.L4:&lt;br /&gt;        testb   $1, %bl&lt;br /&gt;        je      .L8&lt;br /&gt;        movl    %ebx, %esi&lt;br /&gt;        xorl    %eax, %eax&lt;br /&gt;        movl    $.LC1, %edi&lt;br /&gt;        addl    $1, %ebx&lt;br /&gt;        call    printf&lt;br /&gt;        cmpl    $2147483647, %ebx&lt;br /&gt;        jne     .L4&lt;br /&gt;.L7:&lt;br /&gt;        xorl    %eax, %eax&lt;br /&gt;        popq    %rbx&lt;br /&gt;        .cfi_def_cfa_offset 8&lt;br /&gt;        ret&lt;br /&gt;        .cfi_endproc&lt;br /&gt;.LFE11:&lt;br /&gt;        .size   main, .-main&lt;br /&gt;        .ident  "GCC: (SUSE Linux) 4.5.0 20100604 [gcc-4_5-branch revision 160292]"&lt;br /&gt;        .section        .comment.SUSE.OPTs,"MS",@progbits,1&lt;br /&gt;        .string "Ospwg"&lt;br /&gt;        .section        .note.GNU-stack,"",@progbits&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And bit.c:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;.file   "bit.c"&lt;br /&gt;        .section        .rodata.str1.1,"aMS",@progbits,1&lt;br /&gt;.LC0:&lt;br /&gt;        .string "%d is even.\n"&lt;br /&gt;.LC1:&lt;br /&gt;        .string "%d is odd.\n"&lt;br /&gt;        .text&lt;br /&gt;        .p2align 4,,15&lt;br /&gt;.globl main&lt;br /&gt;        .type   main, @function&lt;br /&gt;main:&lt;br /&gt;.LFB11:&lt;br /&gt;        .cfi_startproc&lt;br /&gt;        pushq   %rbx&lt;br /&gt;        .cfi_def_cfa_offset 16&lt;br /&gt;        xorl    %ebx, %ebx&lt;br /&gt;        .cfi_offset 3, -16&lt;br /&gt;        jmp     .L4&lt;br /&gt;        .p2align 4,,10&lt;br /&gt;        .p2align 3&lt;br /&gt;.L8:&lt;br /&gt;        movl    %ebx, %esi&lt;br /&gt;        xorl    %eax, %eax&lt;br /&gt;        movl    $.LC0, %edi&lt;br /&gt;        addl    $1, %ebx&lt;br /&gt;        call    printf&lt;br /&gt;        cmpl    $2147483647, %ebx&lt;br /&gt;        je      .L7&lt;br /&gt;.L4:&lt;br /&gt;        testb   $1, %bl&lt;br /&gt;        jne     .L8&lt;br /&gt;        movl    %ebx, %esi&lt;br /&gt;        xorl    %eax, %eax&lt;br /&gt;        movl    $.LC1, %edi&lt;br /&gt;        addl    $1, %ebx&lt;br /&gt;        call    printf&lt;br /&gt;        cmpl    $2147483647, %ebx&lt;br /&gt;        jne     .L4&lt;br /&gt;.L7:&lt;br /&gt;        xorl    %eax, %eax&lt;br /&gt;        popq    %rbx&lt;br /&gt;        .cfi_def_cfa_offset 8&lt;br /&gt;        ret&lt;br /&gt;        .cfi_endproc&lt;br /&gt;.LFE11:&lt;br /&gt;        .size   main, .-main&lt;br /&gt;        .ident  "GCC: (SUSE Linux) 4.5.0 20100604 [gcc-4_5-branch revision 160292]"&lt;br /&gt;        .section        .comment.SUSE.OPTs,"MS",@progbits,1&lt;br /&gt;        .string "Ospwg"&lt;br /&gt;        .section        .note.GNU-stack,"",@progbits&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;They are virtually identical; the compiler turned them into almost the same program!  In case you have trouble seeing where the differences lie, here is the diff for the two:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;diff mod.s bit.s&lt;br /&gt;1c1&lt;br /&gt;&amp;lt;       .file   "mod.c"&lt;br /&gt;---&lt;br /&gt;&amp;gt;       .file   "bit.c"&lt;br /&gt;31c31&lt;br /&gt;&amp;lt;       je      .L8&lt;br /&gt;---&lt;br /&gt;&amp;gt;       jne     .L8&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You don't get much closer than that.  I won't bother posting the assembly for int.c, (its just a couple more instructions) as the difference in run time is negligible.  With a good optimizing compiler, what you wrote might not even end up in the final output.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-1029872949272162165?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/1029872949272162165/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/09/misconceptions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/1029872949272162165'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/1029872949272162165'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/09/misconceptions.html' title='Misconceptions'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-4229522414839664561</id><published>2010-08-22T09:52:00.000-07:00</published><updated>2010-08-28T19:25:42.420-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='encrypt'/><title type='text'>encrypt(3) example usage</title><content type='html'>A while back I had someone ask about how to use the encrypt() function under Linux.  He had tried the man page, &lt;a href="http://www.kernel.org/doc/man-pages/online/pages/man3/encrypt.3.html"&gt;encrypt(3)&lt;/a&gt;, which even contains an example usage.  Unfortunately for him, the example given was terribly broken.  I managed to find a &lt;a href="http://groups.google.com/group/comp.os.linux.development.apps/msg/c669d8fa36b81e75"&gt;post&lt;/a&gt; by &lt;a href="http://users.physik.fu-berlin.de/~jtt/"&gt;Jens Thoms Törring&lt;/a&gt;&amp;nbsp;which contained a working sample (though there was an off-by-one error which Mr. Törring later brought to my attention). &amp;nbsp;Since the current man page at the time had a broken example, I thought I would send a &lt;a href="http://marc.info/?l=linux-man&amp;amp;m=124743823025364&amp;amp;w=2"&gt;patch&lt;/a&gt; in to have it fixed. &amp;nbsp;That was a little over a year ago, but guess what? &amp;nbsp;Still the same broken code! &amp;nbsp;I don't know why the patch was not applied. &amp;nbsp;Perhaps it was a crappy patch (I don't normally do patches, so I might have done it wrong). &amp;nbsp;Or maybe the maintainer of the man pages was too busy. &amp;nbsp;I don't really know what happened.  Since speculation is pretty much useless, I thought I might post the code here, for anyone else searching for a useful example of encrypt usage.&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;pre class="hl"&gt;&lt;span class="hl com"&gt;/* Modified from original source code&lt;/span&gt;&lt;br /&gt;&lt;span class="hl com"&gt; * written by Jens Thoms Toerring.  The original&lt;/span&gt;&lt;br /&gt;&lt;span class="hl com"&gt; * can be found on comp.os.linux.development.&lt;/span&gt;&lt;br /&gt;&lt;span class="hl com"&gt; */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="hl ppc"&gt;#define _XOPEN_SOURCE&lt;/span&gt;&lt;br /&gt;&lt;span class="hl ppc"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl ppc"&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl ppc"&gt;#include &amp;lt;crypt.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="hl com"&gt;/* You need to link with libcrypt (-lcrypt) &lt;/span&gt;&lt;br /&gt;&lt;span class="hl com"&gt; * to compile this example with glibc.&lt;/span&gt;&lt;br /&gt;&lt;span class="hl com"&gt; */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="hl kwb"&gt;int&lt;/span&gt; &lt;span class="hl kwd"&gt;main&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl kwb"&gt;void&lt;/span&gt;&lt;span class="hl opt"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwb"&gt;char&lt;/span&gt; key&lt;span class="hl opt"&gt;[&lt;/span&gt;&lt;span class="hl num"&gt;64&lt;/span&gt;&lt;span class="hl opt"&gt;];&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwb"&gt;char&lt;/span&gt; orig&lt;span class="hl opt"&gt;[&lt;/span&gt;&lt;span class="hl num"&gt;9&lt;/span&gt;&lt;span class="hl opt"&gt;] =&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;eggplant&amp;quot;&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwb"&gt;char&lt;/span&gt; buf&lt;span class="hl opt"&gt;[&lt;/span&gt;&lt;span class="hl num"&gt;64&lt;/span&gt;&lt;span class="hl opt"&gt;];&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwb"&gt;char&lt;/span&gt; txt&lt;span class="hl opt"&gt;[&lt;/span&gt;&lt;span class="hl num"&gt;9&lt;/span&gt;&lt;span class="hl opt"&gt;];&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwb"&gt;int&lt;/span&gt; i&lt;span class="hl opt"&gt;,&lt;/span&gt; j&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="hl kwa"&gt;for&lt;/span&gt; &lt;span class="hl opt"&gt;(&lt;/span&gt;i &lt;span class="hl opt"&gt;=&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; i &lt;span class="hl opt"&gt;&amp;lt;&lt;/span&gt; &lt;span class="hl num"&gt;64&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; i&lt;span class="hl opt"&gt;++) {&lt;/span&gt;&lt;br /&gt;        key&lt;span class="hl opt"&gt;[&lt;/span&gt;i&lt;span class="hl opt"&gt;] =&lt;/span&gt; &lt;span class="hl kwd"&gt;rand&lt;/span&gt;&lt;span class="hl opt"&gt;() &amp;amp;&lt;/span&gt; &lt;span class="hl num"&gt;1&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="hl kwa"&gt;for&lt;/span&gt; &lt;span class="hl opt"&gt;(&lt;/span&gt;i &lt;span class="hl opt"&gt;=&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; i &lt;span class="hl opt"&gt;&amp;lt;&lt;/span&gt; &lt;span class="hl num"&gt;8&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; i&lt;span class="hl opt"&gt;++) {&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl kwa"&gt;for&lt;/span&gt; &lt;span class="hl opt"&gt;(&lt;/span&gt;j &lt;span class="hl opt"&gt;=&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; j &lt;span class="hl opt"&gt;&amp;lt;&lt;/span&gt; &lt;span class="hl num"&gt;8&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; j&lt;span class="hl opt"&gt;++) {&lt;/span&gt;&lt;br /&gt;            buf&lt;span class="hl opt"&gt;[&lt;/span&gt;i &lt;span class="hl opt"&gt;*&lt;/span&gt; &lt;span class="hl num"&gt;8&lt;/span&gt; &lt;span class="hl opt"&gt;+&lt;/span&gt; j&lt;span class="hl opt"&gt;] =&lt;/span&gt; orig&lt;span class="hl opt"&gt;[&lt;/span&gt;i&lt;span class="hl opt"&gt;] &amp;gt;&amp;gt;&lt;/span&gt; j &lt;span class="hl opt"&gt;&amp;amp;&lt;/span&gt; &lt;span class="hl num"&gt;1&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl kwd"&gt;setkey&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;key&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwd"&gt;printf&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl str"&gt;&amp;quot;Before encrypting: %s&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;&amp;quot;&lt;/span&gt;&lt;span class="hl opt"&gt;,&lt;/span&gt; orig&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="hl kwd"&gt;encrypt&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;buf&lt;span class="hl opt"&gt;,&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwa"&gt;for&lt;/span&gt; &lt;span class="hl opt"&gt;(&lt;/span&gt;i &lt;span class="hl opt"&gt;=&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; i &lt;span class="hl opt"&gt;&amp;lt;&lt;/span&gt; &lt;span class="hl num"&gt;8&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; i&lt;span class="hl opt"&gt;++) {&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl kwa"&gt;for&lt;/span&gt; &lt;span class="hl opt"&gt;(&lt;/span&gt;j &lt;span class="hl opt"&gt;=&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;,&lt;/span&gt; txt&lt;span class="hl opt"&gt;[&lt;/span&gt;i&lt;span class="hl opt"&gt;] =&lt;/span&gt; &lt;span class="hl str"&gt;'\0'&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; j &lt;span class="hl opt"&gt;&amp;lt;&lt;/span&gt; &lt;span class="hl num"&gt;8&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; j&lt;span class="hl opt"&gt;++) {&lt;/span&gt;&lt;br /&gt;            txt&lt;span class="hl opt"&gt;[&lt;/span&gt;i&lt;span class="hl opt"&gt;] |=&lt;/span&gt; buf&lt;span class="hl opt"&gt;[&lt;/span&gt;i &lt;span class="hl opt"&gt;*&lt;/span&gt; &lt;span class="hl num"&gt;8&lt;/span&gt; &lt;span class="hl opt"&gt;+&lt;/span&gt; j&lt;span class="hl opt"&gt;] &amp;lt;&amp;lt;&lt;/span&gt; j&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;        txt&lt;span class="hl opt"&gt;[&lt;/span&gt;&lt;span class="hl num"&gt;8&lt;/span&gt;&lt;span class="hl opt"&gt;] =&lt;/span&gt; &lt;span class="hl str"&gt;'\0'&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwd"&gt;printf&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl str"&gt;&amp;quot;After encrypting:  %s&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;&amp;quot;&lt;/span&gt;&lt;span class="hl opt"&gt;,&lt;/span&gt; txt&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="hl kwd"&gt;encrypt&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;buf&lt;span class="hl opt"&gt;,&lt;/span&gt; &lt;span class="hl num"&gt;1&lt;/span&gt;&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwa"&gt;for&lt;/span&gt; &lt;span class="hl opt"&gt;(&lt;/span&gt;i &lt;span class="hl opt"&gt;=&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; i &lt;span class="hl opt"&gt;&amp;lt;&lt;/span&gt; &lt;span class="hl num"&gt;8&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; i&lt;span class="hl opt"&gt;++) {&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl kwa"&gt;for&lt;/span&gt; &lt;span class="hl opt"&gt;(&lt;/span&gt;j &lt;span class="hl opt"&gt;=&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;,&lt;/span&gt; txt&lt;span class="hl opt"&gt;[&lt;/span&gt;i&lt;span class="hl opt"&gt;] =&lt;/span&gt; &lt;span class="hl str"&gt;'\0'&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; j &lt;span class="hl opt"&gt;&amp;lt;&lt;/span&gt; &lt;span class="hl num"&gt;8&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt; j&lt;span class="hl opt"&gt;++) {&lt;/span&gt;&lt;br /&gt;            txt&lt;span class="hl opt"&gt;[&lt;/span&gt;i&lt;span class="hl opt"&gt;] |=&lt;/span&gt; buf&lt;span class="hl opt"&gt;[&lt;/span&gt;i &lt;span class="hl opt"&gt;*&lt;/span&gt; &lt;span class="hl num"&gt;8&lt;/span&gt; &lt;span class="hl opt"&gt;+&lt;/span&gt; j&lt;span class="hl opt"&gt;] &amp;lt;&amp;lt;&lt;/span&gt; j&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;        txt&lt;span class="hl opt"&gt;[&lt;/span&gt;&lt;span class="hl num"&gt;8&lt;/span&gt;&lt;span class="hl opt"&gt;] =&lt;/span&gt; &lt;span class="hl str"&gt;'\0'&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwd"&gt;printf&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl str"&gt;&amp;quot;After decrypting:  %s&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;&amp;quot;&lt;/span&gt;&lt;span class="hl opt"&gt;,&lt;/span&gt; txt&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="hl kwa"&gt;return&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-4229522414839664561?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/4229522414839664561/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/08/encrypt3-example-usage.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/4229522414839664561'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/4229522414839664561'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/08/encrypt3-example-usage.html' title='encrypt(3) example usage'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-5538484370568333044</id><published>2010-08-21T15:41:00.000-07:00</published><updated>2011-08-18T16:44:45.427-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='D'/><title type='text'>The easy way out</title><content type='html'>I was just reading an &lt;a href="http://drdobbs.com/high-performance-computing/217801225"&gt;article&lt;/a&gt; by &lt;a href="http://erdani.com/"&gt;Andrei Alexandrescu&lt;/a&gt; called, &lt;i&gt;The Case for D&lt;/i&gt;. &amp;nbsp;In it he compares the traditional C "hello world" program to its D counterpart.  Consider the following example:&lt;br /&gt;&lt;pre class="hl"&gt;&lt;span class="hl ppc"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="hl kwd"&gt;main&lt;/span&gt;&lt;span class="hl opt"&gt;()&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwd"&gt;printf&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl str"&gt;"Hello, world&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;"&lt;/span&gt;&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;If I compile this with gcc -o hello hello.c, I get an executable (without any warnings from the compiler). &amp;nbsp;It runs, and the return value is 13. &amp;nbsp;Wha-what? &amp;nbsp;Return value? &amp;nbsp;I didn't return anything. &amp;nbsp;But printf() did.&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;pre&gt;~/stuff&amp;gt; ./hello&lt;br /&gt;Hello, world&lt;br /&gt;~/stuff&amp;gt; echo $?&lt;br /&gt;13&lt;br /&gt;&lt;/pre&gt;See? &amp;nbsp;The thirteen happens to be the return value of printf() - 13 characters in "Hello, world\n" got printed out to the console. &amp;nbsp;This sticks around for the shell echo, because status did not get returned back to the OS, via a return statement. &amp;nbsp;The above program is not exactly conforming C - not to C89, and not to C99. &amp;nbsp;In C89, main may be declared as above, but must have an explicit return statement. &amp;nbsp;Under C99, main must be declared as one of the following:&lt;br /&gt;&lt;pre class="hl"&gt;&lt;span class="hl kwb"&gt;int&lt;/span&gt; &lt;span class="hl kwd"&gt;main&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl kwb"&gt;void&lt;/span&gt;&lt;span class="hl opt"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="hl kwb"&gt;int&lt;/span&gt; &lt;span class="hl kwd"&gt;main&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl kwb"&gt;int&lt;/span&gt; argc&lt;span class="hl opt"&gt;,&lt;/span&gt; &lt;span class="hl kwb"&gt;char&lt;/span&gt; &lt;span class="hl opt"&gt;*&lt;/span&gt;argv&lt;span class="hl opt"&gt;[])&lt;/span&gt; &lt;span class="hl com"&gt;/* int main(int argc, char **argv)&lt;/span&gt;&lt;br /&gt;&lt;span class="hl com"&gt;                             * is also acceptable&lt;/span&gt;&lt;br /&gt;&lt;span class="hl com"&gt;                             */&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;Additionally, under C89, an explicit return at the end of main is required. &amp;nbsp;In C99, it is not, and if not provided, a return value of zero is implied.&lt;br /&gt;&lt;br /&gt;Andrei Alexandrescu argues that this all creates incorrect behaviour. &amp;nbsp;If we do the classic hello world program, such as the first example&lt;sup&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;1&lt;/span&gt;&lt;/sup&gt;, then a weird value gets returned from main. That is not really desirable at all. &amp;nbsp;If we add a return (under C89), or if one is implied (C99), we get rid of the weird values being sent back to the OS.  This appears to fix the problem.  Or does it?&lt;br /&gt;&lt;br /&gt;What happens if printf() fails? &amp;nbsp;It returns a negative value. &amp;nbsp;Do we let printf() happily fail, and then return 0 (which means success on most systems)? &amp;nbsp;That does not make sense either. &amp;nbsp;His suggestion was an altered "hello world" program:&lt;br /&gt;&lt;pre class="hl"&gt;&lt;span class="hl ppc"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="hl kwb"&gt;int&lt;/span&gt; &lt;span class="hl kwd"&gt;main&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl kwb"&gt;void&lt;/span&gt;&lt;span class="hl opt"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwa"&gt;return&lt;/span&gt; &lt;span class="hl kwd"&gt;printf&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl str"&gt;"Hello, world!&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;"&lt;/span&gt;&lt;span class="hl opt"&gt;) &amp;lt;&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This might even make an experienced C programmer do a double take. &amp;nbsp;For those who may not get what it is doing, basically the return value of printf() is evaluated and compared to 0. &amp;nbsp;If it is less than 0 (meaning printf() failed, and returned a negative value), then the expression is &lt;i&gt;true&lt;/i&gt; (remember that in C, the result of any expression evaluating to true is non-zero). &amp;nbsp; Because it is true, non-zero then gets returned from main. &amp;nbsp;If the return from printf() is not less than zero (meaning it succeeded, and returned the number of characters printed), then the expression is false. &amp;nbsp;All expressions evaluating as false are 0. &amp;nbsp;So if printf() is successful, the expression evaluates as false, and the result of the expression is 0, which gets returned from main. &amp;nbsp;In short, if the call to printf() fails, the proper value (i.e., not 0) is returned, indicating some sort of failure to the OS. &amp;nbsp;If the call to printf() succeeds, the integer 0, indicating all is well, is returned.&amp;nbsp;This is, in my opinion, a truly elegant bit of code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;At any rate, the point of this one part of his article is not to talk about how to fix C, but that using D is the preferred option, because, &amp;nbsp;it does things more correctly. &amp;nbsp;According to Alexandrescu, &lt;br /&gt;&lt;blockquote&gt;"D attempts not only to allow you to do the right thing, it systematically attempts to make the right thing synonymous to the path of least resistance whenever possible. And it turns out they can be synonymous more often than one might think."&lt;/blockquote&gt;&lt;br /&gt;From what I can glean from the article, I find myself having to agree.  I mean, the "right thing" for C is to check those return values. &amp;nbsp;But this is not _at all_ the path of least resistance. &amp;nbsp;His modified example is for the simplest bit of code. &amp;nbsp;A less refined approach might look something like this:&lt;br /&gt;&lt;pre class="hl"&gt;&lt;span class="hl ppc"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl ppc"&gt;#include &amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl ppc"&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="hl kwb"&gt;int&lt;/span&gt; &lt;span class="hl kwd"&gt;main&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl kwb"&gt;void&lt;/span&gt;&lt;span class="hl opt"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwb"&gt;char&lt;/span&gt; message&lt;span class="hl opt"&gt;[] =&lt;/span&gt; &lt;span class="hl str"&gt;"Hello, world&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;"&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwb"&gt;size_t&lt;/span&gt; message_len&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    message_len &lt;span class="hl opt"&gt;=&lt;/span&gt; &lt;span class="hl kwd"&gt;strlen&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;message&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl kwa"&gt;if&lt;/span&gt; &lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl kwd"&gt;printf&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl str"&gt;"%s"&lt;/span&gt;&lt;span class="hl opt"&gt;,&lt;/span&gt; message&lt;span class="hl opt"&gt;) != (&lt;/span&gt;&lt;span class="hl kwb"&gt;int&lt;/span&gt;&lt;span class="hl opt"&gt;)&lt;/span&gt; message_len&lt;span class="hl opt"&gt;) {&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl kwd"&gt;fprintf&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;stderr&lt;span class="hl opt"&gt;,&lt;/span&gt; &lt;span class="hl str"&gt;"%s&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;"&lt;/span&gt;&lt;span class="hl opt"&gt;,&lt;/span&gt; &lt;span class="hl str"&gt;"Call to printf() failed!"&lt;/span&gt;&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;        &lt;span class="hl kwd"&gt;exit&lt;/span&gt;&lt;span class="hl opt"&gt;(&lt;/span&gt;EXIT_FAILURE&lt;span class="hl opt"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="hl kwa"&gt;return&lt;/span&gt; &lt;span class="hl num"&gt;0&lt;/span&gt;&lt;span class="hl opt"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see it gets real ugly - real fast.  Furthermore, while it might deal with one problem, it also causes another: If we are to check the return values of all functions, then we must also deal with the call to fprintf() (I will leave that as an exercise to the reader). All of this for one of the most simple programs you can do! &amp;nbsp;The point is that while we don't have to go to these lengths for a simple "hello world" program (recall the elegant example by&amp;nbsp;Alexandrescu), we do have to address these issues in production code.  In truth, it often seems easier to ignore some things than to deal with them.  But this &lt;i&gt;will&lt;/i&gt; come back to bite you like a rabid dog.  Wouldn't it be nice if some of this stuff was covered by the language so that you, the programmer, could get on with writing good code?  I think that D just might be headed in that direction.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;1.&lt;/span&gt;&amp;nbsp;I believe the example given is straight out of &lt;a href="http://en.wikipedia.org/wiki/The_C_Programming_Language_(book)"&gt;K&amp;amp;R&lt;/a&gt;, albeit from the initial introductory/tutorial material of the text.  Returning a value from main is explained in more detail further on in the book.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-5538484370568333044?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/5538484370568333044/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/08/easy-way-out.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/5538484370568333044'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/5538484370568333044'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/08/easy-way-out.html' title='The easy way out'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-3265045443695206116</id><published>2010-08-21T14:03:00.001-07:00</published><updated>2010-12-04T19:03:40.169-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='D'/><category scheme='http://www.blogger.com/atom/ns#' term='Go'/><title type='text'>Google Go, or Digital Mars D?</title><content type='html'>&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Recently I learned of the&amp;nbsp;&lt;a href="http://golang.org/"&gt;Go&lt;/a&gt;&amp;nbsp;programming language. &amp;nbsp;It is, according to the header on the main golang web page, an expressive, concurrent, garbage-collected, systems programming language. It looks kind of cool. &amp;nbsp;There is a compiler (&lt;a href="http://golang.org/doc/go_faq.html#What_kind_of_a_name_is_6g"&gt;6g&lt;/a&gt;) which works on my system. &amp;nbsp;I would prefer to use the gcc &amp;nbsp;front-end&amp;nbsp;(&lt;a href="http://gcc.gnu.org/ml/gcc/2009-11/msg00297.html"&gt;gccgo&lt;/a&gt;), but at this point I cannot get it running.&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Then there is the&amp;nbsp;&lt;a href="http://www.digitalmars.com/d/"&gt;D&lt;/a&gt;&amp;nbsp;programming language. &amp;nbsp;It is, according to the D main page, also a systems programming language. &amp;nbsp;It looks appealing as well. &amp;nbsp;D comes with its own compiler,&amp;nbsp;&lt;a href="http://www.digitalmars.com/d/2.0/dmd-linux.html"&gt;dmd&lt;/a&gt;, and a front end for gcc (&lt;a href="http://bitbucket.org/goshawk/gdc/wiki/Home"&gt;gdc&lt;/a&gt;).&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Apparently, it kind of seems that these two languages have some overlap in their audience/goals. &amp;nbsp;&lt;a href="http://www.digitalmars.com/d/archives/digitalmars/D/Go_A_new_system_programing_language_100547.html#N100551"&gt;This thread&lt;/a&gt;&amp;nbsp;has some discussion about that from a primarily pro D perspective. &amp;nbsp;&lt;a href="http://groups.google.com/group/golang-nuts/browse_thread/thread/f24e7d46091e27ab/66af4f56569ee2a8?lnk=raot&amp;amp;pli=1"&gt;This&lt;/a&gt;&amp;nbsp;is another thread, but more from a pro Go perspective.&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;My&amp;nbsp;dilemma&amp;nbsp;is that I want to learn a new language. &amp;nbsp;I am a hobby&amp;nbsp;programmer, with a pretty good handle on C. &amp;nbsp;I have made stabs at C++ before, and while I think it is a wonderful language (string handling and memory management are so much easier than C) it is also a lot more to learn than C. &amp;nbsp;I am wondering if D or Go might be more suitable. &amp;nbsp;Ultimately, I might have to dive into both to make my decision. &amp;nbsp;I am hoping not to have to do that though. &amp;nbsp;One thing that will help make my decision is the documentation available. &amp;nbsp;I cannot learn a new language without some help. &amp;nbsp;So I will have to look into that aspect as well. &amp;nbsp;If you are a Go programmer, or a D programmer, (or both) and you feel like offering any suggestions as to what path I should take, please leave a comment. &amp;nbsp;I would appreciate any sound advice.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-3265045443695206116?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/3265045443695206116/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/08/google-go-or-digital-mars-d.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/3265045443695206116'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/3265045443695206116'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/08/google-go-or-digital-mars-d.html' title='Google Go, or Digital Mars D?'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-6788944131232086190</id><published>2010-05-01T10:20:00.000-07:00</published><updated>2010-06-18T15:51:26.104-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Gnome'/><title type='text'>More on changing the Gnome clock</title><content type='html'>In my previous &lt;a href="http://totally-out-of-ideas.blogspot.com/2010/01/changing-gnome-panel-clock-from-24hr.html"&gt;post&lt;/a&gt; about the Gnome clock, I showed you how to  change the clock from the default 24 hour time display to a 12 hour format.  In this post, I will show how you can change things to display seconds as well.  Here is my default display string in gconf-editor:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;%a %b %d, %l:%M %p&lt;/pre&gt;&lt;br /&gt;From reading the &lt;i&gt;date&lt;/i&gt; manpage, you know that this will display the Year, month, day, hours and minutes.  Something like this:  Sat May 01, 5:16.  But what about seconds?  If you want that, just add the appropriate specifier (%S) to the date string:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;%a %b %d, %l:%M&lt;span class="Apple-style-span" style="color: red;"&gt;:%S&lt;/span&gt; %p&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;Note:&lt;/span&gt;&lt;/b&gt;&amp;nbsp;You will also need to check the 'show_seconds' box roughly 11 places below the date string setting in gconf-editor. If you forget this part, the seconds portion will display, but the numbers will not actually change until the minutes portion changes because the clock isn't being updated every second.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-6788944131232086190?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/6788944131232086190/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/05/more-on-changing-gnome-clock.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/6788944131232086190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/6788944131232086190'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/05/more-on-changing-gnome-clock.html' title='More on changing the Gnome clock'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-4060591793331958272</id><published>2010-04-24T11:13:00.000-07:00</published><updated>2010-04-24T11:14:28.418-07:00</updated><title type='text'>What I have been doing.</title><content type='html'>For the past few minutes, anyway...&lt;br /&gt;&lt;br /&gt;&lt;code&gt;(a+b)^7&lt;br /&gt;= (a+b)(a+b)(a+b)(a+b)(a+b)(a+b)(a+b)&lt;br /&gt;= (a^2 + ab + ab + b^2)(a+b)(a+b)(a+b)(a+b)(a+b)&lt;br /&gt;= a(a^2 + ab + ab + b^2) + b(a^2 + ab + ab + b^2)(a+b)(a+b)(a+b)(a+b)&lt;br /&gt;= a^3 + a^2b + a^2b + ab^2 + a^2b + ab^2 + ab^2 + b^3 (a+b)(a+b)(a+b)(a+b)&lt;br /&gt;= (a^3 + 3a^2b + 3ab^2 + b^3)(a+b)(a+b)(a+b)(a+b)&lt;br /&gt;= a(a^3 + 3a^2b + 3ab^2 + b^3) + b(a^3 + 3a^2b + 3ab^2 + b^3)(a+b)(a+b)(a+b)&lt;br /&gt;= (a^4 + 3a^3b + 3a^2b^2 + ab^3 + a^3b + 3a^2b^2 + 3ab^3 + b^4)(a+b)(a+b)(a+b)&lt;br /&gt;= (a^4 + 4a^3b + 6a^2b^2 + 4ab^3 + b^4)(a+b)(a+b)(a+b)&lt;br /&gt;= a(a^4 + 4a^3b + 6a^2b^2 + 4ab^3 + b^4) + b(a^4 + 4a^3b + 6a^2b^2 + 4ab^3 + b^4)(a+b)(a+b)&lt;br /&gt;= (a^5 + 4a^4b + 6a^3b^2 + 4a^2b^3 + ab^4 + a^4b + 4a^3^b2 + 6a^2b^3 + 4ab^4 + b^5)(a+b)(a+b)&lt;br /&gt;= (a^5 + 5a^4b + 10a^3b^2 + 10a^2b^3 + 5ab^4 + b^5)(a+b)(a+b)&lt;br /&gt;= a(a^5 + 5a^4b + 10a^3b^2 + 10a^2b^3 + 5ab^4 + b^5) + b(a^5 + 5a^4b + 10a^3b^2 + 10a^2b^3 + 5ab^4 + b^5)(a+b)&lt;br /&gt;= (a^6 + 5a^5b + 10a^4b^2 +10a^3b^3 + 5a^2b^4 + ab^5 + a^5b + 5a^4b^2 + 10a^3b^3 + 10a^2b^4 + 5ab^5 + b^6)(a+b)&lt;br /&gt;= (a^6 + 6a^5b + 15a^4b^2 + 20a^3b^3 + 15a^2b^4 + 6ab^5 + b^6)(a+b)&lt;br /&gt;= a(a^6 + 6a^5b + 15a^4b^2 + 20a^3b^3 + 15a^2b^4 + 6ab^5 + b^6) + b(a^6 + 6a^5b + 15a^4b^2 + 20a^3b^3 + 15a^2b^4 + 6ab^5 + b^6)&lt;br /&gt;= a^7 + 6a^6b + 15a^5b^2 + 20a^4b^3 + 15a^3b^4 + 6a^2b^5 + a^6b + a^6b^2 + 6a^5b^2 + 15a^4b^3 + 20a^3b^4 + 15a^2b^5 + 6ab^6 + b^7&lt;br /&gt;= a^7 + 7a^6b + 21a^5b^2 + 35a^4b^3 + 35a^3b^4 + 21a^2b^5 + 7ab^6 + b^7&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-4060591793331958272?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/4060591793331958272/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/04/what-i-have-been-doing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/4060591793331958272'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/4060591793331958272'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/04/what-i-have-been-doing.html' title='What I have been doing.'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-129800688965018053</id><published>2010-02-06T16:23:00.000-08:00</published><updated>2010-02-07T06:36:52.615-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='X-FI'/><category scheme='http://www.blogger.com/atom/ns#' term='OpenSUSE'/><category scheme='http://www.blogger.com/atom/ns#' term='Sound'/><category scheme='http://www.blogger.com/atom/ns#' term='Creative'/><title type='text'>OpenSUSE 11.2:  My best Linux experience by far.</title><content type='html'>Over the years I have been through a few different Linux distributions. &amp;nbsp;I ran Mandrake (hey, I was really a n00b) for a bit. &amp;nbsp;Then I caught the Gentoo bug (no, I was not a ricer, but I did really like their helpful forums and wiki pages) and did that for quite a few years. &amp;nbsp;Then something went wrong with my system, and I lost the drive. &amp;nbsp;I didn't have time to fiddle with restoring everything, so I slapped Fedora 11 on it. &amp;nbsp;It was the Fedora install that got me thinking that I kind of enjoyed it when everything seemed to work, right out of the box. &amp;nbsp;  In fact, I was so pleased with the way it all worked so well, that I installed it on both of my computers. &amp;nbsp;I liked the fact that I didn't have to spend hours trying to make things work. &amp;nbsp;Someone once said, &lt;i&gt;"Linux is only free if your time is worth nothing."&lt;/i&gt;&lt;a name='more'&gt;&lt;/a&gt;&amp;nbsp;Stated by someone embittered against Linux, to be sure, but there is a grain of truth there. &amp;nbsp;I want to do my work -- NOT fight with getting things working. &amp;nbsp;Fedora was showing me that this could happen.&amp;nbsp;&amp;nbsp; &amp;nbsp;But there were a few things I was not happy with, so I started thinking about a different distro. &amp;nbsp;I decided to try OpenSUSE, and boy am I ever glad I did. &amp;nbsp;Say what you will about Novell &lt;a href="http://boycottnovell.com/wiki/index.php/Main_Page"&gt;being in bed with Microsoft&lt;/a&gt;, but they have put together one heck of a distribution. &amp;nbsp;Hence, the reason for this post.&lt;br /&gt;&lt;br /&gt;I recently bought a new box store computer. &amp;nbsp;Nothing fancy, but a better processor that the old one that just kacked on me. &amp;nbsp;I put OpenSUSE 11.2 on it, and &lt;i&gt;everything&lt;/i&gt;&amp;nbsp;worked correctly. &amp;nbsp;Just turn it on, and it works. &amp;nbsp;Now I also got Windows 7 with the new machine. &amp;nbsp;When I went to install&amp;nbsp;Dragon Naturally Speaking, I was informed&amp;nbsp;that the onboard sound on my machine was not suitable. &amp;nbsp;No problem, as I have an old Creative SoundBlaster X-FI card to put in it. &amp;nbsp;(Of course this card has history with Linux, and none of it good. &amp;nbsp;More about that later). &amp;nbsp;I installed it today and, after a bit of prodding, Windows 7 found the right drivers and installed them. &amp;nbsp; Presto - sound card working nicely. &amp;nbsp;Now I mention this because when I was playing around with the beta and RC versions of Win 7, I was very impressed with the facilities for finding and installing drivers. &amp;nbsp;Microsoft has done well with this. &amp;nbsp;&lt;i&gt;Because of my previous experience&lt;/i&gt;, I was little surprised that the driver installation was not a little smoother today. &amp;nbsp;So much for Windows, but what about Linux? &lt;br /&gt;&lt;br /&gt;To be honest, I was hopeful my experience would be better this time than previous attempts. &amp;nbsp;Creative has not been kind to the Linux community with its X-FI cards. &amp;nbsp;They have offered zero support for the longest time. &amp;nbsp;Apparently they have changed their ways a little, and now there is reasonable support for that line of cards. &amp;nbsp;While OpenSUSE was booting up, I was thinking I would probably have to fire up YAST, and do something to get the card installed, but before I did that, I figured I might as well see if there was any sound. &amp;nbsp;I fired up GnR, and I was completely blown away. &amp;nbsp;The sound worked. &amp;nbsp;Immediately. &amp;nbsp;Without any intervention by me. &amp;nbsp;Even Windows 7 (which I am by no means bashing here) did not do this. &lt;br /&gt;&lt;br /&gt;To any and all OpenSUSE people who happen to read this: &amp;nbsp;Thank you. &amp;nbsp;Thank you for making my Linux Experience so pleasant. &amp;nbsp;I am long tired of fighting with things that should just work. &amp;nbsp;You have made the Linux that I have been waiting for a reality.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-129800688965018053?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/129800688965018053/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/02/opensuse-112-my-best-linux-experience.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/129800688965018053'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/129800688965018053'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/02/opensuse-112-my-best-linux-experience.html' title='OpenSUSE 11.2:  My best Linux experience by far.'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-5748026171891764430</id><published>2010-01-28T09:23:00.000-08:00</published><updated>2010-01-28T09:27:39.968-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Gnome'/><title type='text'>Changing Gnome panel clock from 24hr time to 12hr time on OpenSUSE 11.2</title><content type='html'>Fire up your shell, and type in gconf-editor. &amp;nbsp;Then, on the left, select Apps --&amp;gt; panel --&amp;gt; applets --&amp;gt; applet0 --&amp;gt; prefs (This was slightly different for me between two different machines. &amp;nbsp;It might be ...applets --&amp;gt; clock_screen0 --&amp;gt; prefs.) &amp;nbsp;First you want to right click on 'format' on the right side of the gconf-editor, and select 'Edit Key'. &amp;nbsp;In the dialogue box that comes up, enter 'custom' (without the quotes). &amp;nbsp;Then click ok. &amp;nbsp;Next, you will need to enter 'custom_format' (about 6 entries above 'format'). &amp;nbsp;Again, right click and select 'Edit Key'. &amp;nbsp;Here you will enter &amp;lt;b&amp;gt;%a %b %d, %l:M %p&amp;lt;/b&amp;gt; and click ok. &amp;nbsp;This will get you a format such as Thu Jan 28, 12:20. &amp;nbsp;If you prefer a different format, look at some of the options available in the date man page.&lt;br /&gt;&lt;br /&gt;Read more &lt;a href="http://www.bomahy.nl/hylke/blog/pretty-gnome-clock/"&gt;here&lt;/a&gt;. &amp;nbsp;(Don't forget to look at the comments section at the bottom as well).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-5748026171891764430?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/5748026171891764430/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/01/changing-gnome-panel-clock-from-24hr.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/5748026171891764430'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/5748026171891764430'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/01/changing-gnome-panel-clock-from-24hr.html' title='Changing Gnome panel clock from 24hr time to 12hr time on OpenSUSE 11.2'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-1404371025347189534</id><published>2010-01-18T12:28:00.000-08:00</published><updated>2010-06-18T15:05:49.329-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='zsh'/><category scheme='http://www.blogger.com/atom/ns#' term='Toolbox'/><category scheme='http://www.blogger.com/atom/ns#' term='history'/><category scheme='http://www.blogger.com/atom/ns#' term='CLI'/><category scheme='http://www.blogger.com/atom/ns#' term='Bash'/><title type='text'>Shell shortcuts part deux.</title><content type='html'>In my &lt;a href="http://totally-out-of-ideas.blogspot.com/2010/01/shell-shortcuts.html"&gt;last post&lt;/a&gt;, I demonstrated how you can use the !! and !$ features of your Bash &amp;amp; zsh history to get your work done more quickly. &amp;nbsp; I use the former all the time, but &amp;nbsp;the latter? &amp;nbsp;Well, not so much. &amp;nbsp;This is because I use something even better for &lt;i&gt;interactive &lt;/i&gt;shell use. &amp;nbsp;It is M-. &amp;nbsp;That is Meta plus period. &amp;nbsp;All you Emacs &lt;s&gt;zealots&lt;/s&gt; users will know what I mean by &lt;i&gt;Meta&lt;/i&gt;. &amp;nbsp;:) &amp;nbsp;The &lt;i&gt;Meta-key &lt;/i&gt;is Alt on your computer, or sometimes Esc. &amp;nbsp;Both work on my machine, but I prefer Alt over Esc, because it is less work.&lt;br /&gt;&lt;br /&gt;Try doing M-. in your shell (Press and hold the Alt key, and then press the period key). &amp;nbsp;Like !$, M-. will give you the last part of the last command entered, but this time &lt;i&gt;you can see it immediately. &amp;nbsp;&lt;/i&gt;Better still, you can cycle through all of your commands. &amp;nbsp;Just keep hitting M-. and the shell will display the last part of each command, in order, from newest to oldest. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;Note: &amp;nbsp;&lt;/span&gt;&lt;/b&gt;&amp;nbsp;If you use the ESC key for your 'Meta' key, then you need to release the ESC key each time. &amp;nbsp;Otherwise, if you hold it down and tap the . (period) key, it will return the end of the last command only once, and then start echoing the period after it.&lt;br /&gt;&lt;br /&gt;As an example, say you had just finished a&lt;br /&gt;&lt;br /&gt;&lt;code&gt;grep fred /etc/passwd&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You are ready to use the command line history feature:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;vi M-.&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Which would expand to (immediately):&lt;br /&gt;&lt;br /&gt;&lt;code&gt;vi /etc/passwd&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Then, if it looks right, just press Enter.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-1404371025347189534?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/1404371025347189534/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/01/shell-shortcuts-part-deux.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/1404371025347189534'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/1404371025347189534'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/01/shell-shortcuts-part-deux.html' title='Shell shortcuts part deux.'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-4382456844494869388</id><published>2010-01-16T13:22:00.000-08:00</published><updated>2010-01-16T13:22:00.304-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='zsh'/><category scheme='http://www.blogger.com/atom/ns#' term='history'/><category scheme='http://www.blogger.com/atom/ns#' term='CLI'/><category scheme='http://www.blogger.com/atom/ns#' term='Bash'/><title type='text'>Shell shortcuts</title><content type='html'>In Bash and zsh, you can access the command history by using several shortcuts. &amp;nbsp;For example, by typing !![Enter], the previous command will be executed. &amp;nbsp;If you are not sure of what the previous command was, you could do !!:p[Enter] and the previous command will be displayed, but not executed. &amp;nbsp;Now, if you like what you see, you can do !![Enter], and the shell will execute that command.&lt;br /&gt;&lt;br /&gt;Another ! shortcut is !$. &amp;nbsp; This will give you the &lt;i&gt;end&lt;/i&gt; of the previous command. &amp;nbsp;So if my previous command was:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;grep fred /etc/passwd&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;doing !$ would give me &lt;i&gt;/etc/passwd&lt;/i&gt;. &amp;nbsp;This can be handy. &amp;nbsp;Say for example the user fred exists on the system, and grep returns his record from /etc/passwd. &amp;nbsp;If there is something I see in one of the fields that I wish to change, all I need to do (provided that grep was the last command I did) is:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;vi !$&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This will expand to&lt;br /&gt;&lt;br /&gt;&lt;code&gt;vi /etc/passwd&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;If you are not sure how !$ will expand for you (ie., you cannot remember for certain what your last command was exactly), you can use the :p option:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;vi !$:p&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-4382456844494869388?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/4382456844494869388/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/01/shell-shortcuts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/4382456844494869388'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/4382456844494869388'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/01/shell-shortcuts.html' title='Shell shortcuts'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-5889477599755639873</id><published>2010-01-15T12:51:00.000-08:00</published><updated>2010-01-15T12:51:00.162-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Toolbox'/><category scheme='http://www.blogger.com/atom/ns#' term='pagers'/><title type='text'>Pagers</title><content type='html'>I won't give you a history of documentation viewers (aka &lt;i&gt;pagers&lt;/i&gt;) on *nix systems, other than to say that there used to be pg and more. Then along came &lt;a href="http://www.greenwoodsoftware.com/less/"&gt;less&lt;/a&gt;, which was a lot like more, but way better. &amp;nbsp;Apparently there is a play on words there, so maybe it is true that &lt;i&gt;less is more.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Anyway, I have long followed the advice to use the less pager where it is available. &amp;nbsp;I don't follow that advice strictly any more. &amp;nbsp;I now use &lt;a href="http://www.jedsoft.org/most/"&gt;most&lt;/a&gt;.  From the most home page:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;"MOST is a powerful paging program for Unix, VMS, MSDOS, and win32 systems. Unlike other well-known paging programs&amp;nbsp;&lt;a href="http://www.jedsoft.org/most/"&gt;most&lt;/a&gt;&amp;nbsp;supports multiple windows and can scroll left and right. Why settle for less?"&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Indeed.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-5889477599755639873?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/5889477599755639873/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/01/pagers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/5889477599755639873'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/5889477599755639873'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/01/pagers.html' title='Pagers'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-7835731178509054112</id><published>2010-01-14T16:31:00.000-08:00</published><updated>2010-01-14T17:23:36.891-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Toolbox'/><category scheme='http://www.blogger.com/atom/ns#' term='Bash'/><title type='text'>Making your Bash scripts look a little better</title><content type='html'>One thing I have noticed about this blog is that shell scripts are _very_ difficult to make look nice. &amp;nbsp;I am not sure if that is a Blogger problem, or an issue with this template. &amp;nbsp;Either way, I don't like mucking around with the way things look. &amp;nbsp;I want to get my ideas down and not have to be constantly tweaking the text formatting. &lt;br /&gt;&lt;br /&gt;Anyway, after monkeying around for a while with the shell script on the &lt;a href="http://totally-out-of-ideas.blogspot.com/2010/01/optimizing-your-shell-scripts.html"&gt;previous post&lt;/a&gt;, I decided to search for a script beautifier, along the lines of &lt;a href="http://www.gnu.org/software/indent/"&gt;GNU indent&lt;/a&gt;, but for shell scripts. &amp;nbsp;Eventually, I came across a ruby script, written by&amp;nbsp;&lt;a href="http://www.arachnoid.com/"&gt;Paul Lutus&lt;/a&gt;, and aptly named&amp;nbsp;&lt;i&gt;Bash Script Beautifier&lt;/i&gt;. &amp;nbsp;So far, it has worked very well for me. &lt;br /&gt;&lt;br /&gt;As always, utilities such as this one may not work exactly the way you want. &amp;nbsp;You would do well to make a backup copy of your script before you run it through the beautifier. &amp;nbsp;Also, be sure to read the documentation on the download page. &amp;nbsp;You can read all about it, and download the script&amp;nbsp;&lt;a href="http://www.arachnoid.com/linux/beautify_bash/index.html"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-7835731178509054112?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/7835731178509054112/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/01/making-your-bash-scripts-look-little.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/7835731178509054112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/7835731178509054112'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/01/making-your-bash-scripts-look-little.html' title='Making your Bash scripts look a little better'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-6298064760608411029</id><published>2010-01-12T14:56:00.000-08:00</published><updated>2010-08-28T19:56:12.191-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='awk'/><category scheme='http://www.blogger.com/atom/ns#' term='cut'/><category scheme='http://www.blogger.com/atom/ns#' term='CLI'/><category scheme='http://www.blogger.com/atom/ns#' term='builtins'/><title type='text'>Optimizing your shell scripts</title><content type='html'>A few days ago I came across a couple of posts, by &lt;a href="http://bashcurescancer.com/"&gt;Brock Noland&lt;/a&gt;, about splitting strings natively with the shell. &amp;nbsp;You can find them &lt;a href="http://bashcurescancer.com/splitting-strings-natively-with-the-shell-why.html"&gt;here&lt;/a&gt; and &lt;a href="http://bashcurescancer.com/splitting-strings-natively-with-the-shell-native-vs-native.html"&gt;here&lt;/a&gt;. &amp;nbsp;Basically, the writer demonstrated that using shell builtins and variables is much more desirable than using outside programs, such as cut and awk for the same purpose. &amp;nbsp;The reason for this is due to speed. &amp;nbsp;Every time you make a call to an outside program with the shell, you fork a new process, and that takes time.&lt;br /&gt;&lt;br /&gt;I decided to tinker with this idea a bit more, to get a better impression of how much slower using cut and awk really is.  I made each of the following functions iterate 100 times. &amp;nbsp;I am pretty sure some of you will be shocked by the speed difference between cut and awk, versus the shell native string splitting.&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;Here is my code, followed by the execution results:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;&lt;b&gt;&lt;span class="Apple-style-span"&gt;Note:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;The following code is virtually identical to what is found on the pages I linked to above. &amp;nbsp;The first two functions I modified to iterate more times, the third and fourth are essentially unchanged, and the final two are changed from the two&amp;nbsp;preceding, albeit slightly, to gain a small performance increase.&lt;br /&gt;&lt;pre class="hl"&gt;&lt;span class="hl slc"&gt;#!/bin/bash                                  &lt;/span&gt;&lt;br /&gt;f_cut&lt;span class="hl opt"&gt;() {&lt;/span&gt;&lt;br /&gt;   &lt;span class="hl kwa"&gt;for&lt;/span&gt; i &lt;span class="hl kwa"&gt;in&lt;/span&gt; &lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;span class="hl num"&gt;0&lt;/span&gt;.&lt;span class="hl num"&gt;.99&lt;/span&gt;&lt;span class="hl opt"&gt;};&lt;/span&gt; &lt;span class="hl kwa"&gt;do&lt;/span&gt;&lt;br /&gt;      &lt;span class="hl kwa"&gt;while&lt;/span&gt; &lt;span class="hl kwb"&gt;read&lt;/span&gt; line&lt;span class="hl opt"&gt;;&lt;/span&gt; &lt;span class="hl kwa"&gt;do&lt;/span&gt;&lt;br /&gt;         uid&lt;span class="hl opt"&gt;=&lt;/span&gt;$&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;$line&amp;quot;&lt;/span&gt; | cut &lt;span class="hl opt"&gt;-&lt;/span&gt;d&lt;span class="hl opt"&gt;: -&lt;/span&gt;f3&lt;span class="hl opt"&gt;)&lt;/span&gt;&lt;br /&gt;         &lt;span class="hl kwa"&gt;if&lt;/span&gt; &lt;span class="hl opt"&gt;[[&lt;/span&gt; &lt;span class="hl kwc"&gt;$uid&lt;/span&gt; &lt;span class="hl opt"&gt;-&lt;/span&gt;gt &lt;span class="hl num"&gt;10&lt;/span&gt; &lt;span class="hl opt"&gt;]];&lt;/span&gt; &lt;span class="hl kwa"&gt;then&lt;/span&gt;         &lt;br /&gt;            shell&lt;span class="hl opt"&gt;=&lt;/span&gt;$&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;$line&amp;quot;&lt;/span&gt; | cut &lt;span class="hl opt"&gt;-&lt;/span&gt;d&lt;span class="hl opt"&gt;: -&lt;/span&gt;f7&lt;span class="hl opt"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span class="hl kwa"&gt;if&lt;/span&gt; &lt;span class="hl opt"&gt;[[&lt;/span&gt; &lt;span class="hl str"&gt;'/sbin/nologin'&lt;/span&gt; &lt;span class="hl opt"&gt;==&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;$shell&amp;quot;&lt;/span&gt; &lt;span class="hl opt"&gt;]];&lt;/span&gt; &lt;span class="hl kwa"&gt;then&lt;/span&gt;&lt;br /&gt;               &lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;$line&amp;quot;&lt;/span&gt; | cut &lt;span class="hl opt"&gt;-&lt;/span&gt;d&lt;span class="hl opt"&gt;: -&lt;/span&gt;f1           &lt;br /&gt;            &lt;span class="hl kwa"&gt;fi&lt;/span&gt;                                        &lt;br /&gt;         &lt;span class="hl kwa"&gt;fi&lt;/span&gt;                                           &lt;br /&gt;      &lt;span class="hl kwa"&gt;done&lt;/span&gt; &lt;span class="hl opt"&gt;&amp;lt;/&lt;/span&gt;etc&lt;span class="hl opt"&gt;/&lt;/span&gt;passwd                            &lt;br /&gt;   &lt;span class="hl kwa"&gt;done&lt;/span&gt;                                               &lt;br /&gt;&lt;span class="hl opt"&gt;}&lt;/span&gt;                                                     &lt;br /&gt;&lt;br /&gt;f_awk&lt;span class="hl opt"&gt;() {&lt;/span&gt;&lt;br /&gt;   &lt;span class="hl kwa"&gt;for&lt;/span&gt; i &lt;span class="hl kwa"&gt;in&lt;/span&gt; &lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;span class="hl num"&gt;0&lt;/span&gt;.&lt;span class="hl num"&gt;.99&lt;/span&gt;&lt;span class="hl opt"&gt;};&lt;/span&gt; &lt;span class="hl kwa"&gt;do&lt;/span&gt;&lt;br /&gt;      &lt;span class="hl kwa"&gt;while&lt;/span&gt; &lt;span class="hl kwb"&gt;read&lt;/span&gt; line&lt;span class="hl opt"&gt;;&lt;/span&gt; &lt;span class="hl kwa"&gt;do&lt;/span&gt;&lt;br /&gt;         uid&lt;span class="hl opt"&gt;=&lt;/span&gt;$&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;$line&amp;quot;&lt;/span&gt; | &lt;span class="hl kwc"&gt;awk&lt;/span&gt; &lt;span class="hl opt"&gt;-&lt;/span&gt;F&lt;span class="hl opt"&gt;:&lt;/span&gt; &lt;span class="hl str"&gt;'{print $3}'&lt;/span&gt;&lt;span class="hl opt"&gt;)&lt;/span&gt;&lt;br /&gt;         &lt;span class="hl kwa"&gt;if&lt;/span&gt; &lt;span class="hl opt"&gt;[[&lt;/span&gt; &lt;span class="hl kwc"&gt;$uid&lt;/span&gt; &lt;span class="hl opt"&gt;-&lt;/span&gt;gt &lt;span class="hl num"&gt;10&lt;/span&gt; &lt;span class="hl opt"&gt;]];&lt;/span&gt; &lt;span class="hl kwa"&gt;then&lt;/span&gt;                  &lt;br /&gt;            shell&lt;span class="hl opt"&gt;=&lt;/span&gt;$&lt;span class="hl opt"&gt;(&lt;/span&gt;&lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;$line&amp;quot;&lt;/span&gt; | &lt;span class="hl kwc"&gt;awk&lt;/span&gt; &lt;span class="hl opt"&gt;-&lt;/span&gt;F&lt;span class="hl opt"&gt;:&lt;/span&gt; &lt;span class="hl str"&gt;'{print $7}'&lt;/span&gt;&lt;span class="hl opt"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span class="hl kwa"&gt;if&lt;/span&gt; &lt;span class="hl opt"&gt;[[&lt;/span&gt; &lt;span class="hl str"&gt;'/sbin/nologin'&lt;/span&gt; &lt;span class="hl opt"&gt;==&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;$shell&amp;quot;&lt;/span&gt; &lt;span class="hl opt"&gt;]];&lt;/span&gt; &lt;span class="hl kwa"&gt;then&lt;/span&gt;    &lt;br /&gt;               &lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;$line&amp;quot;&lt;/span&gt; | &lt;span class="hl kwc"&gt;awk&lt;/span&gt; &lt;span class="hl opt"&gt;-&lt;/span&gt;F&lt;span class="hl opt"&gt;:&lt;/span&gt; &lt;span class="hl str"&gt;'{print $1}'&lt;/span&gt;      &lt;br /&gt;            &lt;span class="hl kwa"&gt;fi&lt;/span&gt;                                            &lt;br /&gt;         &lt;span class="hl kwa"&gt;fi&lt;/span&gt;                                               &lt;br /&gt;      &lt;span class="hl kwa"&gt;done&lt;/span&gt; &lt;span class="hl opt"&gt;&amp;lt;/&lt;/span&gt;etc&lt;span class="hl opt"&gt;/&lt;/span&gt;passwd                                &lt;br /&gt;   &lt;span class="hl kwa"&gt;done&lt;/span&gt;                                                   &lt;br /&gt;&lt;span class="hl opt"&gt;}&lt;/span&gt;                                                         &lt;br /&gt;&lt;br /&gt;shell_1&lt;span class="hl opt"&gt;() {&lt;/span&gt;&lt;br /&gt;   &lt;span class="hl kwa"&gt;for&lt;/span&gt; i &lt;span class="hl kwa"&gt;in&lt;/span&gt; &lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;span class="hl num"&gt;0&lt;/span&gt;.&lt;span class="hl num"&gt;.99&lt;/span&gt;&lt;span class="hl opt"&gt;};&lt;/span&gt; &lt;span class="hl kwa"&gt;do&lt;/span&gt;&lt;br /&gt;      &lt;span class="hl kwa"&gt;while&lt;/span&gt; &lt;span class="hl kwb"&gt;read&lt;/span&gt; line&lt;span class="hl opt"&gt;;&lt;/span&gt; &lt;span class="hl kwa"&gt;do&lt;/span&gt;&lt;br /&gt;         oldifs&lt;span class="hl opt"&gt;=&lt;/span&gt;&lt;span class="hl str"&gt;&amp;quot;$IFS&amp;quot;&lt;/span&gt;   &lt;br /&gt;         IFS&lt;span class="hl opt"&gt;=:&lt;/span&gt;           &lt;br /&gt;         &lt;span class="hl kwb"&gt;set&lt;/span&gt; &lt;span class="hl opt"&gt;--&lt;/span&gt; &lt;span class="hl kwc"&gt;$line&lt;/span&gt;    &lt;br /&gt;         IFS&lt;span class="hl opt"&gt;=&lt;/span&gt;&lt;span class="hl str"&gt;&amp;quot;$oldifs&amp;quot;&lt;/span&gt;   &lt;br /&gt;         &lt;span class="hl kwa"&gt;if&lt;/span&gt; &lt;span class="hl opt"&gt;[[&lt;/span&gt; &lt;span class="hl kwc"&gt;$3&lt;/span&gt; &lt;span class="hl opt"&gt;-&lt;/span&gt;gt &lt;span class="hl num"&gt;10&lt;/span&gt; &lt;span class="hl opt"&gt;]] &amp;amp;&amp;amp; [[&lt;/span&gt; &lt;span class="hl str"&gt;'/sbin/nologin'&lt;/span&gt; &lt;span class="hl opt"&gt;==&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;$7&amp;quot;&lt;/span&gt; &lt;span class="hl opt"&gt;]];&lt;/span&gt; &lt;span class="hl kwa"&gt;then&lt;/span&gt;&lt;br /&gt;            &lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;$1&amp;quot;&lt;/span&gt;                                           &lt;br /&gt;         &lt;span class="hl kwa"&gt;fi&lt;/span&gt;                                                       &lt;br /&gt;      &lt;span class="hl kwa"&gt;done&lt;/span&gt; &lt;span class="hl opt"&gt;&amp;lt;/&lt;/span&gt;etc&lt;span class="hl opt"&gt;/&lt;/span&gt;passwd                                        &lt;br /&gt;   &lt;span class="hl kwa"&gt;done&lt;/span&gt;                                                           &lt;br /&gt;&lt;span class="hl opt"&gt;}&lt;/span&gt;                                                                 &lt;br /&gt;&lt;br /&gt;shell_2&lt;span class="hl opt"&gt;() {&lt;/span&gt;&lt;br /&gt;   &lt;span class="hl kwa"&gt;for&lt;/span&gt; i &lt;span class="hl kwa"&gt;in&lt;/span&gt; &lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;span class="hl num"&gt;0&lt;/span&gt;.&lt;span class="hl num"&gt;.99&lt;/span&gt;&lt;span class="hl opt"&gt;};&lt;/span&gt; &lt;span class="hl kwa"&gt;do&lt;/span&gt;&lt;br /&gt;      &lt;span class="hl kwa"&gt;while&lt;/span&gt; IFS&lt;span class="hl opt"&gt;=:&lt;/span&gt; &lt;span class="hl kwb"&gt;read&lt;/span&gt; username pp uid gid gecos hd shell&lt;span class="hl opt"&gt;;&lt;/span&gt; &lt;span class="hl kwa"&gt;do&lt;/span&gt;&lt;br /&gt;         &lt;span class="hl kwa"&gt;if&lt;/span&gt; &lt;span class="hl opt"&gt;[[&lt;/span&gt; &lt;span class="hl kwc"&gt;$uid&lt;/span&gt; &lt;span class="hl opt"&gt;-&lt;/span&gt;gt &lt;span class="hl num"&gt;10&lt;/span&gt; &lt;span class="hl opt"&gt;]] &amp;amp;&amp;amp; [[&lt;/span&gt; &lt;span class="hl str"&gt;'/sbin/nologin'&lt;/span&gt; &lt;span class="hl opt"&gt;==&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;$shell&amp;quot;&lt;/span&gt; &lt;span class="hl opt"&gt;]];&lt;/span&gt; &lt;span class="hl kwa"&gt;then&lt;/span&gt;&lt;br /&gt;            &lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;$username&amp;quot;&lt;/span&gt;                                          &lt;br /&gt;         &lt;span class="hl kwa"&gt;fi&lt;/span&gt;                                                             &lt;br /&gt;      &lt;span class="hl kwa"&gt;done&lt;/span&gt; &lt;span class="hl opt"&gt;&amp;lt;/&lt;/span&gt;etc&lt;span class="hl opt"&gt;/&lt;/span&gt;passwd                                              &lt;br /&gt;   &lt;span class="hl kwa"&gt;done&lt;/span&gt;                                                                 &lt;br /&gt;&lt;span class="hl opt"&gt;}&lt;/span&gt;                                                                       &lt;br /&gt;&lt;br /&gt;shell_3&lt;span class="hl opt"&gt;() {&lt;/span&gt;&lt;br /&gt;   oldifs&lt;span class="hl opt"&gt;=&lt;/span&gt;&lt;span class="hl str"&gt;&amp;quot;$IFS&amp;quot;&lt;/span&gt;&lt;br /&gt;   IFS&lt;span class="hl opt"&gt;=:&lt;/span&gt;      &lt;br /&gt;   &lt;span class="hl kwa"&gt;for&lt;/span&gt; i &lt;span class="hl kwa"&gt;in&lt;/span&gt; &lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;span class="hl num"&gt;0&lt;/span&gt;.&lt;span class="hl num"&gt;.99&lt;/span&gt;&lt;span class="hl opt"&gt;};&lt;/span&gt; &lt;span class="hl kwa"&gt;do&lt;/span&gt;&lt;br /&gt;      &lt;span class="hl kwa"&gt;while&lt;/span&gt; &lt;span class="hl kwb"&gt;read&lt;/span&gt; line&lt;span class="hl opt"&gt;;&lt;/span&gt; &lt;span class="hl kwa"&gt;do&lt;/span&gt;&lt;br /&gt;         &lt;span class="hl kwb"&gt;set&lt;/span&gt; &lt;span class="hl opt"&gt;--&lt;/span&gt; &lt;span class="hl kwc"&gt;$line&lt;/span&gt;    &lt;br /&gt;         &lt;span class="hl kwa"&gt;if&lt;/span&gt; &lt;span class="hl opt"&gt;[[&lt;/span&gt; &lt;span class="hl kwc"&gt;$3&lt;/span&gt; &lt;span class="hl opt"&gt;-&lt;/span&gt;gt &lt;span class="hl num"&gt;10&lt;/span&gt; &lt;span class="hl opt"&gt;]] &amp;amp;&amp;amp; [[&lt;/span&gt; &lt;span class="hl str"&gt;'/sbin/nologin'&lt;/span&gt; &lt;span class="hl opt"&gt;==&lt;/span&gt; &lt;span class="hl kwc"&gt;$7&lt;/span&gt; &lt;span class="hl opt"&gt;]];&lt;/span&gt; &lt;span class="hl kwa"&gt;then&lt;/span&gt;&lt;br /&gt;            &lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;$1&amp;quot;&lt;/span&gt;                                         &lt;br /&gt;         &lt;span class="hl kwa"&gt;fi&lt;/span&gt;                                                     &lt;br /&gt;      &lt;span class="hl kwa"&gt;done&lt;/span&gt; &lt;span class="hl opt"&gt;&amp;lt;/&lt;/span&gt;etc&lt;span class="hl opt"&gt;/&lt;/span&gt;passwd                                      &lt;br /&gt;   &lt;span class="hl kwa"&gt;done&lt;/span&gt;                                                         &lt;br /&gt;   IFS&lt;span class="hl opt"&gt;=&lt;/span&gt;&lt;span class="hl str"&gt;&amp;quot;$oldifs&amp;quot;&lt;/span&gt;                                                &lt;br /&gt;&lt;span class="hl opt"&gt;}&lt;/span&gt;                                                               &lt;br /&gt;&lt;br /&gt;shell_4&lt;span class="hl opt"&gt;() {&lt;/span&gt;&lt;br /&gt;   oldifs&lt;span class="hl opt"&gt;=&lt;/span&gt;&lt;span class="hl str"&gt;&amp;quot;$IFS&amp;quot;&lt;/span&gt;&lt;br /&gt;   IFS&lt;span class="hl opt"&gt;=:&lt;/span&gt;&lt;br /&gt;   &lt;span class="hl kwa"&gt;for&lt;/span&gt; i &lt;span class="hl kwa"&gt;in&lt;/span&gt; &lt;span class="hl opt"&gt;{&lt;/span&gt;&lt;span class="hl num"&gt;0&lt;/span&gt;.&lt;span class="hl num"&gt;.99&lt;/span&gt;&lt;span class="hl opt"&gt;};&lt;/span&gt; &lt;span class="hl kwa"&gt;do&lt;/span&gt;&lt;br /&gt;      &lt;span class="hl kwa"&gt;while&lt;/span&gt; &lt;span class="hl kwb"&gt;read&lt;/span&gt; username pp uid gid gecos hd shell&lt;span class="hl opt"&gt;;&lt;/span&gt; &lt;span class="hl kwa"&gt;do&lt;/span&gt;&lt;br /&gt;         &lt;span class="hl kwa"&gt;if&lt;/span&gt; &lt;span class="hl opt"&gt;[[&lt;/span&gt; &lt;span class="hl kwc"&gt;$uid&lt;/span&gt; &lt;span class="hl opt"&gt;-&lt;/span&gt;gt &lt;span class="hl num"&gt;10&lt;/span&gt; &lt;span class="hl opt"&gt;]] &amp;amp;&amp;amp; [[&lt;/span&gt; &lt;span class="hl str"&gt;'/sbin/nologin'&lt;/span&gt; &lt;span class="hl opt"&gt;==&lt;/span&gt; &lt;span class="hl kwc"&gt;$shell&lt;/span&gt; &lt;span class="hl opt"&gt;]];&lt;/span&gt; &lt;span class="hl kwa"&gt;then&lt;/span&gt;&lt;br /&gt;            &lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;$username&amp;quot;&lt;/span&gt;&lt;br /&gt;         &lt;span class="hl kwa"&gt;fi&lt;/span&gt;&lt;br /&gt;      &lt;span class="hl kwa"&gt;done&lt;/span&gt; &lt;span class="hl opt"&gt;&amp;lt;/&lt;/span&gt;etc&lt;span class="hl opt"&gt;/&lt;/span&gt;passwd&lt;br /&gt;   &lt;span class="hl kwa"&gt;done&lt;/span&gt;&lt;br /&gt;   IFS&lt;span class="hl opt"&gt;=&lt;/span&gt;&lt;span class="hl str"&gt;&amp;quot;$oldifs&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl opt"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;%s&amp;quot;&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;---Cut---&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl kwa"&gt;time&lt;/span&gt; f_cut &lt;span class="hl opt"&gt;&amp;gt;/&lt;/span&gt;dev&lt;span class="hl opt"&gt;/&lt;/span&gt;null&lt;br /&gt;&lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;%s&amp;quot;&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;---Awk---&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl kwa"&gt;time&lt;/span&gt; f_awk &lt;span class="hl opt"&gt;&amp;gt;/&lt;/span&gt;dev&lt;span class="hl opt"&gt;/&lt;/span&gt;null&lt;br /&gt;&lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;%s&amp;quot;&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;---Shell 1---&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl kwa"&gt;time&lt;/span&gt; shell_1 &lt;span class="hl opt"&gt;&amp;gt;/&lt;/span&gt;dev&lt;span class="hl opt"&gt;/&lt;/span&gt;null&lt;br /&gt;&lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;%s&amp;quot;&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;---Shell 2---&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl kwa"&gt;time&lt;/span&gt; shell_2 &lt;span class="hl opt"&gt;&amp;gt;/&lt;/span&gt;dev&lt;span class="hl opt"&gt;/&lt;/span&gt;null&lt;br /&gt;&lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;%s&amp;quot;&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;---Shell 3---&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl kwa"&gt;time&lt;/span&gt; shell_3 &lt;span class="hl opt"&gt;&amp;gt;/&lt;/span&gt;dev&lt;span class="hl opt"&gt;/&lt;/span&gt;null&lt;br /&gt;&lt;span class="hl kwb"&gt;printf&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;&lt;/span&gt;&lt;span class="hl esc"&gt;\n&lt;/span&gt;&lt;span class="hl str"&gt;%s&amp;quot;&lt;/span&gt; &lt;span class="hl str"&gt;&amp;quot;---Shell 4---&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl kwa"&gt;time&lt;/span&gt; shell_4 &lt;span class="hl opt"&gt;&amp;gt;/&lt;/span&gt;dev&lt;span class="hl opt"&gt;/&lt;/span&gt;null&lt;/pre&gt;&lt;br /&gt;Now we'll have a look at the time results:&lt;br /&gt;&lt;br /&gt;&lt;pre class="hl"&gt;&lt;span class="hl str"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;---Cut---&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;real    1m10.278s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;user    0m20.068s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;sys     1m9.745s &lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;---Awk---&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;real    1m24.043s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;user    0m25.170s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;sys     1m21.238s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;---Shell 1---&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;real    0m1.387s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;user    0m1.282s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;sys     0m0.100s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;---Shell 2---&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;real    0m1.219s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;user    0m1.109s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;sys     0m0.104s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;---Shell 3---&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;real    0m0.943s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;user    0m0.852s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;sys     0m0.090s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;---Shell 4---&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;real    0m0.887s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;user    0m0.786s&lt;/span&gt;&lt;br /&gt;&lt;span class="hl str"&gt;sys     0m0.097s&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;First, notice that the functions with cut and awk took &lt;b&gt;over a minute each&lt;/b&gt; to complete the work! &amp;nbsp;Compare this with the results of &lt;i&gt;Shell 1&lt;/i&gt;&amp;nbsp;and &lt;i&gt;Shell 2&lt;/i&gt;&amp;nbsp;and you can see a massive difference. &amp;nbsp;&lt;b&gt;The latter only took a little over a second &lt;/b&gt;to complete. &amp;nbsp;The obvious lesson here, as Brock Noland pointed out in his post, is that cut and awk are not the best solution in a case like this.&lt;br /&gt;&lt;br /&gt;The last two functions, whose results are displayed in&amp;nbsp;&lt;i&gt;Shell 3&lt;/i&gt;&amp;nbsp;and &lt;i&gt;Shell 4&lt;/i&gt;, are my modifications. &amp;nbsp;I was able to shave enough off to get them both below a second in execution time. &amp;nbsp;I did this by moving some stuff out of the &lt;i&gt;for loop&lt;/i&gt;&amp;nbsp;that did not need to be in there at all. &amp;nbsp;This saves a tiny bit of work for the processor. &amp;nbsp;On big jobs, this would add up to bigger time differences.&lt;br /&gt;&lt;br /&gt;Don't use cut or awk for jobs like this. &amp;nbsp;Let the shell do the work.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-6298064760608411029?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/6298064760608411029/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/01/optimizing-your-shell-scripts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/6298064760608411029'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/6298064760608411029'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2010/01/optimizing-your-shell-scripts.html' title='Optimizing your shell scripts'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-8289063657946153263</id><published>2009-12-28T16:28:00.000-08:00</published><updated>2010-06-18T19:09:12.496-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dirs'/><category scheme='http://www.blogger.com/atom/ns#' term='popd'/><category scheme='http://www.blogger.com/atom/ns#' term='pushd'/><category scheme='http://www.blogger.com/atom/ns#' term='CLI'/><category scheme='http://www.blogger.com/atom/ns#' term='builtins'/><title type='text'>Using pushd, popd and dirs</title><content type='html'>Since I have a bit of time on my hands, I thought I might share a trick or two. &amp;nbsp;Well, not really 'tricks,' but good information to know. I will cover the shell builtins, pushd, popd, and dirs for bash and zsh.  Additionally, I will demonstrate how to use some shell aliases, in order to make the use of these handy builtins even more convenient, and time saving.&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;Wouldn't it be nice if you could have your shell keep track of the directories where you were, so that you could easily return to them later? If you are using bash or zsh, you already have this capability available to you.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;Say you are working in the directory ~/programming/network/modules.&amp;nbsp; You wish to cd to another directory, and then return.&amp;nbsp; There are several ways you could do this, but some are definitely more efficient than others.  Consider:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;modules $ cd ~/bin&lt;br /&gt;bin $&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now, to get back to the directory ~/programming/network/modules, I hope you would never consider doing this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;bin $ cd ~/programming/network/modules&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Of course you &lt;i&gt;could&lt;/i&gt; do it that way, but it is such a waste of keystrokes, and of your time.&amp;nbsp; In this case, it is best to do this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;bin $ cd -&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The cd - is a short cut to return to the previous directory.&amp;nbsp; It only is useful for &lt;i&gt;one&lt;/i&gt; directory though.&amp;nbsp; If you were to issue this command repeatedly, you would flip back and forth between the same two directories.&lt;br /&gt;&lt;br /&gt;If you want the shell to remember more directories, you need to use the pushd and popd commands.&amp;nbsp; By using these two, you can utilise the directory stack to keep track of directories you want to.&amp;nbsp; Instead of using cd to change directory, use pushd to both push the current directory name on to the stack, &lt;i&gt;and&lt;/i&gt; to change to the new directory you wanted.&amp;nbsp; To return to my previous example, where I was in ~/programming/network/modules, and wanted to change to ~/bin, I would do:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;modules $ &lt;span style="color: red;"&gt;pushd ~/bin&lt;/span&gt;&lt;br /&gt;~/bin ~/programming/network/modules&lt;br /&gt;bin $&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now I am in ~/bin, and the old directory (~/programming/network/modules) is on the stack, saved for future use.&amp;nbsp; If I wanted to return to the previous directory, I would simply do:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;bin $ &lt;span style="color: red;"&gt;popd&lt;/span&gt;&lt;br /&gt;~/programming/network/modules&lt;br /&gt;modules $&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Right back where I started!&amp;nbsp; Of course, if you were only changing directory once, you would be better off using cd -, as shown previously.&amp;nbsp; But if you have a great deal of directories you wish to save, push them on to the stack with pushd, and use them later.&lt;br /&gt;&lt;br /&gt;How then, do I keep track of where I am at, and what stack frames are available, and where?&amp;nbsp; Consider the following (a contrived example, but good enough as an illustration):&lt;br /&gt;&lt;br /&gt;&lt;code&gt;modules $ &lt;span style="color: red;"&gt;cd&lt;/span&gt;&lt;br /&gt;~ $ &lt;span style="color: red;"&gt;pushd programming&lt;/span&gt;&lt;br /&gt;~/programming ~&lt;br /&gt;programming $ &lt;span style="color: red;"&gt;pushd network/&lt;/span&gt;&lt;br /&gt;~/programming/network ~/programming ~&lt;br /&gt;network $ &lt;span style="color: red;"&gt;pushd modules/&lt;/span&gt;&lt;br /&gt;~/programming/network/modules ~/programming/network ~/programming ~&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;As you can see, I issued a cd command which, without options or arguments, changed my current working directory to my home directory, ~/.&amp;nbsp; Then I pushed 3 directories on to the stack: &amp;nbsp;~/programming, ~/network, and ~/modules. &amp;nbsp;If I use the dirs -v command, I can get a listing of the directory stack:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;modules $ dirs -v&lt;br /&gt;&amp;nbsp;0&amp;nbsp; ~/programming/network/modules&lt;br /&gt;&amp;nbsp;1&amp;nbsp; ~/programming/network&lt;br /&gt;&amp;nbsp;2&amp;nbsp; ~/programming&lt;br /&gt;&amp;nbsp;3&amp;nbsp; ~&lt;br /&gt;modules $&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;I pushed ~/ on to the stack first, and you can see now that it is on the 'bottom', underneath all the other frames.&lt;br /&gt;&lt;br /&gt;You can also use the dirs command with no options, where you will get a listing of the stack frames, but listed on the same line, with the left side corresponding to the most recent push, and the right side being the first push:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;modules $ &lt;span style="color: red;"&gt;dirs&lt;/span&gt;&lt;br /&gt;~/programming/network/modules ~/programming/network ~/programming ~&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You can use the info from dirs -v to make directory changes. &amp;nbsp;If I wanted to go to ~/programming rather quickly, I would do:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;modules $ pushd +2&lt;br /&gt;~/programming ~ ~/programming/network/modules ~/programming/network&lt;br /&gt;programming $&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The +2 corresponds to frame 2 of the dirs -v listing above.&lt;br /&gt;&lt;br /&gt;Both pushd and popd can take an integer like the above +2, with either '+' or '-'.&amp;nbsp; If a '+' is specified, +&lt;i&gt;n&lt;/i&gt;, then the &lt;i&gt;n&lt;/i&gt;th stack frame from the 'top' of the stack (dirs -v, or the 'left' of a dirs listing)' is affected.&amp;nbsp; If a '-' is specified, -&lt;i&gt;n&lt;/i&gt;, then the &lt;i&gt;n&lt;/i&gt;th frame from the 'bottom of the stack (dirs -v, or the 'right' of a dirs listing) is affected.&amp;nbsp; To confuse things a little here, in the zsh, if setopt PUSHD_MINUS is set, then the function of the '+' and '-' are reversed when used with both pushd and popd.&lt;br /&gt;&lt;br /&gt;zsh also has a feature where you can use cd with a +&lt;i&gt;n&lt;/i&gt; where &lt;i&gt;n &lt;/i&gt;corresponds to a stack frame, and the cd will be to that directory.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;[kermit@minty]~/programming/network% pwd&lt;br /&gt;/home/kermit/programming/network&lt;br /&gt;[kermit@minty]~/programming/network% dirs -v &lt;br /&gt;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~/programming/network&lt;br /&gt;&lt;span style="color: red;"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /bin&lt;/span&gt;&lt;br /&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~&lt;br /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~/programming&lt;br /&gt;[kermit@minty]~/programming/network% &lt;span style="color: red;"&gt;cd +1&lt;/span&gt;&lt;br /&gt;/bin&lt;br /&gt;[kermit@minty]/bin% &lt;span style="color: red;"&gt;pwd&lt;/span&gt;&lt;br style="color: red;" /&gt;&lt;span style="color: red;"&gt;/bin&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This should be enough to give you an idea of what can be accomplished with pushd and popd.&amp;nbsp; If you find yourself using these two commands often, you will begin to long for a shortcut.&amp;nbsp; Place the following in your .bashrc (or .zshrc)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;alias -- +='pushd'&lt;br /&gt;alias -- -='popd'&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now you can use + for pushd, and - for popd.&lt;br /&gt;&lt;br /&gt;A couple of other thoughts.&amp;nbsp; First of all, if you want to clear your directory stack, do&lt;br /&gt;&lt;br /&gt;&lt;code&gt;dirs -c&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Regarding dirs, a useful feature of zsh (which bash doesn't have) is the ability to populate the stack 'manually' with a list, using the dirs command:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;[kermit@minty]~% pwd&lt;br /&gt;/home/kermit&lt;br /&gt;[kermit@minty]~% dirs -v&lt;br /&gt;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~&lt;br /&gt;[kermit@minty]~% &lt;span style="color: red;"&gt;dirs ~/programming ~/programming/network /bin /usr/src&lt;/span&gt;&lt;br /&gt;[kermit@minty]~% dirs -v&lt;br /&gt;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~&lt;br /&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~/programming&lt;br /&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~/programming/network&lt;br /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /bin&lt;br /&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /usr/src&lt;br /&gt;[kermit@minty]~%&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;As you can see, the directory stack was built from the list I entered &lt;i&gt;plus&lt;/i&gt; the current working directory.&lt;br /&gt;&lt;br /&gt;You might have noticed that every time you do a pushd (or popd), the next line is always the output of a dirs command.&amp;nbsp; &lt;s&gt;I don't know of any way to silence this with bash&lt;/s&gt;, but with zsh, just add the following to your .zshrc:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;setopt PUSHD_SILENT&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;To get the same effect in bash, you could do an alias for pushd and popd:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;alias pushd='pushd &amp;gt; /dev/null'&lt;br /&gt;alias popd='popd &amp;gt; /dev/null'&lt;br /&gt;&lt;br /&gt;#If you did the +/- alias for pushd/popd as shown above, try&lt;br /&gt;&lt;br /&gt;alias -- +='pushd &amp;gt; /dev/null'&lt;br /&gt;alias -- -='popd &amp;gt; /dev/null'&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Finally, if you use zsh, and you want to automatically store directory changes on the stack just by moving around with cd, put the following in your .zshrc:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;setopt&amp;nbsp; AUTO_PUSHD&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;With this option set, every cd command will act like a pushd command, storing your current directory on the stack, and then changing to the new directory.&amp;nbsp; This will save you a lot of typing!&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Unless you like the idea of typing more than necessary, you will want to use pushd, popd, and dirs to your advantage while on the command line, in order to save time, and wear and tear on your wrists/fingers.&amp;nbsp; As always, consult your local man pages for particulars about the shell that you are using.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-8289063657946153263?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/8289063657946153263/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/12/using-pushd-and-popd.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/8289063657946153263'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/8289063657946153263'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/12/using-pushd-and-popd.html' title='Using pushd, popd and dirs'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-7022901693971405005</id><published>2009-12-21T03:39:00.000-08:00</published><updated>2010-01-14T19:04:49.384-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Gnome'/><title type='text'>How to delete the 'Desktop' folder in Gnome...</title><content type='html'>...and not have the contents of your home directory displayed on your desktop.&lt;br /&gt;&lt;br /&gt;Maybe its just me, but I really don't like the way that a fresh Gnome install sets up a user's home directory with a bunch of empty directories, like 'Video', 'Documents', and the totally evil 'Desktop' folder. &amp;nbsp;If you are like me, you want to decide what is in the home folder, which does not include all the extra directories they offer. &amp;nbsp;A reasonable person would expect that the quick and easy solution would be to delete the unwanted directories, but not so fast my friend. &amp;nbsp;All of the directories can be safely deleted, but one. &amp;nbsp;If you remove the 'Desktop' folder, you will end up with all the contents of your home directory (not including hidden files) displayed on your desktop. &amp;nbsp; Of course fixing your 'mistake' of deleting the &lt;i&gt;Desktop&lt;/i&gt; folder is not as easy as doing a &lt;br /&gt;&lt;br /&gt;&lt;code&gt;mkdir ~/Desktop&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;No no, the wonderful people at Gnome must have thought that would be too easy. &amp;nbsp;No, first you must search around on the internet and find a post like &lt;a href="http://ubuntuforums.org/showthread.php?t=581498"&gt;this one&lt;/a&gt;. &amp;nbsp;Then you have to fire up your editor and do some editing, as &lt;i&gt;well as &lt;/i&gt;replacing the folder 'Desktop.' &amp;nbsp;Then all will be well. Except for the fact that your home directory still has a folder in it that YOU DON'T WANT!!!1!&lt;br /&gt;&lt;br /&gt;Anyway, the solution is pretty simple.&lt;a name='more'&gt;&lt;/a&gt;&amp;nbsp;You still have to have some sort of directory to point Nautilus to, but nobody says it can't be hidden. &amp;nbsp;Here is what you do:&lt;br /&gt;&lt;br /&gt;Create a hidden directory like so:&lt;br /&gt;&lt;br /&gt;&lt;ocde&gt;mkdir ~/.desktop&lt;br /&gt;&lt;br /&gt;Then open the file ~/.config/user-dirs.dirs with your favourite editor, eg:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;vi ~/.config/user-dirs.dirs&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;In there you will see something like the following:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="color: red;"&gt;XDG_DESKTOP_DIR="$HOME/"&lt;/span&gt;&lt;br /&gt;XDG_DOWNLOAD_DIR="$HOME/"&lt;br /&gt;XDG_TEMPLATES_DIR="$HOME/"&lt;br /&gt;XDG_PUBLICSHARE_DIR="$HOME/"&lt;br /&gt;XDG_DOCUMENTS_DIR="$HOME/"&lt;br /&gt;XDG_MUSIC_DIR="$HOME/"&lt;br /&gt;XDG_PICTURES_DIR="$HOME/"&lt;br /&gt;XDG_VIDEOS_DIR="$HOME/"&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The line in red (above) is the one you want to change:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;XDG_DESKTOP_DIR="$HOME/&lt;span style="color: red;"&gt;.desktop&lt;/span&gt;"&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;After this, you can kill nautilus (it should restart for you), or reboot your machine if you like, and your problem will be solved. &amp;nbsp;You will not have the ugly mess of unwanted directories in your home folder, nor will your home folder be displayed on your desktop any longer.&lt;/ocde&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-7022901693971405005?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/7022901693971405005/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/12/how-to-delete-your-desktop-folder-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/7022901693971405005'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/7022901693971405005'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/12/how-to-delete-your-desktop-folder-in.html' title='How to delete the &apos;Desktop&apos; folder in Gnome...'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-363482446396374378</id><published>2009-12-18T19:25:00.000-08:00</published><updated>2009-12-25T09:16:40.621-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ps'/><category scheme='http://www.blogger.com/atom/ns#' term='grep'/><category scheme='http://www.blogger.com/atom/ns#' term='egrep'/><category scheme='http://www.blogger.com/atom/ns#' term='CLI'/><title type='text'>ps headers and grep</title><content type='html'>GNU &lt;a href="http://linux.die.net/man/1/ps"&gt;ps(1)&lt;/a&gt; has a &lt;i&gt;plethora&lt;/i&gt; of options.&amp;nbsp; One of the more useful features of ps is the header label which is printed at the top of the ps output, such as in the following snippet:&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;Listing 1.1&lt;/b&gt;&lt;/span&gt;&lt;code&gt;&lt;br /&gt;char $ ps&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: red;"&gt;PID TTY          &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TIME CMD&lt;/span&gt;&lt;br /&gt;15705 pts/1    00:00:00 bash&lt;br /&gt;16345 pts/1    00:00:00 ps&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;As you can see, each column has a label on the top.&amp;nbsp; In this example (Listing 1.1), the columns are labelled PID, TTY, TIME and CMD.&amp;nbsp; This is the most basic invocation of the ps command, and the output is minimal.&amp;nbsp; If you start adding options, such as doing &lt;b&gt;ps aux&lt;/b&gt;, (where you will get you a listing of all the processes on the system using BSD style syntax) you will get quite a bit more text to sift through.&amp;nbsp; But what if you are only after a certain term, such as &lt;i&gt;tty&lt;/i&gt;, for example in the &lt;b&gt;ps aux&lt;/b&gt; listing?&lt;a name='more'&gt;&lt;/a&gt; To start with, you could pipe the output of ps into &lt;a href="http://linux.die.net/man/1/grep"&gt;grep(1)&lt;/a&gt;, in order to list only the things you are looking for:&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;Listing 1.2&lt;/b&gt;&lt;/span&gt;&lt;code&gt;&lt;br /&gt;char $ ps aux | grep tty&lt;br /&gt;root      1588  0.0  0.0   1852   444 tty4     Ss+  Dec17   0:00 /sbin/mingetty tty4&lt;br /&gt;root      1592  0.0  0.0   1852   440 tty6     Ss+  Dec17   0:00 /sbin/mingetty tty6&lt;br /&gt;root      1634  2.2  2.7  46812 28332 tty1     Ss+  Dec17  42:09 /usr/bin/Xorg :0 -nr -verbose -auth /var/run/gdm/auth-for-gdm-6n8EnG/database -nolisten tcp vt1&lt;br /&gt;root     12845  0.0  0.0   1852   444 tty3     Ss+  Dec17   0:00 /sbin/mingetty tty3&lt;br /&gt;root     12898  0.0  0.0   1852   452 tty5     Ss+  Dec17   0:00 /sbin/mingetty tty5&lt;br /&gt;root     14863  0.0  0.0   1852   452 tty2     Ss+  06:57   0:00 /sbin/mingetty tty2&lt;br /&gt;kermit   16382  0.0  0.0   4192   780 pts/1    S+   21:42   0:00 grep tty&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This works, but there are a couple of things I don't like about it.&amp;nbsp; First of all, there are some instances of tty that I &lt;i&gt;don't want.&lt;/i&gt;&amp;nbsp; Most notable is the last line, which lists the instance of grep looking for 'tty'.&amp;nbsp;&amp;nbsp; We can get rid of this by doing a &lt;b&gt;grep -v&lt;/b&gt;, which basically says 'don't match &lt;i&gt;this&lt;/i&gt;,' where &lt;i&gt;this &lt;/i&gt;is the term you supply.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;Listing 1.3&lt;/b&gt;&lt;/span&gt;&lt;code&gt;&lt;br /&gt;char $ ps aux | grep tty | grep -v grep | grep -v tty1&lt;br /&gt;root      1588  &amp;nbsp;0.0  0.0   1852   444 tty4     Ss+  Dec17   0:00 /sbin/mingetty tty4&lt;br /&gt;root      1592  &amp;nbsp;0.0  0.0   1852   440 tty6     Ss+  Dec17   0:00 /sbin/mingetty tty6&lt;br /&gt;root     12845  0.0  0.0   1852   444 tty3     Ss+  Dec17   0:00 /sbin/mingetty tty3&lt;br /&gt;root     12898  0.0  0.0   1852   452 tty5     Ss+  Dec17   0:00 /sbin/mingetty tty5&lt;br /&gt;root     14863  0.0  0.0   1852   452 tty2     Ss+  06:57   0:00 /sbin/mingetty tty2&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This looks a lot better.&amp;nbsp; Notice that I actually eliminated &lt;i&gt;two &lt;/i&gt;entries with grep -v:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;Listing 1.4&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;char $ ps aux | grep tty | &lt;span style="color: red;"&gt;grep -v grep | grep -v tty1&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;First, I got rid of the line listing grep (listing 1.4a below) as well as the long line with tty1 (listing 1.4b below). &lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;Listing 1.4a&lt;/b&gt;&lt;/span&gt;&lt;code&gt;&lt;br /&gt;kermit   16382  0.0  0.0   4192   780 pts/1    S+   21:42   0:00 &lt;span style="color: red;"&gt;grep tty&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;Listing 1.4B&lt;/b&gt;&lt;/span&gt;&lt;code&gt;&lt;br /&gt;root      1634  2.2  2.7  46812 28332 &lt;span style="color: red;"&gt;tty1&lt;/span&gt;     Ss+  Dec17  42:09 /usr/bin/Xorg :0 -nr -verbose -auth /var/run/gdm/auth-for-gdm-6n8EnG/database -nolisten tcp vt1&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the interest of less typing, a way to shorten this string of commands would be to use the &lt;a href="http://linux.die.net/man/1/egrep"&gt;egrep(1)&lt;/a&gt; program, instead of grep. egrep allows for extended regular expression&amp;nbsp; usage, and can be invoked either by egrep or grep -E.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;Listing 1.5&lt;/b&gt;&lt;/span&gt;&lt;code&gt;&lt;br /&gt;char $ ps aux | grep tty | &lt;span style="color: red;"&gt;egrep -v 'grep|tty1'&lt;/span&gt;&lt;br /&gt;root      1588  &amp;nbsp;0.0  0.0   1852   444 tty4     Ss+  Dec17   0:00 /sbin/mingetty tty4&lt;br /&gt;root      1592  &amp;nbsp;0.0  0.0   1852   440 tty6     Ss+  Dec17   0:00 /sbin/mingetty tty6&lt;br /&gt;root     12845  0.0  0.0   1852   444 tty3     Ss+  Dec17   0:00 /sbin/mingetty tty3&lt;br /&gt;root     12898  0.0  0.0   1852   452 tty5     Ss+  Dec17   0:00 /sbin/mingetty tty5&lt;br /&gt;root     14863  0.0  0.0   1852   452 tty2     Ss+  06:57   0:00 /sbin/mingetty tty2&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;As you can see, the command is shorter, but the output is still the same, and looks nice.&amp;nbsp; There is one other problem though; there are eleven columns, but no label to indicate the kind of information being displayed.&amp;nbsp; The label is printed with ps aux, but the grep output doesn't print that, because &lt;i&gt;I didn't ask it to do that&lt;/i&gt;.&amp;nbsp; I need to ask grep to display all the lines with tty&lt;i&gt; and &lt;/i&gt;the header also&lt;i&gt;.&lt;/i&gt; Once again I will use egrep to get what I am after:&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;Listing 1.6&lt;/b&gt;&lt;/span&gt;&lt;code&gt;&lt;br /&gt;char $ ps aux | &lt;span style="color: red;"&gt;egrep 'PID|tty'&lt;/span&gt; | egrep -v 'grep|tty1'&lt;br /&gt;USER       PID %CPU %MEM    VSZ    RSS TTY      STAT START   TIME COMMAND&lt;br /&gt;root      1588  &amp;nbsp;0.0  0.0   1852   444 tty4     Ss+  Dec17   0:00 /sbin/mingetty tty4&lt;br /&gt;root      1592  &amp;nbsp;0.0  0.0   1852   440 tty6     Ss+  Dec17   0:00 /sbin/mingetty tty6&lt;br /&gt;root     12845  0.0  0.0   1852   444 tty3     Ss+  Dec17   0:00 /sbin/mingetty tty3&lt;br /&gt;root     12898  0.0  0.0   1852   452 tty5     Ss+  Dec17   0:00 /sbin/mingetty tty5&lt;br /&gt;root     14863  0.0  0.0   1852   452 tty2     Ss+  06:57   0:00 /sbin/mingetty tty2&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;I told egrep to look for both 'PID' ('PID' is found in the header label, so grep finds it and prints the entire line) and 'tty,' but &lt;i&gt;not&lt;/i&gt; to print any line with 'tty1' or 'grep' in it.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Final thoughts:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;By chaining a couple of commands together with pipes, you can produce some pretty informative, and easy to read output.&amp;nbsp; I would encourage you to read through your local man pages for ps and grep, to get a better handle on what options are available to you on &lt;i&gt;your &lt;/i&gt;system.&amp;nbsp; &lt;br /&gt;&lt;br /&gt;The idea of using egrep to grab the ps header is not mine.&amp;nbsp; I came across it in &lt;a href="http://www.aeleen.com/home.htm"&gt;&lt;i&gt;Æ&lt;/i&gt;leen Frisch's&lt;/a&gt; book &lt;a href="http://oreilly.com/catalog/9781565921276"&gt;&lt;i&gt;Essential System Administration&lt;/i&gt;, Second edition&lt;/a&gt;, pg 261.&amp;nbsp; This edition of her book is now out of print, however the &lt;a href="http://oreilly.com/catalog/9780596003432"&gt;third edition&lt;/a&gt; is still available.&amp;nbsp; I haven't read it (yet), but it is on my short list of books to buy.&amp;nbsp; Ironically, I picked up my copy of the second edition in a clearance bin at a local store a number of years ago.&amp;nbsp; I let it sit on my shelf for a long time after that.&amp;nbsp; Then one day I decided to start reading it, and could not put it down.&amp;nbsp; I still refer to it fairly regularly.&amp;nbsp; It is a very good book, and I would recommend it to anyone who wishes to become better at doing sys-admin type work&lt;i&gt;.&lt;/i&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-363482446396374378?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/363482446396374378/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/12/ps-headers-and-grep.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/363482446396374378'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/363482446396374378'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/12/ps-headers-and-grep.html' title='ps headers and grep'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-7791075948201721314</id><published>2009-08-04T19:02:00.000-07:00</published><updated>2009-08-04T19:37:38.580-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Find'/><category scheme='http://www.blogger.com/atom/ns#' term='CLI'/><title type='text'>Find gotcha</title><content type='html'>Not too sure if I can call this a bonafide 'gotcha,' but it is something to keep in mind.&lt;br /&gt;&lt;br /&gt;It is a good idea to occasionally check your Unix system for orphaned files. Normally you do so by using &lt;i&gt;find &lt;/i&gt;with the -nouser and -nogroup filters. You could do two separate searches, one for -nouser, and then one for -nogroup, but typically the two are combined in one find command.  Now here is the gotcha:&lt;div&gt;&lt;br /&gt;&lt;code&gt;find / -nouser -nogroup -print&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If you search &lt;a href="http://www.google.ca/search?hl=en&amp;amp;rlz=1C1GGLS_enCA339CA339&amp;amp;q=find+&amp;quot;-nouser+-nogroup&amp;quot;&amp;amp;btnG=Search&amp;amp;meta="&gt;find "-nouser -nogroup"&lt;/a&gt; on Google you likely find some examples like the one above.  The problem with it is that there is an implied &lt;i&gt;and &lt;/i&gt;when two or more filters are used as in the example.  It is the same as doing the following (explicitly):&lt;br /&gt;&lt;br /&gt;&lt;code&gt;find / -nouser &lt;span class="Apple-style-span"  style="color:#FF6666;"&gt;-a&lt;/span&gt; -nogroup -print&lt;/code&gt;&lt;br /&gt;or:&lt;br /&gt;&lt;code&gt;find / -nouser &lt;span class="Apple-style-span"  style="color:#FF6666;"&gt;-and&lt;/span&gt; -nogroup -print&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The examples above will only 'find' files that belong to 'nouser' &lt;b&gt;&lt;i&gt;and &lt;/i&gt;&lt;/b&gt;'nogroup.'  If a file matches -nouser, but not -nogroup, find will not display it.  If a file exists that matches -nogroup, but not -nouser, it will not display.  Find will only return results that meet &lt;i&gt;both &lt;/i&gt;criteria.  In order to find all orphaned files, you want to do an &lt;i&gt;or:&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;find / -nouser &lt;span class="Apple-style-span"  style="color:#FF0000;"&gt;-o&lt;/span&gt; -nogroup -print&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now go have some fun tracking down those orphaned files!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-7791075948201721314?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/7791075948201721314/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/08/find-gotcha.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/7791075948201721314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/7791075948201721314'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/08/find-gotcha.html' title='Find gotcha'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-5451152410674869374</id><published>2009-08-03T17:48:00.000-07:00</published><updated>2009-12-28T17:22:29.047-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Find'/><category scheme='http://www.blogger.com/atom/ns#' term='CLI'/><title type='text'>Getting rid of troublesome files with GNU find.</title><content type='html'>Ok, so this isn't that much of a problem these days for those who are running a GUI, but what about when X isn't available?  Consider the following:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;kermit@fastbox ~/tmp/work2 $ ls -l&lt;br /&gt;total 4&lt;br /&gt;-rw-r--r-- 1 kermit kermit 37 2009-08-03 21:04 -pesky&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;I got that file by doing:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;kermit@fastbox ~/tmp/work2 $ echo "Haha, sucker"\! "Try and get rid of me"\! &amp;gt; -pesky&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Now try and issue the rm command on the file &lt;span style="font-style: italic;"&gt;-pesky&lt;/span&gt; and you will find that it doesn't work so well.  What can you do?  Well, you can do what Bash tells you, and do:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;kermit@fastbox ~/tmp/work2 $ rm -f ./-pesky&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Or if you read the man page for rm, you would know that you can also do:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;kermit@fastbox ~/tmp/work2 $ rm -f  -- -pesky  &lt;span style="color: red;"&gt;#The '--' tells the shell there are no more options following.&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;But there is another interesting way to do this operation, and it will work with other kinds of problematic, persistent files as well.  We will use &lt;span style="font-style: italic;"&gt;find&lt;/span&gt; to nuke the file.  First, you need to find the inode number of the file, by using ls with the -i flag:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;kermit@fastbox ~/tmp/work2 $ ls -li&lt;br /&gt;total 4&lt;br /&gt;8339920 -rw-r--r-- 1 kermit kermit 37 2009-08-03 20:57 -pesky&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;In this case, the inode number is 8339920.  Now we can tell &lt;span style="font-style: italic;"&gt;find&lt;/span&gt; to find the file with that number.  Once it finds it, we can -exec /bin/rm -f and remove it:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;kermit@fastbox ~/tmp/work2 $ find . -inum 8339920 -exec /bin/rm -f {} \;&lt;br /&gt;kermit@fastbox ~/tmp/work2 $ ls -l&lt;br /&gt;total 0&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-5451152410674869374?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/5451152410674869374/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/08/getting-rid-of-troublesome-files-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/5451152410674869374'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/5451152410674869374'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/08/getting-rid-of-troublesome-files-with.html' title='Getting rid of troublesome files with GNU find.'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-6391231983574516703</id><published>2009-02-09T09:18:00.000-08:00</published><updated>2009-02-09T12:10:17.671-08:00</updated><title type='text'>OpenSolaris 2008.11 - What is right, and what needs work</title><content type='html'>A friend of mine was trying to compile a simple C program on his university shell account. It turns out that the server hosting his shell account runs some version of Solaris.  Not being experienced with anything Sun, I was not as helpful as I would like to have been with his questions about invoking the compiler.  Since I had often thought that I would like to give &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;OpenSolaris&lt;/span&gt; a whirl, now seemed like a good time to try.  This is a short account of my experience doing just that, triple booting Linux, FreeBSD, and &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;OpenSolaris&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;First of all, to boot &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;OpenSolaris&lt;/span&gt; after installation, it is not just a matter of editing your grub.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;conf&lt;/span&gt; with an entry for &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;OpenSolaris&lt;/span&gt;.  The version of grub supplied with &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_5"&gt;OpenSolaris&lt;/span&gt; is special, and needs to be installed in order to boot into that OS.  This works &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_6"&gt;ok&lt;/span&gt;, and you can either add your other entries to it, or you can do like I did and leave the original grub on /&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_7"&gt;dev&lt;/span&gt;/&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_8"&gt;hda&lt;/span&gt;, and then use an entry like this to get to either the FreeBSD &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_9"&gt;bootloader&lt;/span&gt; or the &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_10"&gt;OpenSolaris&lt;/span&gt; grub on /&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_11"&gt;dev&lt;/span&gt;/&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_12"&gt;hdb&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;# For booting GNU/Linux&lt;br /&gt;title  GNU/Linux 2.6.27-gentoo-r8&lt;br /&gt;root (&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_13"&gt;hd&lt;/span&gt;0,0)&lt;br /&gt;kernel /boot/kernel-2.6.27-gentoo-r8 root=/&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_14"&gt;dev&lt;/span&gt;/&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_15"&gt;hda&lt;/span&gt;3 \&lt;br /&gt;video=&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_16"&gt;uvesafb&lt;/span&gt;:1280x1024-24,&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_17"&gt;mtrr&lt;/span&gt;:3,&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_18"&gt;ywrap&lt;/span&gt; \&lt;br /&gt;&lt;br /&gt;#For booting FreeBSD&lt;br /&gt;title FreeBSD&lt;br /&gt;root (&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_19"&gt;hd&lt;/span&gt;1,0)&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_20"&gt;savedefault&lt;/span&gt;&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_21"&gt;makeactive&lt;/span&gt;&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_22"&gt;chainloader&lt;/span&gt; +1&lt;br /&gt;&lt;br /&gt;#For booting &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_23"&gt;OpenSolaris&lt;/span&gt;&lt;br /&gt;title &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_24"&gt;OpenSolaris&lt;/span&gt;&lt;br /&gt;root (&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_25"&gt;hd&lt;/span&gt;1,1)&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_26"&gt;savedefault&lt;/span&gt;&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_27"&gt;makeactive&lt;/span&gt;&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_28"&gt;chainloader&lt;/span&gt; +1&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The installation went very well.  I popped in the &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_29"&gt;livecd&lt;/span&gt;, and once the desktop came up, clicked on the icon there to install the OS.  It made me fill in some info, like &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_30"&gt;username&lt;/span&gt;/password stuff, as well as timezone etc., and partitions.  Then it did the install.  After that, all I had to do was reboot.&lt;br /&gt;&lt;br /&gt;The boot into the full install was impressive.   The screen resolution just worked, although &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_32"&gt;nvidia&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_33"&gt;twinview&lt;/span&gt; was not working immediately.  All that was needed for that was to open a shell and enter '&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_34"&gt;pfexec&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_35"&gt;nvidia&lt;/span&gt;-&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_36"&gt;config&lt;/span&gt;' and then use the sweet utility to change the settings.  You can read more about that &lt;a href="http://weblogs.java.net/blog/bleonard/archive/2008/05/opensolaris_200.html"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;There were a few issues with drivers.  I run an old &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_37"&gt;Asus&lt;/span&gt; A8V-Deluxe motherboard, which is well supported under Linux and FreeBSD, but apparently not as well with &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_38"&gt;OpenSolaris&lt;/span&gt;.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;First off, it did not automatically do something intelligent with the Marvell 88E8001 Ethernet Controller.  That was not too much trouble though, as I was able to boot back into Linux, download a driver, and then boot back into Solaris and install it.  It worked well then, and the network &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_39"&gt;automagically&lt;/span&gt; worked too.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;The second problem was with the &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_40"&gt;Sata&lt;/span&gt; Raid controller - no driver for that either.  Not a problem for me, as I still am running a pair of &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_41"&gt;ATA&lt;/span&gt; disks; for those of you with &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_42"&gt;Sata&lt;/span&gt;, this could be trouble though.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;The final problems were sound-card related.  The Creative Sound Blaster X-&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_43"&gt;Fi&lt;/span&gt; Extreme did not surprise me - it is hardly supported under Linux.  But my old C-Media card was not picked up either.  Oh well - Windows 7 had some trouble with that one too.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Over all, my impression of the install was favourable.  I think that a lot of work has gone into the installer and &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_44"&gt;sysconfig&lt;/span&gt; utilities, to make the experience a pleasant one, and it shows.  Kudos to the people who are working on that end of &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_45"&gt;OpenSolaris&lt;/span&gt;.  I am also fairly impressed with the package management system which has a nice graphical user interface.  Nice and easy to use, and from my experience, takes care of all the dependencies.  It is on par with modern Linux distributions, if nothing else.&lt;br /&gt;&lt;br /&gt;Now for the parts that I didn't like so much..&lt;br /&gt;&lt;br /&gt;The first point is a minor one; though I was impressed with the initial boot, this had to do more with the fact that things worked, and not so much to do with the &lt;span style="font-style: italic;"&gt;presentation&lt;/span&gt;.  What I mean is that upon booting to the grub menu, the user is given two choices, either a regular boot (which happens to be a graphical frame-buffer deal with a 'sort of' progress bar.  Basically it just keeps moving so you get the idea that something is going on, I guess.)  or a text boot from the console.  I selected this (text-boot) once, just to see how it looked and, as a Gentoo user, I can say that I was totally disappointed.  There was hardly any information there at all.  So if you are into a descriptive (and possibly interactive) boot process, forget about it with OpenSolaris.&lt;br /&gt;&lt;br /&gt;The other thing I did not like was the fact that the default desktop is Gnome.  &lt;a href="http://mail.gnome.org/archives/usability/2005-December/msg00021.html"&gt;Linus doesn't like Gnome&lt;/a&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;[1] &lt;/span&gt;and neither do I.  And here is the kicker, &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_46"&gt;KDE&lt;/span&gt; is not really offered.  Sure, you can get an old version (i.e., 3.4x), or you can go for the super new 4.2x stuff, but no (easy) option for getting 3.5.9 on there.  In my mind, this is a huge mistake.  I have never really been able to get into Gnome, because it seems so hard to customise.  All this said, I gather that it is not easy to get the &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_47"&gt;KDE&lt;/span&gt; 3.x stuff running on &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_48"&gt;OpenSolaris&lt;/span&gt;, and that the 4.x series promises to be good when it is ready.  Until then, I guess I will stick with my Linux, FreeBSD and &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_49"&gt;KDE&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;[1]&lt;/span&gt;.  &lt;span style="font-size:85%;"&gt;Although he has been &lt;a href="http://www.computerworld.com/action/article.do?command=viewArticleBasic&amp;amp;taxonomyName=Software&amp;amp;articleId=9126619&amp;amp;taxonomyId=18&amp;amp;pageNumber=5"&gt;using it lately&lt;/a&gt;, and even &lt;a href="http://distrowatch.com/weekly.php?issue=20090202#feature"&gt;developed a patch for it&lt;/a&gt; at some point, which the developers rejected.&lt;br /&gt;  Yes, you read that right; they rejected it.   !!?? Hey guys, &lt;/span&gt;&lt;span style="font-style: italic;font-size:85%;" &gt;Linus&lt;/span&gt;&lt;span style="font-size:85%;"&gt; sent you a patch!  Put it in!&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-6391231983574516703?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/6391231983574516703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/02/opensolaris-200811-what-is-right-and.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/6391231983574516703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/6391231983574516703'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/02/opensolaris-200811-what-is-right-and.html' title='OpenSolaris 2008.11 - What is right, and what needs work'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-2800600533774038993</id><published>2009-02-08T20:18:00.000-08:00</published><updated>2010-01-14T17:26:56.743-08:00</updated><title type='text'>Building C and C++ Programs</title><content type='html'>For a beginning programmer, sometimes the biggest problem is just getting a program to compile, as opposed to actually writing the program itself.  That is why it is often helpful to do a little 'Hello, world!' program, just to get a feel for the system, how the compiler is invoked, and so on.  So in this post, the reader will learn how to compile a 'Hello, world!' program for three different systems, in two different languages.  The systems will be Linux, FreeBSD, and OpenSolaris.  The first two will be similar in that they both (normally) employ gcc (GNU Compiler Collection, but formerly GNU C Compiler) as the standard system compiler.  OpenSolaris is more interesting, as it makes the Sun C and C++ compilers available, as well as gcc.  As for the languages, if you haven't already guessed, they will be C and C++.  So let's begin with a C program, hello.c:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;&lt;br /&gt;int main(void)&lt;br /&gt;{&lt;br /&gt;printf("Hello, world!\n");&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A simple program, one that lets the programmer concentrate on getting the compiler working,&lt;span style="font-style: italic;"&gt; without&lt;/span&gt; having to worry about fixing source errors.  Now then, the first thing to know is that on many (if not all) Unix like systems, the C compiler can generally be invoked with the command 'cc'.  This may be the actual C compiler, named 'cc,' or the command may be a &lt;span style="font-style: italic;"&gt;symlink&lt;/span&gt; to another compiler, such as gcc.  In the latter case, the symlink is added for the sake of not breaking things.  cc was the standard command for invoking the C compiler, and to take it away would, if nothing else, break tradition, not to mention some Makefiles as well.  You can determine some basic information about where your C compiler resides (and if it is even installed!) by issuing the following command from the shell:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;which cc&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In the case of my OpenSolaris machine, this produces the following:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;/usr/bin/cc&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If I do an ls -l on /usr/bin/cc, I see that it is really just a symlink to another location on disk:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;ls -l /usr/bin/cc&lt;br /&gt;lrwxrwxrwx 1 root root 33 2009-02-08 22:52 /usr/bin/cc -&amp;gt; ../../opt/SunStudioExpress/bin/cc&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;All very interesting stuff.  You could also do something like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;cc -V&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Which produces:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;cc: Sun Ceres C 5.10 SunOS_i386 2008/10/22&lt;br /&gt;usage: cc [ options] files.  Use 'cc -flags' for details&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So in this case, at least, we know that when we use the command 'cc', we are invoking the Sun C compiler.  So why don't we do that then - copy the program hello.c (above) into your favourite text editor, and save it as hello.c -- then, from the directory that you save the hello.c file, invoke the C compiler with the following command:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;cc -o hello hello.c&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;and hit Enter.  You should get your shell prompt back almost immediately.  What you have done with the above command is to run the C compiler (cc), with the compiled output being called 'hello' (-o hello -- -o stands for output name.  If you don't do the -o option, the program will still compile, with the executable being named a.out -- this is also a tradition in Unix like systems.  If you run a.out, it will print 'Hello, world!' to the standard output.  a.out stands for 'assembler output,' which is a fallback to older systems and procedures.) and the input source file to the compiler being hello.c&lt;br /&gt;&lt;br /&gt;As you can see, there is not much to it.  If you do an ls -l in the directory where you ran the compiler from, you should see the executable file, 'hello'  You can run it by typing in:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;./hello&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The ./ part of ./hello means 'Run the program 'hello' which is found in &lt;span style="font-style: italic;"&gt;this&lt;/span&gt; directory.&lt;br /&gt;With OpenSolaris, you have the option to install &lt;span style="font-style: italic;"&gt;another&lt;/span&gt; compiler as well, namely, gcc.  You can issue the same commands to find out where gcc exists and which version you are using:&lt;br /&gt;&lt;pre&gt;which gcc&lt;br /&gt;/usr/bin/gcc&lt;br /&gt;&lt;br /&gt;ls -l /usr/bin/gcc&lt;br /&gt;lrwxrwxrwx 1 root root 14 2009-02-08 23:20 /usr/bin/gcc -&amp;gt; ../sfw/bin/gcc&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Keep in mind that determining the version of gcc is slightly different than the way you do it for cc:&lt;br /&gt;&lt;pre&gt;gcc -v&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note that it is a small v as opposed to a large V for cc.  You can read more about the compiler command switches by doing man cc or man gcc to access the manual page for each compiler.&lt;br /&gt;&lt;br /&gt;If you decide to use gcc, you ought to use two flags every time you compile.  They are the -Wall (Warnings All) and the -Wextra (Warnings extra) flags.  By using them, the compiler will give you lots of extra info with any problems your source code might have.  Their use is indispensable, in my opinion.  Use them like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;gcc -Wall -Wextra -o hello hello.c&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And here is the added bonus - if you can compile like this on OpenSolaris (Sun), then you can do it under Linux or FreeBSD, which come with gcc as the standard compiler.&lt;br /&gt;&lt;br /&gt;Now then, on to compiling C++ programs.  First, we need a suitable 'Hello, world!' program:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;cout &amp;lt;&amp;lt; "Hello, world!" &amp;lt;&amp;lt; endl;&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Now the interesting thing about C++ programs is that there are &lt;span style="font-style: italic;"&gt;several &lt;/span&gt;standard ways of naming with a suffix.  With C, a file is foo.c, such as hello.c -- but with C++ it might be hello.C (note the capital C), or hello.cc, or hello.cpp, or hello.cxx  For our purposes, we will stick to hello.cc  So how do we compile it?  Well, if you want to go the traditional route, you would invoke the C++ compiler like this:  &lt;br /&gt;&lt;pre&gt;CC -o hello hello.cc&lt;br /&gt;&lt;/pre&gt;Note the capital CC; pretty imaginative, huh?  That is simple, and easy to remember though.  If you want to use the GNU C++ compiler, you would do:  &lt;br /&gt;&lt;pre&gt;g++ -o hello hello.cc&lt;br /&gt;&lt;/pre&gt;Both of these methods would produce an executable named 'hello,' which could then be invoked as with './hello' at the command prompt.  If you use g++, once again, you can (and should) use the -Wall -Wextra flags.  Also, you can use g++ in the same fashion on any other system which has the GNU Compiler Collection available, such as Linux, or FreeBSD.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-2800600533774038993?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/2800600533774038993/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/02/building-c-and-c-programs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/2800600533774038993'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/2800600533774038993'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/02/building-c-and-c-programs.html' title='Building C and C++ Programs'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259080474015777403.post-4926377027774260150</id><published>2009-02-01T10:39:00.000-08:00</published><updated>2010-08-28T18:17:56.355-07:00</updated><title type='text'>Getting a simple directory listing in Linux</title><content type='html'>There are often many ways to do the same things under Linux; getting a listing of a given directory falls under that category.  The easiest way is to issue the command, 'ls -l', in the shell.  Alternatively, if you don't mind a bit of work, you could write your own program.&lt;br /&gt;&lt;br /&gt;Lately, I have been reading Steve D. Pate's &lt;i&gt;&lt;a href="http://www.amazon.com/UNIX-Filesystems-Evolution-Design-Implementation/dp/0471164836" target="_blank"&gt;UNIX Filesystems -- Evolution, Design, and Implementation&lt;/a&gt;&lt;/i&gt;.  I am at the section in the book (pp.21-22) where the author implements a simple version of the Unix style ls command.  The book itself was published in 2003 and, as things stand in 2009, the code example he lists will not even compile.  Here is the code:&lt;br /&gt;&lt;pre style="color:#ffffff; font-size:10pt; font-family:'Courier New';"&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;sys/types.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;sys/stat.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;sys/dirent.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;sys/unistd.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;fcntl.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;unistd.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;errno.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;pwd.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;grp.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#define BUFSZ 1024&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ffffff"&gt;main&lt;/span&gt;&lt;span style="color:#ffffff"&gt;()&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ffffff"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; dirent &lt;span style="color:#ffffff"&gt;*&lt;/span&gt;dir&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; stat st&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; passwd &lt;span style="color:#ffffff"&gt;*&lt;/span&gt;pw&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; group &lt;span style="color:#ffffff"&gt;*&lt;/span&gt;grp&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#00ff00"&gt;char&lt;/span&gt; buf&lt;span style="color:#ffffff"&gt;[&lt;/span&gt;BUFSZ&lt;span style="color:#ffffff"&gt;], *&lt;/span&gt;bp&lt;span style="color:#ffffff"&gt;, *&lt;/span&gt;ftime&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#00ff00"&gt;int&lt;/span&gt; dfd&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; fd&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; nread&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    dfd &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;open&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;quot;.&amp;quot;&lt;/span&gt;&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; O_RDONLY&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#ffffff"&gt;bzero&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;buf&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; BUFSZ&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#b26818"&gt;while&lt;/span&gt; &lt;span style="color:#ffffff"&gt;(&lt;/span&gt;nread &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;getdents&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;dfd&lt;span style="color:#ffffff"&gt;, (&lt;/span&gt;&lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; dirent &lt;span style="color:#ffffff"&gt;*) &amp;amp;&lt;/span&gt;buf&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; BUFSZ&lt;span style="color:#ffffff"&gt;) !=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;0&lt;/span&gt;&lt;span style="color:#ffffff"&gt;) {&lt;/span&gt;&lt;br /&gt;        bp &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; buf&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;        dir &lt;span style="color:#ffffff"&gt;= (&lt;/span&gt;&lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; dirent &lt;span style="color:#ffffff"&gt;*)&lt;/span&gt; buf&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color:#b26818"&gt;do&lt;/span&gt; &lt;span style="color:#ffffff"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color:#b26818"&gt;if&lt;/span&gt; &lt;span style="color:#ffffff"&gt;(&lt;/span&gt;dir&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;d_reclen &lt;span style="color:#ffffff"&gt;!=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;0&lt;/span&gt;&lt;span style="color:#ffffff"&gt;) {&lt;/span&gt;&lt;br /&gt;                &lt;span style="color:#ffffff"&gt;stat&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;dir&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;d_name&lt;span style="color:#ffffff"&gt;, &amp;amp;&lt;/span&gt;st&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;                ftime &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;ctime&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&amp;amp;&lt;/span&gt;st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_mtime&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;                ftime&lt;span style="color:#ffffff"&gt;[&lt;/span&gt;&lt;span style="color:#ff0000"&gt;16&lt;/span&gt;&lt;span style="color:#ffffff"&gt;] =&lt;/span&gt; &lt;span style="color:#ff0000"&gt;'\0'&lt;/span&gt;&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;                ftime &lt;span style="color:#ffffff"&gt;+=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;4&lt;/span&gt;&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;                pw &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;getpwuid&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_uid&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;                grp &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;getgrgid&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_gid&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;                &lt;span style="color:#ffffff"&gt;perms&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_mode&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;                &lt;span style="color:#ffffff"&gt;printf&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;quot;%3d %-8s %-7s %9d %s %s&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;\n&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#ffffff"&gt;,&lt;/span&gt;&lt;br /&gt;                       st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_nlink&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; pw&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;pw_name&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; grp&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;gr_name&lt;span style="color:#ffffff"&gt;,&lt;/span&gt;&lt;br /&gt;                       st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_size&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; ftime&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; dir&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;d_name&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;            &lt;span style="color:#ffffff"&gt;}&lt;/span&gt;&lt;br /&gt;            bp &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; bp &lt;span style="color:#ffffff"&gt;+&lt;/span&gt; dir&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;d_reclen&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;            dir &lt;span style="color:#ffffff"&gt;= (&lt;/span&gt;&lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; dirent &lt;span style="color:#ffffff"&gt;*) (&lt;/span&gt;bp&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;        &lt;span style="color:#ffffff"&gt;}&lt;/span&gt; &lt;span style="color:#b26818"&gt;while&lt;/span&gt; &lt;span style="color:#ffffff"&gt;(&lt;/span&gt;dir&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;d_ino &lt;span style="color:#ffffff"&gt;!=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;0&lt;/span&gt;&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;        &lt;span style="color:#ffffff"&gt;bzero&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;buf&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; BUFSZ&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#ffffff"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ffffff"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;Here is what I get when I try to compile it on my machine:&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-size:80%;"&gt;kermit@fastbox ~/cprogs/fs $ gcc -Wall -o pate_ls pate_ls.c&lt;br /&gt;pate_ls.c:3:24: error: sys/dirent.h: No such file or directory&lt;br /&gt;pate_ls.c:14: warning: return type defaults to ‘int’&lt;br /&gt;pate_ls.c: In function ‘main’:&lt;br /&gt;pate_ls.c:23: warning: implicit declaration of function ‘bzero’&lt;br /&gt;pate_ls.c:23: warning: incompatible implicit declaration of built-in function ‘bzero’&lt;br /&gt;pate_ls.c:24: warning: implicit declaration of function ‘getdents’&lt;br /&gt;pate_ls.c:24: warning: suggest parentheses around assignment used as truth value&lt;br /&gt;pate_ls.c:28: error: dereferencing pointer to incomplete type&lt;br /&gt;pate_ls.c:29: error: dereferencing pointer to incomplete type&lt;br /&gt;pate_ls.c:30: warning: implicit declaration of function ‘ctime’&lt;br /&gt;pate_ls.c:30: warning: assignment makes pointer from integer without a cast&lt;br /&gt;pate_ls.c:35: warning: implicit declaration of function ‘perms’&lt;br /&gt;pate_ls.c:36: warning: implicit declaration of function ‘printf’&lt;br /&gt;pate_ls.c:36: warning: incompatible implicit declaration of built-in function ‘printf’&lt;br /&gt;pate_ls.c:38: error: dereferencing pointer to incomplete type&lt;br /&gt;pate_ls.c:38: warning: format ‘%3d’ expects type ‘int’, but argument 2 has type ‘__nlink_t’&lt;br /&gt;pate_ls.c:38: warning: format ‘%9d’ expects type ‘int’, but argument 5 has type ‘__off_t’&lt;br /&gt;pate_ls.c:40: error: dereferencing pointer to incomplete type&lt;br /&gt;pate_ls.c:42: error: dereferencing pointer to incomplete type&lt;br /&gt;pate_ls.c:20: warning: unused variable ‘fd’&lt;br /&gt;pate_ls.c:45: warning: control reaches end of non-void function&lt;br /&gt;kermit@fastbox ~/cprogs/fs/tmp $&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;That's a lot to look at!  What we need to do is make some changes, so that the code will compile cleanly.  Before dealing with the errors and warnings though, we will first look at the only 'major' change to the code, which will have a bonus side effect of eliminating some of the other problems.  What we are going to do, is get rid of the call to getdents.  If you look at your man page for getdents, you will notice the following:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;"This is not the function you are interested in. Look at readdir(3) for the POSIX conforming C library interface. This page documents the bare kernel system call interface."&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;I am not sure if getdents was &lt;span style="font-style: italic;"&gt;ever&lt;/span&gt; able to be used under Linux, such as is demonstrated above, but it certainly is not &lt;span style="font-style: italic;"&gt;now&lt;/span&gt;.  Instead, if we want to read a directory, we can use the readdir system call.  Furthermore, instead of using the open system call on a directory, we can use the opendir system call that is provided under Linux.  By using readdir, we can get rid of a few variables, notably the buf array, which also eliminates the need for the call to bzero.  (Incidentally, if you read the man page for bzero, you will notice that it is being deprecated in favour of the memset function).  Let's have a look at the original code again, with some comments annotating some of the problems with regards to building it under Linux:&lt;br /&gt;&lt;pre style="color:#ffffff; font-size:10pt; font-family:'Courier New';"&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;sys/types.h&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;sys/stat.h&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;sys/dirent.h&amp;gt;&lt;/span&gt;         &lt;span style="color:#0000ff"&gt;/* Does not exist under some  &lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff"&gt;                                 * (all?) Linux distributions&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff"&gt;                                 */&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;sys/unistd.h&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;fcntl.h&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;unistd.h&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;errno.h&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;pwd.h&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;grp.h&amp;gt;&lt;/span&gt; &lt;br /&gt; &lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#define BUFSZ 1024&lt;/span&gt; &lt;br /&gt; &lt;br /&gt;&lt;span style="color:#ffffff"&gt;main&lt;/span&gt;&lt;span style="color:#ffffff"&gt;()&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#ffffff"&gt;{&lt;/span&gt;                               &lt;span style="color:#0000ff"&gt;/* Main returns an int */&lt;/span&gt; &lt;br /&gt;    &lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; dirent &lt;span style="color:#ffffff"&gt;*&lt;/span&gt;dir&lt;span style="color:#ffffff"&gt;;&lt;/span&gt; &lt;br /&gt;    &lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; stat st&lt;span style="color:#ffffff"&gt;;&lt;/span&gt; &lt;br /&gt;    &lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; passwd &lt;span style="color:#ffffff"&gt;*&lt;/span&gt;pw&lt;span style="color:#ffffff"&gt;;&lt;/span&gt; &lt;br /&gt;    &lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; group &lt;span style="color:#ffffff"&gt;*&lt;/span&gt;grp&lt;span style="color:#ffffff"&gt;;&lt;/span&gt; &lt;br /&gt;    &lt;span style="color:#00ff00"&gt;char&lt;/span&gt; buf&lt;span style="color:#ffffff"&gt;[&lt;/span&gt;BUFSZ&lt;span style="color:#ffffff"&gt;], *&lt;/span&gt;bp&lt;span style="color:#ffffff"&gt;, *&lt;/span&gt;ftime&lt;span style="color:#ffffff"&gt;;&lt;/span&gt; &lt;br /&gt;    &lt;span style="color:#00ff00"&gt;int&lt;/span&gt; dfd&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; fd&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; nread&lt;span style="color:#ffffff"&gt;;&lt;/span&gt; &lt;br /&gt; &lt;br /&gt;    dfd &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;open&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;quot;.&amp;quot;&lt;/span&gt;&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; O_RDONLY&lt;span style="color:#ffffff"&gt;);&lt;/span&gt; &lt;br /&gt;    &lt;span style="color:#ffffff"&gt;bzero&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;buf&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; BUFSZ&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;          &lt;span style="color:#0000ff"&gt;/* #include &amp;lt;strings.h&amp;gt; for bzero,&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff"&gt;                                 * but we don't need to use&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff"&gt;                                 * bzero (or memset) if we use&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff"&gt;                                 * readdir instead of getdents&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff"&gt;                                 */&lt;/span&gt; &lt;br /&gt;    &lt;span style="color:#b26818"&gt;while&lt;/span&gt; &lt;span style="color:#ffffff"&gt;(&lt;/span&gt;nread &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;getdents&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;dfd&lt;span style="color:#ffffff"&gt;, (&lt;/span&gt;&lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; dirent &lt;span style="color:#ffffff"&gt;*) &amp;amp;&lt;/span&gt;buf&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; BUFSZ&lt;span style="color:#ffffff"&gt;) !=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;0&lt;/span&gt;&lt;span style="color:#ffffff"&gt;) {&lt;/span&gt; &lt;br /&gt;        &lt;span style="color:#0000ff"&gt;/* We can use readdir instead&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff"&gt;         * of getdents.  Example will&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff"&gt;         * follow later.&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff"&gt;         */&lt;/span&gt; &lt;br /&gt;        bp &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; buf&lt;span style="color:#ffffff"&gt;;&lt;/span&gt; &lt;br /&gt;        dir &lt;span style="color:#ffffff"&gt;= (&lt;/span&gt;&lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; dirent &lt;span style="color:#ffffff"&gt;*)&lt;/span&gt; buf&lt;span style="color:#ffffff"&gt;;&lt;/span&gt; &lt;br /&gt;        &lt;span style="color:#b26818"&gt;do&lt;/span&gt; &lt;span style="color:#ffffff"&gt;{&lt;/span&gt; &lt;br /&gt;            &lt;span style="color:#b26818"&gt;if&lt;/span&gt; &lt;span style="color:#ffffff"&gt;(&lt;/span&gt;dir&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;d_reclen &lt;span style="color:#ffffff"&gt;!=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;0&lt;/span&gt;&lt;span style="color:#ffffff"&gt;) {&lt;/span&gt; &lt;br /&gt;                &lt;span style="color:#ffffff"&gt;stat&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;dir&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;d_name&lt;span style="color:#ffffff"&gt;, &amp;amp;&lt;/span&gt;st&lt;span style="color:#ffffff"&gt;);&lt;/span&gt; &lt;br /&gt;                ftime &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;ctime&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&amp;amp;&lt;/span&gt;st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_mtime&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;    &lt;span style="color:#0000ff"&gt;/* #include &amp;lt;time.h&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff"&gt;                                                 * for ctime() &lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff"&gt;                                                 */&lt;/span&gt; &lt;br /&gt;                ftime&lt;span style="color:#ffffff"&gt;[&lt;/span&gt;&lt;span style="color:#ff0000"&gt;16&lt;/span&gt;&lt;span style="color:#ffffff"&gt;] =&lt;/span&gt; &lt;span style="color:#ff0000"&gt;'\0'&lt;/span&gt;&lt;span style="color:#ffffff"&gt;;&lt;/span&gt; &lt;br /&gt;                ftime &lt;span style="color:#ffffff"&gt;+=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;4&lt;/span&gt;&lt;span style="color:#ffffff"&gt;;&lt;/span&gt; &lt;br /&gt;                pw &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;getpwuid&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_uid&lt;span style="color:#ffffff"&gt;);&lt;/span&gt; &lt;br /&gt;                grp &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;getgrgid&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_gid&lt;span style="color:#ffffff"&gt;);&lt;/span&gt; &lt;br /&gt;                &lt;span style="color:#ffffff"&gt;perms&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_mode&lt;span style="color:#ffffff"&gt;);&lt;/span&gt; &lt;br /&gt;                &lt;span style="color:#ffffff"&gt;printf&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;quot;%3d %-8s %-7s %9d %s %s&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;\n&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; &lt;br /&gt;                       &lt;span style="color:#0000ff"&gt;/* #include &amp;lt;stdio.h&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff"&gt;                        * for printf() &lt;/span&gt; &lt;br /&gt;&lt;span style="color:#0000ff"&gt;                        */&lt;/span&gt; &lt;br /&gt;                       st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_nlink&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; pw&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;pw_name&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; grp&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;gr_name&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; &lt;br /&gt;                       st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_size&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; ftime&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; dir&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;d_name&lt;span style="color:#ffffff"&gt;);&lt;/span&gt; &lt;br /&gt;            &lt;span style="color:#ffffff"&gt;}&lt;/span&gt; &lt;br /&gt;            bp &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; bp &lt;span style="color:#ffffff"&gt;+&lt;/span&gt; dir&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;d_reclen&lt;span style="color:#ffffff"&gt;;&lt;/span&gt; &lt;br /&gt;            dir &lt;span style="color:#ffffff"&gt;= (&lt;/span&gt;&lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; dirent &lt;span style="color:#ffffff"&gt;*) (&lt;/span&gt;bp&lt;span style="color:#ffffff"&gt;);&lt;/span&gt; &lt;br /&gt;        &lt;span style="color:#ffffff"&gt;}&lt;/span&gt; &lt;span style="color:#b26818"&gt;while&lt;/span&gt; &lt;span style="color:#ffffff"&gt;(&lt;/span&gt;dir&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;d_ino &lt;span style="color:#ffffff"&gt;!=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;0&lt;/span&gt;&lt;span style="color:#ffffff"&gt;);&lt;/span&gt; &lt;br /&gt;        &lt;span style="color:#ffffff"&gt;bzero&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;buf&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; BUFSZ&lt;span style="color:#ffffff"&gt;);&lt;/span&gt; &lt;br /&gt;    &lt;span style="color:#ffffff"&gt;}&lt;/span&gt; &lt;br /&gt;    &lt;span style="color:#0000ff"&gt;/* Should return something, as main returns an int */&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#ffffff"&gt;}&lt;/span&gt; &lt;br /&gt;&lt;/pre&gt;And finally, have a look at what the new program, with the changes, looks like:&lt;br /&gt;&lt;pre style="color:#ffffff; font-size:10pt; font-family:'Courier New';"&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;sys/types.h&amp;gt;&lt;/span&gt;          &lt;span style="color:#0000ff"&gt;/* opendir, stat, closedir */&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;dirent.h&amp;gt;&lt;/span&gt;             &lt;span style="color:#0000ff"&gt;/* opendir, readdir, closedir */&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;errno.h&amp;gt;&lt;/span&gt;              &lt;span style="color:#0000ff"&gt;/* perror */&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/span&gt;             &lt;span style="color:#0000ff"&gt;/* exit */&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;sys/stat.h&amp;gt;&lt;/span&gt;           &lt;span style="color:#0000ff"&gt;/* stat */&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;unistd.h&amp;gt;&lt;/span&gt;             &lt;span style="color:#0000ff"&gt;/* stat */&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;time.h&amp;gt;&lt;/span&gt;               &lt;span style="color:#0000ff"&gt;/* ctime */&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;pwd.h&amp;gt;&lt;/span&gt;                &lt;span style="color:#0000ff"&gt;/* getpwuid */&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;grp.h&amp;gt;&lt;/span&gt;                &lt;span style="color:#0000ff"&gt;/* getgrgid */&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff22ff"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;              &lt;span style="color:#0000ff"&gt;/* printf */&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#00ff00"&gt;int&lt;/span&gt; &lt;span style="color:#ffffff"&gt;main&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;&lt;span style="color:#00ff00"&gt;void&lt;/span&gt;&lt;span style="color:#ffffff"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ffffff"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#00ff00"&gt;DIR&lt;/span&gt; &lt;span style="color:#ffffff"&gt;*&lt;/span&gt;dp&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; dirent &lt;span style="color:#ffffff"&gt;*&lt;/span&gt;dirp&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; stat st&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; passwd &lt;span style="color:#ffffff"&gt;*&lt;/span&gt;pw&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#00ff00"&gt;struct&lt;/span&gt; group &lt;span style="color:#ffffff"&gt;*&lt;/span&gt;grp&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#00ff00"&gt;char&lt;/span&gt; &lt;span style="color:#ffffff"&gt;*&lt;/span&gt;ftime&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:#b26818"&gt;if&lt;/span&gt; &lt;span style="color:#ffffff"&gt;((&lt;/span&gt;dp &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;opendir&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;quot;.&amp;quot;&lt;/span&gt;&lt;span style="color:#ffffff"&gt;)) ==&lt;/span&gt; NULL&lt;span style="color:#ffffff"&gt;) {&lt;/span&gt;&lt;br /&gt;        &lt;span style="color:#ffffff"&gt;printf&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;quot;Cannot open this directory&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;\n&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;        &lt;span style="color:#ffffff"&gt;perror&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;quot;opendir&amp;quot;&lt;/span&gt;&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;        &lt;span style="color:#ffffff"&gt;exit&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;EXIT_FAILURE&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#ffffff"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:#b26818"&gt;while&lt;/span&gt; &lt;span style="color:#ffffff"&gt;((&lt;/span&gt;dirp &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;readdir&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;dp&lt;span style="color:#ffffff"&gt;)) !=&lt;/span&gt; NULL&lt;span style="color:#ffffff"&gt;) {&lt;/span&gt;&lt;br /&gt;        &lt;span style="color:#b26818"&gt;if&lt;/span&gt; &lt;span style="color:#ffffff"&gt;(&lt;/span&gt;dirp&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;d_reclen &lt;span style="color:#ffffff"&gt;!=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;0&lt;/span&gt;&lt;span style="color:#ffffff"&gt;) {&lt;/span&gt;&lt;br /&gt;            &lt;span style="color:#ffffff"&gt;stat&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;dirp&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;d_name&lt;span style="color:#ffffff"&gt;, &amp;amp;&lt;/span&gt;st&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;            ftime &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;ctime&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&amp;amp;&lt;/span&gt;st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_mtime&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;            ftime&lt;span style="color:#ffffff"&gt;[&lt;/span&gt;&lt;span style="color:#ff0000"&gt;16&lt;/span&gt;&lt;span style="color:#ffffff"&gt;] =&lt;/span&gt; &lt;span style="color:#ff0000"&gt;'\0'&lt;/span&gt;&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;            ftime &lt;span style="color:#ffffff"&gt;+=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;4&lt;/span&gt;&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;            pw &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;getpwuid&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_uid&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;            grp &lt;span style="color:#ffffff"&gt;=&lt;/span&gt; &lt;span style="color:#ffffff"&gt;getgrgid&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_gid&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;            &lt;span style="color:#ffffff"&gt;printf&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;quot;%3zu %-8s %-7s %9zu %s %s&lt;/span&gt;&lt;span style="color:#ff22ff"&gt;\n&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#ffffff"&gt;,&lt;/span&gt;&lt;br /&gt;                   st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_nlink&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; pw&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;pw_name&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; grp&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;gr_name&lt;span style="color:#ffffff"&gt;,&lt;/span&gt;&lt;br /&gt;                   st&lt;span style="color:#ffffff"&gt;.&lt;/span&gt;st_size&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; ftime&lt;span style="color:#ffffff"&gt;,&lt;/span&gt; dirp&lt;span style="color:#ffffff"&gt;-&amp;gt;&lt;/span&gt;d_name&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;        &lt;span style="color:#ffffff"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#ffffff"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:#ffffff"&gt;closedir&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;dp&lt;span style="color:#ffffff"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:#b26818"&gt;return&lt;/span&gt; &lt;span style="color:#ff0000"&gt;0&lt;/span&gt;&lt;span style="color:#ffffff"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ffffff"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;It compiles cleanly on my system (kernel 2.6.27, gcc 4.1.2).  Note that this implementation is very 'bare bones.'  It lists everything in the directory where it is executed (provided the directory permission settings allows it to do so).  This includes 'hidden' dot files (.somefile), as well as the current directory, dot (.), and the parent directory, dot-dot (..).  Now that you have a working version of the program, I would encourage you to experiment with it, and do the other exercises such as making it accept user input so as to be able to perform long and short listings (and even the -a option to show hidden files) etc.  Finally, I have included a diff of the two files, in order to give an idea of what has been changed:&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-size:80%;"&gt;1,9c1,10&lt;br /&gt;&lt; #include &amp;lt;sys/types.h&amp;gt; &lt;br /&gt;&lt; #include &amp;lt;sys/stat.h&amp;gt; &lt;br /&gt;&lt; #include &amp;lt;sys/dirent.h&amp;gt; &lt;br /&gt;&lt; #include &amp;lt;sys/unistd.h&amp;gt; &lt;br /&gt;&lt; #include &amp;lt;fcntl.h&amp;gt; &lt;br /&gt;&lt; #include &amp;lt;unistd.h&amp;gt; &lt;br /&gt;&lt; #include &amp;lt;errno.h&amp;gt; &lt;br /&gt;&lt; #include &amp;lt;pwd.h&amp;gt; &lt;br /&gt;&lt; #include &amp;lt;grp.h&amp;gt; &lt;br /&gt;--- &lt;br /&gt;&gt; #include &amp;lt;sys/types.h&amp;gt;         /* opendir, stat, closedir */&lt;br /&gt;&gt; #include &amp;lt;dirent.h&amp;gt;            /* opendir, readdir, closedir */&lt;br /&gt;&gt; #include &amp;lt;errno.h&amp;gt;             /* perror */&lt;br /&gt;&gt; #include &amp;lt;stdlib.h&amp;gt;            /* exit */&lt;br /&gt;&gt; #include &amp;lt;sys/stat.h&amp;gt;          /* stat */&lt;br /&gt;&gt; #include &amp;lt;unistd.h&amp;gt;            /* stat */&lt;br /&gt;&gt; #include &amp;lt;time.h&amp;gt;              /* ctime */&lt;br /&gt;&gt; #include &amp;lt;pwd.h&amp;gt;               /* getpwuid */&lt;br /&gt;&gt; #include &amp;lt;grp.h&amp;gt;               /* getgrgid */&lt;br /&gt;&gt; #include &amp;lt;stdio.h&amp;gt;             /* printf */&lt;br /&gt;---&lt;br /&gt;&lt; #define BUFSZ 1024&lt;br /&gt;---&lt;br /&gt;13c14&lt;br /&gt;&lt; main()&lt;br /&gt;---&lt;br /&gt;&gt; int main(void)&lt;br /&gt;15c16,17&lt;br /&gt;&lt;     struct dirent *dir;&lt;br /&gt;---&lt;br /&gt;&gt;     DIR *dp;&lt;br /&gt;&gt;     struct dirent *dirp;&lt;br /&gt;19,20c21&lt;br /&gt;&lt;     char buf[BUFSZ], *bp, *ftime;&lt;br /&gt;&lt;     int dfd, fd, nread;&lt;br /&gt;---&lt;br /&gt;&gt;     char *ftime;&lt;br /&gt;22,43c23,26&lt;br /&gt;&lt;     dfd = open(".", O_RDONLY);&lt;br /&gt;&lt;     bzero(buf, BUFSZ);&lt;br /&gt;&lt;     while (nread = getdents(dfd, (struct dirent *) &amp;buf, BUFSZ) != 0) {&lt;br /&gt;&lt;         bp = buf;&lt;br /&gt;&lt;         dir = (struct dirent *) buf;&lt;br /&gt;&lt;         do {&lt;br /&gt;&lt;             if (dir-&gt;d_reclen != 0) {&lt;br /&gt;&lt;                 stat(dir-&gt;d_name, &amp;st);&lt;br /&gt;&lt;                 ftime = ctime(&amp;st.st_mtime);&lt;br /&gt;&lt;                 ftime[16] = '\0';&lt;br /&gt;&lt;                 ftime += 4;&lt;br /&gt;&lt;                 pw = getpwuid(st.st_uid);&lt;br /&gt;&lt;                 grp = getgrgid(st.st_gid);&lt;br /&gt;&lt;                 perms(st.st_mode);&lt;br /&gt;&lt;                 printf("%3d %-8s %-7s %9d %s %s\n",&lt;br /&gt;&lt;                        st.st_nlink, pw-&gt;pw_name, grp-&gt;gr_name,&lt;br /&gt;&lt;                        st.st_size, ftime, dir-&gt;d_name);&lt;br /&gt;&lt;             }&lt;br /&gt;&lt;             bp = bp + dir-&gt;d_reclen;&lt;br /&gt;&lt;             dir = (struct dirent *) (bp);&lt;br /&gt;&lt;         } while (dir-&gt;d_ino != 0);&lt;br /&gt;&lt;         bzero(buf, BUFSZ);&lt;br /&gt;---&lt;br /&gt;&gt;     if ((dp = opendir(".")) == NULL) {&lt;br /&gt;&gt;         printf("Cannot open this directory\n");&lt;br /&gt;&gt;         perror("opendir");&lt;br /&gt;&gt;         exit(EXIT_FAILURE);&lt;br /&gt;44a28,44&lt;br /&gt;&gt;&lt;br /&gt;&gt;     while ((dirp = readdir(dp)) != NULL) {&lt;br /&gt;&gt;         if (dirp-&gt;d_reclen != 0) {&lt;br /&gt;&gt;             stat(dirp-&gt;d_name, &amp;st);&lt;br /&gt;&gt;             ftime = ctime(&amp;st.st_mtime);&lt;br /&gt;&gt;             ftime[16] = '\0';&lt;br /&gt;&gt;             ftime += 4;&lt;br /&gt;&gt;             pw = getpwuid(st.st_uid);&lt;br /&gt;&gt;             grp = getgrgid(st.st_gid);&lt;br /&gt;&gt;             printf("%3zu %-8s %-7s %9zu %s %s\n",&lt;br /&gt;&gt;                    st.st_nlink, pw-&gt;pw_name, grp-&gt;gr_name,&lt;br /&gt;&gt;                    st.st_size, ftime, dirp-&gt;d_name);&lt;br /&gt;&gt;         }&lt;br /&gt;&gt;     }&lt;br /&gt;&gt;&lt;br /&gt;&gt;     closedir(dp);&lt;br /&gt;&gt;     return 0;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259080474015777403-4926377027774260150?l=totally-out-of-ideas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://totally-out-of-ideas.blogspot.com/feeds/4926377027774260150/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/02/getting-simple-directory-listing-in.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/4926377027774260150'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259080474015777403/posts/default/4926377027774260150'/><link rel='alternate' type='text/html' href='http://totally-out-of-ideas.blogspot.com/2009/02/getting-simple-directory-listing-in.html' title='Getting a simple directory listing in Linux'/><author><name>University-Bound</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
