{"id":4294,"date":"2010-05-06T00:46:21","date_gmt":"2010-05-05T22:46:21","guid":{"rendered":"http:\/\/www.chipwreck.de\/blog\/?p=4294"},"modified":"2011-05-05T05:57:07","modified_gmt":"2011-05-05T03:57:07","slug":"os-x-command-line-utilities","status":"publish","type":"post","link":"https:\/\/www.chipwreck.de\/blog\/2010\/05\/06\/os-x-command-line-utilities\/","title":{"rendered":"OS X Command Line Utilities"},"content":{"rendered":"<p>What I love about OSX is its UNIX(-like) foundation. There are the default UNIX command line tools but also lots of OSX specific commands. This is a compilation of some of these commands you might not know. Feel free to comment.<!--more--><\/p>\n<p>This is a mere list of commands with a short description and one or two examples. To find out more of course use <q><kbd>man command<\/kbd><\/q>.<\/p>\n<p class=\"warning\" style=\"padding: 0.5em; margin-top: 0.5em; font-size: 0.72em !important;\">Commands may destroy all your data or cause a nuclear meltdown &mdash; use only if you know what you are doing.<\/p>\n<h2>Configuration and networking<\/h2>\n<h5><kbd>systemsetup<\/kbd><\/h5>\n<p>&#8211; Manage a variety of configuration stuff.<\/p>\n<p>\t<code lang=\"bash\">sudo systemsetup -getdate # view system date<br \/>\nsystemsetup -getcomputername # display computer name<\/code><\/p>\n<h5><kbd>softwareupdate<\/kbd><\/h5>\n<p>&#8211; Execute Apple Software update from the commandline<\/p>\n<p>\t<code lang=\"bash\">softwareupdate -l # list available updates<br \/>\nsudo softwareupdate -i -a # install all available updates<\/code><\/p>\n<h5><kbd>networksetup<\/kbd><\/h5>\n<p>&#8211; Manage the network configuration<\/p>\n<p>\t<code lang=\"bash\">sudo networksetup -listallhardwareports # list all network interfaces with MAC addresses<br \/>\nsudo networksetup -switchtolocation home # switch network locations<\/code><\/p>\n<h5><kbd>dscl<\/kbd><\/h5>\n<p>&#8211; Directory service management, for example users, groups etc. &#8211; complex stuff, mostly for use on OSX server<\/p>\n<p>\t<code lang=\"bash\">dscl localhost -list \/Local\/Default\/Users # list all local users<\/code><\/p>\n<h5><kbd>dscacheutil<\/kbd><\/h5>\n<p>&#8211; Manage DNS cache<\/p>\n<p>\t<code lang=\"bash\">dscacheutil -flushcache # clear local DNS cache<\/code>\t<\/p>\n<h5><kbd>system_profiler<\/kbd><\/h5>\n<p>&#8211; View system information (Like SystemProfiler.app in Utilities)<\/p>\n<p>\t<code lang=\"bash\">system_profiler # list lots of information<\/code>\t<\/p>\n<h2>Files<\/h2>\n<h5><kbd>chflags<\/kbd><\/h5>\n<p>&#8211; Change file flags, like &#8220;hidden&#8221;, &#8220;archived&#8221;..<\/p>\n<p>\t<code lang=\"bash\">ls -l0 # View flags in the current directory<\/code><\/p>\n<h5><kbd>\/Developer\/Tools\/GetFileInfo<\/kbd><\/h5>\n<p>&#8211; View extended file attributes, like icon, creator and so on. To write these attributes use SetFileInfo<\/p>\n<p>\t<code lang=\"bash\">GetFileInfo any.txt # list the attributes<\/code><\/p>\n<h2>Disks and images<\/h2>\n<h5><kbd>diskutil<\/kbd><\/h5>\n<p>&#8211; Manage local disks<\/p>\n<p>\t<code lang=\"bash\">diskutil list # list local drives and partitions<br \/>\nsudo diskutil repairPermissions \/ # repair permissions<\/code><\/p>\n<h5><kbd>hdiutil<\/kbd><\/h5>\n<p>&#8211; Manage disk images<\/p>\n<p>\t<code lang=\"bash\">hdiutil burn animage.dmg # burn imagefile to cd\/dvd<br \/>\nhdiutil create -srcfolder path any.dmg # create dmg-image from folder<\/code><\/p>\n<h5><kbd>newfs_hfs<\/kbd><\/h5>\n<p>&#8211; Format a disk<\/p>\n<p>\t<code lang=\"bash\"># dangerous enough...<\/code><\/p>\n<h5><kbd>drutil<\/kbd><\/h5>\n<p>&#8211; Interact with CD\/DVD drives<\/p>\n<p>\t<code lang=\"bash\">drutil eject # eject media<br \/>\ndrutil status # show detailed information about drives and media<\/code>\t<\/p>\n<h2>Misc<\/h2>\n<h5><kbd>open<\/kbd><\/h5>\n<p>&#8211; Open a file with a given application.<\/p>\n<p>\t<code lang=\"bash\">open example.txt # opens the file in the default text editor<br \/>\nopen . # opens a new finder window with the current commandline path<\/code><\/p>\n<h5><kbd>pbcopy\/pbpaste<\/kbd><\/h5>\n<p>&#8211; Access OSX clipboard<\/p>\n<p>\t<code lang=\"bash\">ls | pbcopy # copy dir listing to clipboard<\/code><\/p>\n<h5><kbd>mdutil<\/kbd><\/h5>\n<p>&#8211; Manage Spotlight<\/p>\n<p>\t<code lang=\"bash\">mdutil -s \/ # show indexing status on root drive<\/code><\/p>\n<h5><kbd>screencapture<\/kbd><\/h5>\n<p>&#8211; Take a screenshot<\/p>\n<p>\t<code lang=\"bash\">screencapture ~\/Desktop\/scr.png # make a screenshot and save it to the given file<\/code><\/p>\n<h5><kbd>osascript<\/kbd><\/h5>\n<p>&#8211; Run Applescript from the shell<\/p>\n<p>\t<code lang=\"bash\">osascript -e 'tell app \"Terminal\" to close every window whose frontmost is true' # close all terminal windows<br \/>\nsudo osascript -e \"set Volume 0\" # set system volume to zero<\/code>\t<\/p>\n<h5><kbd>qlmanage<\/kbd><\/h5>\n<p>&#8211; Manage QuickLook<\/p>\n<p>\t<code lang=\"bash\">qlmanage -m # list QuickLook plugins and handlers<\/code><\/p>\n<h5><kbd>periodic<\/kbd><\/h5>\n<p>&#8211; Run periodic system jobs<\/p>\n<p>\t<code lang=\"bash\">sudo periodic daily # run daily stuff<\/code><\/p>\n<h2>Ressources<\/h2>\n<p>More in-depth information can be found here:<\/p>\n<ul>\n<li><a class=\"external\" href=\"http:\/\/osxbook.com\/book\/bonus\/ancient\/whatismacosx\/tools.html\">Additional information to the OSX bible &#8220;Mac OSX Internals&#8221;<\/a><\/li>\n<li><a class=\"external\" href=\"http:\/\/osx.realmacmark.de\/index.php#toc\">MacMark: Very good information resource, in German<\/a><\/li>\n<li><a class=\"external\" href=\"http:\/\/images.apple.com\/server\/macosx\/docs\/Intro_Command_Line_Admin_v10.6.pdf\">Intro to command line administration &#8211; great resource from Apple (PDF)<\/a><\/li>\n<li><a class=\"external\" href=\"http:\/\/ss64.com\/osx\/\">A-Z list of OSX commands<\/a><\/li>\n<li><a class=\"external\" href=\"http:\/\/osxdaily.com\/category\/command-line\/\">OSX Daily &#8211; lots of tips<\/a><\/li>\n<li><a class=\"external\" href=\"http:\/\/www.leftcolumn.net\/2009\/02\/15\/40-useful-mac-os-x-shell-scripts-and-terminal-commands\/\">40 Useful Mac OS X Shell Scripts and Terminal Commands<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>What I love about OSX is its UNIX(-like) foundation. There are the default UNIX command line tools but also lots of OSX specific commands. This is a compilation of some of these commands you might not know. Feel free to comment.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[78,19,54],"class_list":["post-4294","post","type-post","status-publish","format-standard","hentry","category-osx","tag-osx","tag-software","tag-track"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paPEN-17g","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/posts\/4294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/comments?post=4294"}],"version-history":[{"count":0,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/posts\/4294\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/media?parent=4294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/categories?post=4294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/tags?post=4294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}