Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Per the Windows and Linux threads, what commands do you find most useful in Mac OS X Server (or Client)?

there's loads of apple specific stuff on this site, people here just seem to enjoy being negative. –  Chopper3 May 12 '09 at 13:29
to be expected i suppose... we are sysadmins :-) –  username May 12 '09 at 13:32
I like your username...username :) –  Chopper3 May 12 '09 at 13:35
show 5 more comments

locked by Mark Henderson Jun 27 '12 at 4:44

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

55 Answers

Truly Mac only: I saw 'open .' above, but open will open any document or app you pass to it.

Generic Unix that I use the most: sudo is pretty handy for changing system config files, etc, which I actually edit in vi.

kill can't be overstated when something hangs (or when another user is still logged into my desktop in the background and I want to log them out, nasty I know but it's my desktop)

ssh/scp - I love that in OSX I can just open a terminal and connect to any of our servers. That alone made me happy to drop Windows.

ifconfig/ping/whois/nmap etc

Well, open is not so truly Mac only... On Windows this command is named start (based on the file extension for files, though internet addresses are supported as well). –  Arjan Aug 11 '09 at 15:04
show 2 more comments

If you want to know what sort of line endings a file has, just run

file /path/to/your-file


$ file imports/sample-students.txt 
imports/sample-students.txt: ASCII text, with CR line terminators
add comment

scutil --dns

Will display the order for DNS resolution. Useful for when you're creating or debugging your Network settings.

add comment
lsof -i 

lists Internet ports that are open. Sample output:

SystemUIS   223 clinton   11u  IPv4 0x3e21b08      0t0  UDP *:*
ARDAgent    262 clinton   16u  IPv4 0x3e21be0      0t0  UDP *:net-assistant
ARDAgent    262 clinton   18u  IPv4 0x5f01a68      0t0  TCP *:net-assistant (LISTEN)
AppleVNCS   263 clinton    4u  IPv6 0x3e274bc      0t0  TCP *:vnc-server (LISTEN)
Opera     48365 clinton   20u  IPv4 0x5f01e64      0t0  TCP WTD-Staff-BlackmoreC:57094->stackoverflow.com:http (ESTABLISHED)
Opera     48365 clinton   23u  IPv4 0x5b12a68      0t0  TCP WTD-Staff-BlackmoreC:57095->stackoverflow.com:http (ESTABLISHED)

Use sudo if you want the ports open by all users, and the flags -n and -P will disable name resolution and port names and give you numbers instead.

add comment
ifconfig | grep cast

is great for getting your IP address, and

ifconfig en1 | grep eth

works well for getting a MAC address.  Using en1 will (almost always) get the Airport's MAC address, which is handy if only known devices are allowed onto your wireless network.  Conversely, if you use en0 -- the built-in ethernet port -- you can then look the machine up in your Open Directory, like so:

ldapsearch -x -h odm -b "cn=computers,dc=odm,dc=pretendoco,dc=com" "macAddress=00:0d:93:b5:82:88"

(Assuming your server was 'odm' and the realm is ODM.PRETENDCO.COM).

add comment

ipconfig is sometimes useful:

Getting current IP address on interface:

$ ipconfig getifaddr en1

Getting the DHCP information that was last received:

$ ipconfig getpacket en1
htype = 1
flags = 0
hlen = 6
hops = 0
xid = 143857879
secs = 0
ciaddr =
yiaddr =
siaddr =
giaddr =
chaddr = 00:aa:bb:cc:dd:ee
sname = 
file = 
Options count is 7
dhcp_message_type (uint8): ACK 0x5
server_identifier (ip):
lease_time (uint32): 0xe10
router (ip_mult): {}
domain_name_server (ip_mult): {,}
subnet_mask (ip):
end (none):
add comment

This question overlaps quite a bit with this one about tools a UNIX administrator cannot live without. Many of the command-line tools for Mac OS X have UNIX roots, such as df, du, and which; however there are notable exceptions that have no obvious UNIX equivalents, such as osascript, open, pbcopy, pbpaste, and say.

add comment

How to enable Time Machine to backup to a NAS.

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

Find MAC address

ifconfig en0 | grep ether | sed s/://g | sed s/ether//

Command to create sparsebundle to copy over to NAS

sudo hdiutil create -nospotlight -library SPUD -size 160g -fs "Case-sensitive Journaled HFS+" -type SPARSEBUNDLE -volname "<VOLNAME>" ./<HOSTNAME>_<MAC_ADDRESS>.sparsebundle

Works like charm backing up to my ReadyNAS.

add comment

It is a freeware third-party tool, but


is really handy. It is a command-line tool that you can optionally install the first time you run TextWrangler. [Other text editors (BBEdit, TextMate) likely provide something analogous.]

edit path/to/somefile

Opens up the file in TextWrangler, and will let you authenticate if you don't normally have permission to edit it. (You can even do it from an ssh session, and it'll open it for the logged-in graphical user).

Better still is that you can pipe things to it.

lsof -i | edit

for example, will show you your open network connections and open them up in TextWrangler, where you can search (and scroll) through them easily.

There is a similar Textmate version called "mate" which is installed with the editor. –  bjtitus Jul 5 '09 at 23:32
add comment

Gain a root shell without enabling the root user (as Apple itself requires sometimes in their docs in order to do some "geeky" stuff, ie to set system-wide language)

sudo bash

This gives you a root shell where you can do everything you want as root, without having to prepend every command with the sudo command.

This may be dangerous, but we are sysadmins, we know what we are doing, don't we? :)

I prefer "sudo -s", it's shorter and I think it may do some specific processing to start the shell "properly". –  w00t Aug 18 '09 at 0:22
show 1 more comment

killall -9 appname force quits an app. Pretty useful if you can't get into Activity Monitor.

add comment

Apart from the usual Unix suspects I find the following useful :-

  • dsconfigad - Edits the Active Directory settings and binds a computer

  • defaults - Edit preferences

  • plutil - Converts plist to and from text

  • softwareupdate - run Software Update from the command-line

  • installer - install packages from the command-line

  • networksetup - set and get various things such as the computer name

If you master those and the usual Unix stuff you have all you need for Mac administration from the command-line.

add comment

I just found out that there's a nifty bash construct that you can use instead of the seq command missing in Mac OS:

echo { 18..21 }
show 1 more comment

A bit pedestrian for this audience, no doubt, but I use:

screencapture -i -c

to grab whatever I want from the screen It's really handy and does things that Grab won't allow me to grab.

add comment

du -d 1 -h

Displays disk usage statistics for the current directory in human readable form.

man [command]

One of the most used commands. Tells you how to use everything else.

add comment
sudo slapconfig -destroyldapserver

Force Demote an LDAP Replica to Standalone. If your Open Directory Master is misconfigured, sometimes trying to demote an Open Directory Replica using Server Admin will fail (eg: you might find your Replica server refuses to demote). You can use slapconfig to force it to demote on these occasions.

add comment
 which program

searched the path for program, and tells you which executable is invoked if you run program without specifying a full path.

It is usually most useful as a shorthand for typing a path.

$ which python
$ ls -l `which python`
lrwxr-xr-x  1 root  wheel  72 30 Jan 22:56 /usr/bin/python -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python
show 2 more comments
sqlite3 foo.db

Starts an interactive SQLite session. If foo.db does not exist, it will be created.

add comment

These are basic, but handy if you have amnesia:

Who am I?


Where am I standing?


What building am I?


What's its address?

ifconfig |grep inet
add comment

OS X specific things I haven't seen mentioned:

mdfind uses the Spotlight search indexes from the commandline, so you can do full-text searches without using the Search pulldown.

networksetup - will show you all the crazy syntax it supports; this is the commandline equivalent of the Network preference pane.

sudo launchctl list - shows the running launchctl jobs. remember launchctl stop X.XX.X will just 'stop' (kill) the currently running instance of a persistent process; to really make it stop running use launchctl unload /System/Library/LaunchDaemons/X.XX.X.plist.

add comment

What DHCP licenses does the client hold?

sudo ls -lt /private/var/db/dhcpclient/leases

List the firewall allow/denies:

sudo ipfw list

Generate a high-entropy password (double click on a promising 16 character string to copy/paste):

head -c90 /dev/random | uuencode -m pwd | hexdump -C
add comment

Ever wanted to know what the IP address of another Mac that you can see is in the Finder is on your LAN thanks to Bonjour?

dscacheutil -q host -a name OtherMac.local

dscacheutil is surprisingly useful and versatile. You can do a lot more with it than just flush the DNS cache (as mentioned elsewhere here), i.e. user lookups and cache stats and dumps.

add comment
locate "foo"

Displays any file on your system with "foo" in its filename. I must use this almost as often as I use Spotlight.

mdfind will query spotlight from the command line. See tuaw.com/2008/01/04/… –  Clinton Blackmore May 29 '09 at 15:30
add comment
 sudo reboot

reboots the computer.

add comment

Maybe not the most "useful" command but say is pretty fun.

For example say I love serverfault to have it read back what you type after "say."

add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.