OS X Command Line Utilities

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.

This is a mere list of commands with a short description and one or two examples. To find out more of course use man command.

Commands may destroy all your data or cause a nuclear meltdown — use only if you know what you are doing.

Configuration and networking

systemsetup

– Manage a variety of configuration stuff.

sudo systemsetup -getdate # view system date systemsetup -getcomputername # display computer name
softwareupdate

– Execute Apple Software update from the commandline

softwareupdate -l # list available updates sudo softwareupdate -i -a # install all available updates
networksetup

– Manage the network configuration

sudo networksetup -listallhardwareports # list all network interfaces with MAC addresses sudo networksetup -switchtolocation home # switch network locations
dscl

– Directory service management, for example users, groups etc. – complex stuff, mostly for use on OSX server

dscl localhost -list /Local/Default/Users # list all local users
dscacheutil

– Manage DNS cache

dscacheutil -flushcache # clear local DNS cache
system_profiler

– View system information (Like SystemProfiler.app in Utilities)

system_profiler # list lots of information

Files

chflags

– Change file flags, like “hidden”, “archived”..

ls -l0 # View flags in the current directory
/Developer/Tools/GetFileInfo

– View extended file attributes, like icon, creator and so on. To write these attributes use SetFileInfo

GetFileInfo any.txt # list the attributes

Disks and images

diskutil

– Manage local disks

diskutil list # list local drives and partitions sudo diskutil repairPermissions / # repair permissions
hdiutil

– Manage disk images

hdiutil burn animage.dmg # burn imagefile to cd/dvd hdiutil create -srcfolder path any.dmg # create dmg-image from folder
newfs_hfs

– Format a disk

# dangerous enough...
drutil

– Interact with CD/DVD drives

drutil eject # eject media drutil status # show detailed information about drives and media

Misc

open

– Open a file with a given application.

open example.txt # opens the file in the default text editor open . # opens a new finder window with the current commandline path
pbcopy/pbpaste

– Access OSX clipboard

ls | pbcopy # copy dir listing to clipboard
mdutil

– Manage Spotlight

mdutil -s / # show indexing status on root drive
screencapture

– Take a screenshot

screencapture ~/Desktop/scr.png # make a screenshot and save it to the given file
osascript

– Run Applescript from the shell

osascript -e 'tell app "Terminal" to close every window whose frontmost is true' # close all terminal windows sudo osascript -e "set Volume 0" # set system volume to zero
qlmanage

– Manage QuickLook

qlmanage -m # list QuickLook plugins and handlers
periodic

– Run periodic system jobs

sudo periodic daily # run daily stuff

Ressources

More in-depth information can be found here:

One Reply to “OS X Command Line Utilities”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.