<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>leftcolumn.net &#187; terminal</title>
	<atom:link href="http://www.leftcolumn.net/tags/terminal/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.leftcolumn.net</link>
	<description>Covering Mac OS X, Mac Software, and other stuff</description>
	<lastBuildDate>Tue, 29 Nov 2011 04:30:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>/etc/hosts file on Mac OSX</title>
		<link>http://www.leftcolumn.net/2011/11/29/etchosts-file-on-mac-osx/</link>
		<comments>http://www.leftcolumn.net/2011/11/29/etchosts-file-on-mac-osx/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 04:28:09 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[mac osx]]></category>
		<category><![CDATA[hosts]]></category>
		<category><![CDATA[mac system admin]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.leftcolumn.net/?p=237</guid>
		<description><![CDATA[I just put this together to cover a question I was asked recently. Might be useful to someone&#8230; Where is the /etc/hosts file in Mac OS X? The hosts file used by Mac OS X is in /etc/. Windows users sometimes have problems finding it since there&#8217;s no %SystemRoot%\system32\drivers\etc folder in the Mac OS. UNIX [...]]]></description>
			<content:encoded><![CDATA[<p><em>I just put this together to cover a question I was asked recently. Might be useful to someone&#8230;</em></p>
<h3>Where is the /etc/hosts file in Mac OS X?</h3>
<p>The hosts file used by Mac OS X is in /etc/. Windows users sometimes have problems finding it since there&#8217;s no %SystemRoot%\system32\drivers\etc folder in the Mac OS. UNIX users might not expect /etc/ to be hidden by the Mac OS X Finder, so they often look in /Library/Application Support/</p>
<h3>Accessing /etc/hosts</h3>
<p>/etc/ is hidden by default. The easiest way of getting to the hosts file is to open /Applications/Utilities/Terminal.app. Then type:<br />
<code>sudo nano /etc/hosts</code></p>
<p>&#8230;you will need to type in your password. Your hots file will open in the text editor &#8216;nano.&#8217;</p>
<h3>Adding entries to /etc/hosts</h3>
<p>On a new line type the IP Address followed by at least one space or tab and then the hostname. Examples:<br />
<code>127.0.0.1 mydevsite.local<br />
192.168.1.222 ads.shadycompany.biz</code></p>
<p>&#8230;hit ctrl + o to Save, and then ctrl + x to quit the text editor.</p>
<p>See here for more about using /etc/hosts for Virtual Servers: <a href="http://www.leftcolumn.net/2009/07/04/adding-an-entry-to-etchosts-on-os-x/" title="Adding an entry to /etc/hosts on OS X">Adding an entry to /etc/hosts on OS X</a></p>
<h3>Background: What is /etc/hosts used for?</h3>
<p>The hosts file is a simple way of mapping IP Addresses to hostnames. It overrides mappings provided by the Domain Name System network. The hosts file is commonly used by network administrators to provide access to LAN resources when no name resolution is available. The other common usage is to block access to specified hosts by adding host entries resolving them to &#8212; for example &#8212; 127.0.0.1.<br />
More Resources:<br />
<a title="Hosts File" href="http://en.wikipedia.org/wiki/Hosts_(file)">http://en.wikipedia.org/wiki/Hosts_(file)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.leftcolumn.net/2011/11/29/etchosts-file-on-mac-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two Nifty Terminal History Tricks</title>
		<link>http://www.leftcolumn.net/2010/05/12/nifty-terminal-history-trick/</link>
		<comments>http://www.leftcolumn.net/2010/05/12/nifty-terminal-history-trick/#comments</comments>
		<pubDate>Tue, 11 May 2010 12:39:51 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[mac osx]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.leftcolumn.net/?p=226</guid>
		<description><![CDATA[I&#8217;ve covered the &#8216;history&#8217; command before, but here are two more useful Mac OS X Terminal commands&#8230; I&#8217;ve been using the Ctrl+ R trick (Hit Ctrl + R, start typing part of the command you want. If you don&#8217;t like the first suggestion hit Ctrl + R again to show the next one). This is [...]]]></description>
			<content:encoded><![CDATA[<p><strong>I&#8217;ve covered the <a href="http://www.leftcolumn.net/2009/02/15/40-useful-mac-os-x-shell-scripts-and-terminal-commands/">&#8216;history&#8217; command</a> before, but here are two more useful Mac OS X Terminal commands&#8230;</strong></p>
<p>I&#8217;ve been using the Ctrl+ R trick (Hit Ctrl + R, start typing part of the command you want. If you don&#8217;t like the first suggestion hit Ctrl + R again to show the next one). This is really handy and fast and it will return matches from the middle of the string.</p>
<p>And I just found another great Terminal command here: <a href="http://osxdaily.com/2010/05/10/discover-the-last-used-command-beginning-with-anything-without-executing-it/">Discover the last used command beginning with anything without executing it</a>&#8230; this one is a bit harder to use:</p>
<p><code>![needle]:p</code></p>
<p>&#8230;where [needle] is the first character(s) of the command you&#8217;re looking for. It&#8217;s not as flexible because it only shows the most recent match instead of cycling through the results, but could still come in handy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leftcolumn.net/2010/05/12/nifty-terminal-history-trick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding an entry to /etc/hosts on OS X</title>
		<link>http://www.leftcolumn.net/2009/07/04/adding-an-entry-to-etchosts-on-os-x/</link>
		<comments>http://www.leftcolumn.net/2009/07/04/adding-an-entry-to-etchosts-on-os-x/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 23:31:53 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[mac osx]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[hosts]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.leftcolumn.net/?p=216</guid>
		<description><![CDATA[Web Developers, Administrators of Mac Networks, and anyone who likes to noodle with OS X will probably eventually need to add hosts file entries. I use them when I&#8217;m testing a moved and/or changed version of a website at new hosting before I move the DNS. I used to add hosts file entries manually then [...]]]></description>
			<content:encoded><![CDATA[<p>Web Developers, Administrators of Mac Networks, and anyone who likes to noodle with OS X will probably eventually need to add hosts file entries. I use them when I&#8217;m testing a moved and/or changed version of a website at new hosting before I move the DNS.</p>
<p>I used to add hosts file entries manually then wonder why they didn&#8217;t seem to work. I tried rebooting, logging out, etc with varying success, until I learned this trick. On the Mac you must flush the DNS cache for the changes to take effect. Mac OS X used to have a friendly utility called NetInfo Manager, but that seems to have been removed in Leopard, so we&#8217;re using terminal commands.</p>
<p>Open a terminal sesion and type:<br />
<code>sudo nano /etc/hosts</code></p>
<p>Hit the down arrow until you get to the end of the file, and add your hosts file entry, for example:<br />
<code>192.168.2.33 myintranetserver.mydomain.com</code><br />
&#8230; I put in an extra line break at the end. I don&#8217;t think it&#8217;s really necessary but it&#8217;s a habit from having to use Windows, which would ignore the last line in a hosts file. </p>
<p>then flush the cache:<br />
<code>sudo dscacheutil -flushcache</code></p>
<p>&#8230;the name should now resolve! Test it:<br />
<code>ping myintranetserver.mydomain.com</code></p>
<h3>Other Info</h3>
<p>One thing that Windows, for all its annoyances, did get right is that changes to the hosts file (in &#8216;c:\Windows\system32\drivers\etc&#8217;) are reflected immediately. I&#8217;d like to see Apple do something about this in OS X, perhaps just flushing the cache automatically when /etc/hosts changes.</p>
<p>Another handy use for /etc/hosts is to set up mapping of virtual server addresses. For example, I use MAMP on my development Mac, and create new virtual hosts entries in Apache for each site I&#8217;m working on. Then for each I just add a new entry in the hosts file, e.g.:<br />
<code>127.0.0.1 devclientsite7.leftcolumn.net</code><br />
&#8230; then I just use devclientsite7.leftcolumn.net:8080 in Safari or Firefox to access the development site. It means my development sites don&#8217;t have to be in subdirectories, instead I just make sure the sites use a config file to figure out what their address is, and I make sure that config file is updated when the site is moved to a live system.</p>
<p>On OS X Tiger (10.4) and probably earlier, there was some strange behaviour with hosts file entries. You could add an entry and it would take effect, but if you had no network available, the name would not resolve and could not be used, even if it resolved to 127.0.0.1! So you have the bizarre situation of putting in addresses for virtual hosts as described in the previous paragraph, all of which resolve to 127.0.0.1, but still not being able to use them for testing and development when not connected to the Internet. If anyone can enlighten me as to how this was anything other than a bug in OS X I&#8217;d be interested&#8230;</p>
<p>You can also use hosts file entries to block ads (by resolving common ad server addresses to e.g.: 127.0.0.1). You can download huge lists of ad servers for this purpose. This is a good idea when you&#8217;re stuck using  Internet Explorer on Windows, especially on dial-up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leftcolumn.net/2009/07/04/adding-an-entry-to-etchosts-on-os-x/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>MacBook Pro won&#8217;t wake up from sleep</title>
		<link>http://www.leftcolumn.net/2009/05/24/macbook-pro-wont-wake-up-from-sleep/</link>
		<comments>http://www.leftcolumn.net/2009/05/24/macbook-pro-wont-wake-up-from-sleep/#comments</comments>
		<pubDate>Sun, 24 May 2009 00:31:47 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[mac osx]]></category>
		<category><![CDATA[macbook pro]]></category>
		<category><![CDATA[system]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.leftcolumn.net/?p=205</guid>
		<description><![CDATA[One day my new MacBook Pro 17&#8243; wouldn&#8217;t wake up. When I opened the lid machine was running but the Desktop wouldn&#8217;t load (just a default blue Desktop background colour) and there was no response from the Mouse or Keyboard. I eventually had to hard reset the Mac. This annoying issue can apparently be caused [...]]]></description>
			<content:encoded><![CDATA[<p>One day my new MacBook Pro 17&#8243; wouldn&#8217;t wake up. When I opened the lid machine was running but the Desktop wouldn&#8217;t load (just a default blue Desktop background colour) and there was no response from the Mouse or Keyboard. I eventually had to hard reset the Mac. </p>
<p>This annoying issue can apparently be caused a few different ways, but if your Mac is new and has all System Updates applied, chances are that the issue is caused when you close the lid and then move the mac before the contents of RAM are written out. There&#8217;s a feature called Safe Sleep, enabled by default, which can preserve and restore the state of a sleeping Mac even when the battery is removed. This sounds great, but the Safe Sleep procedure can take up to 30 seconds, which is too long for me.</p>
<p>How to fix this annoying problem? Here&#8217;s how I switched it off:</p>
<pre>sudo pmset -a hibernatemode 0
sudo rm /var/vm/sleepimage
</pre>
<p>&#8230;you need to supply the super user password. After making the change, reboot the Mac. The Mac should now Sleep within a couple of seconds. The second line removes the file that Sleep Safe uses to store the contents of RAM. Since you&#8217;ve switched off Safe Sleep, the space can be recovered.</p>
<p>Personally I don&#8217;t see the need for Safe Sleep on a Mac with a non-removable battery, but be aware that if the machine is asleep and runs out of battery power you wil lose your logged in session! I haven&#8217;t tried it, and most OS X apps will deal pretty well with this anyway, but it&#8217;s not wise to let this happen&#8230;</p>
<p>More details:</p>
<p><a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/pmset.1.html">Apple pmset Manual</a><br />
<a href="http://www.macworld.com/article/53471/2006/10/sleepmode.html">Macworld article on setting sleep modes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.leftcolumn.net/2009/05/24/macbook-pro-wont-wake-up-from-sleep/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>40 Useful Mac OS X Shell Scripts and Terminal Commands</title>
		<link>http://www.leftcolumn.net/2009/02/15/40-useful-mac-os-x-shell-scripts-and-terminal-commands/</link>
		<comments>http://www.leftcolumn.net/2009/02/15/40-useful-mac-os-x-shell-scripts-and-terminal-commands/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 10:51:16 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[mac osx]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.leftcolumn.net/?p=71</guid>
		<description><![CDATA[Here are a bunch of Mac OS X terminal commands sorted into general categories. I have intentionally omitted long bash scripts and AppleScripts and focussed instead on small useful commands that can be plugged into bigger scripts or used on their own&#8230; enjoy! System Restart Mac OS X: shutdown - r now Shutdown Mac OS [...]]]></description>
			<content:encoded><![CDATA[<p>Here are a bunch of Mac OS X terminal commands sorted into general categories. I have intentionally omitted long bash scripts and AppleScripts and focussed instead on small useful commands that can be plugged into bigger scripts or used on their own&#8230; enjoy!</p>
<h3>System</h3>
<p>Restart Mac OS X:</p>
<pre>shutdown - r now</pre>
<p>Shutdown Mac OS X:</p>
<pre>shutdown now</pre>
<h3>Power Management / Energy Saving</h3>
<p>Get overview of current Power Management Settings:</p>
<pre>pmset -g</pre>
<p>Put display to sleep after 15 minutes of inactivity:</p>
<pre>sudo pmset displaysleep 15</pre>
<p>Put Computer to sleep after 30 minutes of inactivity:</p>
<pre>sudo pmset sleep 30</pre>
<p>&#8230;Also see my post about <a href="http://www.leftcolumn.net/2009/05/24/macbook-pro-wont-wake-up-from-sleep/" title="hibernate mode and Safe Sleep on the Mac">hibernate mode and Safe Sleep on the Mac</a></p>
<h3>OS X Look and Feel</h3>
<p><a href="http://www.macosxhints.com/article.php?story=20090105064613347">Permanently disable Dock icon bouncing</a></p>
<p>Disable Dashboard (don&#8217;t forget to drag the Dashboard Dock icon off the Dock too):</p>
<pre>defaults write com.apple.dashboard mcx-disabled -boolean YES
killall Dock</pre>
<p>Enable Dashboard:</p>
<pre>defaults write com.apple.dashboard mcx-disabled -boolean NO
killall Dock</pre>
<p>Force the Finder to show hidden files (very useful for Web Developers who need to edit .htaccess files, for example):</p>
<pre>defaults write com.apple.finder AppleShowAllFiles TRUE</pre>
<p>Force the Finder to hide hidden files (ie: back to the default setting):</p>
<pre>defaults write com.apple.finder AppleShowAllFiles FALSE</pre>
<h3>Networking</h3>
<p>Ping a host to see whether it&#8217;s available:</p>
<pre>ping -o leftcolumn.net</pre>
<p>Troubleshoot routing problems to a host using traceroute:</p>
<pre>traceroute leftcolumn.net</pre>
<p>Check whether a host is running an HTTP server (ie: check that a Web Site is available):</p>
<pre>curl -I www.leftcolumn.net | head -n 1</pre>
<p><a href="http://www.macosxhints.com/article.php?story=20080217065538984">Automatically enable Internet Sharing at startup</a></p>
<p>Manage Windows networks (a drop-in for the NET command on Windows). Too many options to list here, so run this for details:</p>
<pre>man net</pre>
<p>Use dig to discover Domain information:</p>
<pre>dig www.leftcolumn.net A
dig www.leftcolumn.net MX</pre>
<p>Who is logged in to your Mac?</p>
<pre>w</pre>
<p>Show routing table:</p>
<pre>netstat -r</pre>
<p>Show active network connections:</p>
<pre>netstat -an</pre>
<p>Show network statistics:</p>
<pre>netstat -s</pre>
<h3>Troubleshooting</h3>
<p>List all open files (this will take a few seconds to complete on most Macs):</p>
<pre>lsof</pre>
<p>Restart Bonjour &#8211; handy when a Mac &#8216;disappears&#8217; from the Network:</p>
<pre>sudo launchctl unload /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
sudo launchctl load /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist</pre>
<p>Eject a CD&#8230; it&#8217;s never happened to me but you can eject a stuck cd with the following. Note that it won&#8217;t always be &#8216;disk1&#8242;:</p>
<pre>diskutil eject disk1</pre>
<h3>Text Manipulation commands</h3>
<p><em>Sometimes you need to take some text from the clipboard or a file, transform it somehow and then use it. Here are a bunch of commands that do text manipulation. I&#8217;ve assumed you want to transform text from the clipboard and back again, see the notes at the end of the article for info on how to write to and from files instead.</em></p>
<p>Count number of lines in the text in the Clipboard:</p>
<pre>pbpaste | wc -l</pre>
<p>Count number of words in the text in the Clipboard:</p>
<pre>pbpaste | wc -w</pre>
<p>Sort lines of text in the Clipboard and copy them back to the Clipboard:</p>
<pre>pbpaste | sort | pbcopy</pre>
<p>Reverse each line of text in the Clipboard (ie: make each line appear backwards) and copy them back to the Clipboard:</p>
<pre>pbpaste | rev | pbcopy</pre>
<p>Strip duplicate lines from lines of text in the Clipboard and copy only one instance of each duplicate line back to the Clipboard (output is sorted):</p>
<pre>pbpaste | sort | uniq | pbcopy</pre>
<p>Find duplicate lines from lines of text in the Clipboard and copy only one instance of each duplicate line (stripping non-duplicates) back to the Clipboard (output is sorted):</p>
<pre>pbpaste | sort | uniq -d | pbcopy</pre>
<p>Strip duplicate lines from lines of text in the Clipboard and copy only one instance of each line (stripping duplicates entirely) back to the Clipboard (output is sorted):</p>
<pre>pbpaste | sort | uniq -u | pbcopy</pre>
<p>Tidy up HTML in the Clipboard and copy it back to the Clipboard:</p>
<pre>pbpaste | tidy | pbcopy</pre>
<p>Display the first 5 lines from the Clipboard:</p>
<pre>pbpaste | head -n 5</pre>
<p>Display the last 5 lines from the Clipboard:</p>
<pre>pbpaste | tail -n 5</pre>
<p>Convert tabs to spaces for the lines in the Clipboard:</p>
<pre>pbpaste | expand | pbcopy</pre>
<h3>Other useful commands</h3>
<p>Password protect your web site! Create a CRYPTed user/password for using in a .htpasswd file. Save the <strong>outputted results</strong> of <strong>A</strong> below to a file called .htpasswd in the directory you want to secure. Then save the <strong>contents</strong> of <strong>B</strong> to a file called .htaccess in the same folder.</p>
<h4>A:</h4>
<pre>htpasswd -nb username password</pre>
<h4>B:</h4>
<pre>AuthType Basic
AuthName "restricted area"
AuthUserFile /path/to/your/site/.htpasswd
require valid-user</pre>
<p>Display a history of commands used in the terminal by the current user:</p>
<pre>history</pre>
<p>Convert a file to HTML. Support formats are Text, .RTF, .DOC.</p>
<pre>textutil -convert html file.extension</pre>
<p>Nano is a very easy-to-use text editor for quick changes to text files. It is less powerful than VIM but has the advantage of clearly showing you the common editing commands:</p>
<pre>nano [file_to_edit]</pre>
<p>&#8230;In nano, use ctrl+o to Save and ctrl+x to quit.</p>
<p>Greg shared a way of tidying the terminal window. Essentially this command scrolls down a page, clearing the current view:</p>
<pre>clear</pre>
<h3>iTunes</h3>
<p>Change iTunes link behaviour to point at local iTunes Library instead of iTunes Store:</p>
<pre>defaults write com.apple.iTunes invertStoreLinks -bool YES</pre>
<p>Change iTunes link behaviour to point at iTunes Store instead of local iTunes Library (ie: back to the default):</p>
<pre>defaults write com.apple.iTunes invertStoreLinks -bool NO</pre>
<h3>Other Mac OS X Terminal Resources</h3>
<p><a href="http://www.kernelthread.com/mac/osx/tools.html">Mac OS X Hacking Tools</a> (old but detailed list for the obsessive only).</p>
<p><a href="http://hayne.net/MacDev/Bash/">Cameron Hayne&#8217;s Bash Scripts</a></p>
<p><a href="http://www.macosxhints.com/">Mac OS X Hints</a></p>
<p><a href="http://discussions.apple.com/">Apple Forums</a></p>
<p>Note: For commands where I&#8217;ve used pbcopy to get the contents of the Clipboard as input, you can use the contents of a file as input instead. Swap <em>pbpaste</em> for:</p>
<pre>cat [/path/to/filename]</pre>
<p>And to put the results into a file on your desktop, just swap <em>| pbcopy</em> for:</p>
<pre>&gt; ~/Desktop/filename.txt</pre>
<p>&#8230; hope you find them useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leftcolumn.net/2009/02/15/40-useful-mac-os-x-shell-scripts-and-terminal-commands/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
	</channel>
</rss>

