{"id":5,"date":"2008-02-28T23:41:19","date_gmt":"2008-02-28T23:41:19","guid":{"rendered":"http:\/\/vgable.com\/blog\/2008\/02\/28\/useful-macosx-terminal-commands\/"},"modified":"2009-03-23T05:17:05","modified_gmt":"2009-03-23T10:17:05","slug":"useful-macosx-terminal-commands","status":"publish","type":"post","link":"https:\/\/vgable.com\/blog\/2008\/02\/28\/useful-macosx-terminal-commands\/","title":{"rendered":"Useful MacOSX Terminal Commands"},"content":{"rendered":"<p>Here are some OS X specific terminal commands that I have found useful, and you might not be aware of.  Running <code>man command<\/code> in the Terminal will give you more information about <code>command<\/code> as it is on your system.<\/p>\n<p><b><a href=\"http:\/\/www.hmug.org\/man\/2\/open.php\">open<\/a><\/b><br \/>\nopen file will open file the same way it would have been opened if you double-clicked it in the Finder.  You can also specify what program to use to open the file.<\/p>\n<p><b><a href=\"http:\/\/www.hmug.org\/man\/1\/pbcopy.php\">pbcopy, pbpaste<\/a><\/b><br \/>\nBridges the clipboard and the command line; you can pipe the clipboard into stdout, or pipe stdout into the clipboard.<\/p>\n<p><b><a href=\"http:\/\/www.hmug.org\/man\/1\/ps.php\">ps -axww<\/a><\/b><br \/>\nLists every process running on the system, and gives the full-path to them, and their PSN.  I almost never use any other arguments to ps.<\/p>\n<p><b><a href=\"http:\/\/www.hmug.org\/man\/1\/osascript.php\">osascript<\/a><\/b><br \/>\nExecute an AppleScript. osascript -e &#8220;code-goes-here&#8221;, will execute the AppleScript inside the &#8220;&#8221;. This is a great way to get AppleScript functionality in a good scripting language.<\/p>\n<p><b><a href=\"http:\/\/www.hmug.org\/man\/1\/ditto.php\">ditto<\/a><\/b><br \/>\nCan do the work of <a href=\"http:\/\/www.hmug.org\/man\/1\/cp.php\">cp<\/a> or <a href=\"http:\/\/www.hmug.org\/man\/1\/zip.php\">zip<\/a>, but it does the right thing on OS X, and won&#8217;t throw away Mac-specific bits.<br \/>\n<code>ditto -ckX --rsrc --keepParent path_to_a_bundledFile.bundle bundledFile.bundle.zip<\/code> will compress <code>path_to_a_bundledFile.bundle<\/code>, and keep all the Mac-bits intact.<\/p>\n<p><b><a href=\"http:\/\/www.hmug.org\/man\/1\/hdiutil.php\">hdiutil<\/a><\/b><br \/>\nCreate and manipulate disk-images; you can even use it to burn a disk-image to CD\/DVD.<br \/>\nInside a perl-script I do:<code><br \/>\nhdiutil create -ov -fs HFS+ -format UDBZ -volname \\&#8221;IMLocation v$version (beta)\\&#8221; -srcfolder $IMLBuildDir ~\/Projects\/Website\/imlocation\/IMLocation.dmg<\/code><br \/>\nTo  make the disk-image for <a href=\"http:\/\/vgable.com\/imlocation\/\">IMLocation<\/a> out of the contents of the directory $IMLBuildDir.<\/p>\n<p><b><a href=\"http:\/\/www.hmug.org\/man\/1\/screencapture.php\">screencapture<\/a><\/b><br \/>\nLets you take a screenshot.  Unfortunately not very well documented.<br \/>\n<code>screencapture -x \/tmp\/screen.png<\/code><br \/>\nWill <i>silently<\/i> take a screenshot, and save it to \/tmp\/screen.png.<br \/>\nI think this could be great for bug-reporting.<\/p>\n<p><b><a href=\"http:\/\/www.hmug.org\/man\/8\/system_profiler.php\">system_profiler<\/a><\/b><br \/>\nReports system hardware and software configuration; with no arguments it reports everything.  Obviously great for bug reports and research.<\/p>\n<p><b><a href=\"http:\/\/developer.apple.com\/DOCUMENTATION\/Darwin\/Reference\/ManPages\/man1\/sw_vers.1.html\">sw_vers<\/a><\/b><br \/>\nPrints version information about the Mac OS X.<code><br \/>\n$ sw_vers<br \/>\nProductName:\tMac OS X<br \/>\nProductVersion:\t10.5<br \/>\nBuildVersion:\t9A581<br \/>\n$ sw_vers -productName<br \/>\nMac OS X<br \/>\n$ sw_vers -productVersion<br \/>\n10.5<br \/>\n$ sw_vers -buildVersion<br \/>\n9A581<\/code><\/p>\n<p><b><a href=\"http:\/\/developer.apple.com\/documentation\/Darwin\/Reference\/ManPages\/man8\/systemsetup.8.html\">systemsetup<\/a><\/b><br \/>\nConfiguration tool for certain machine settings in System Preferences.<\/p>\n<p><b><a href=\"http:\/\/www.hmug.org\/man\/1\/defaults.php\">defaults<\/a><\/b><br \/>\nRead and write application preferences.  You can use it to discover and activate hidden settings, like <a href=\"http:\/\/www.macosxhints.com\/article.php?story=20030110063041629\">Safari&#8217;s Debug menu<\/a>. <code>defaults read &gt; all_defaults.txt<\/code>  will give you a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Grep\">grep-able<\/a> text-file with every default on your system.  It&#8217;s also a useful tool for automated testing, since you can twiddle configurations.<\/p>\n<p><b><a href=\"http:\/\/www.codethecode.com\/Projects\/class-dump\/download.html\">class-dump<\/a><\/b> (3rd party tool)<br \/>\nMakes .h files from a binary.  Great for reverse-engineering.<\/p>\n<p>In addition to standard UNIX commands, Mac OS X includes many powerful command-line tools.  This article only scratches the surface, and ignores many tools like <a href=\"http:\/\/developer.apple.com\/documentation\/Darwin\/Reference\/ManPages\/man1\/podcast.1.html\">podcast<\/a> that are probably very useful, but aren&#8217;t part of my workflow.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here are some OS X specific terminal commands that I have found useful, and you might not be aware of. Running man command in the Terminal will give you more information about command as it is on your system. open open file will open file the same way it would have been opened if you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,10,9],"tags":[167,86,236],"class_list":["post-5","post","type-post","status-publish","format-standard","hentry","category-macosx","category-tips","category-unix","tag-apple","tag-command-line","tag-terminal"],"_links":{"self":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/5","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/comments?post=5"}],"version-history":[{"count":0,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/5\/revisions"}],"wp:attachment":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/media?parent=5"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/categories?post=5"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/tags?post=5"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}