<?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; reference</title>
	<atom:link href="http://www.leftcolumn.net/tags/reference/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, 11 May 2010 12:51:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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 X:
shutdown now
Power Management / [...]]]></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>
<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>11</slash:comments>
		</item>
	</channel>
</rss>
