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)?

share

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.

2  
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
2  
to be expected i suppose... we are sysadmins :-) –  username May 12 '09 at 13:32
1  
I like your username...username :) –  Chopper3 May 12 '09 at 13:35

55 Answers 55

sudo changeip -checkhostname

Checks that forward and reverse DNS resolution are healthy, and often shows you the command you can use to fix the problem. If it says "the names match, there is nothing to change" you're in good shape. Vital if you ever change your server's network configuration. Also important to use this before you promote your server to an Open Directory Master.

share
fs_usage

Lets you monitor file system activity. Handy if you want to see what files some app creates. See http://rentzsch.com/macosx/fs_usageIntro for more explanation.

share
ipconfig getpacket en0

Displays network configuration for the primary Ethernet interface (en0).

If you're used to Windows and think "ipconfig" is broken - it's not ;-) You just need to add a couple arguments

share
4  
Of course, if you're used to Linux, 'ifconfig en0' works just as well. –  Tim May 14 '09 at 11:38

The 'airport' CLI utility is my favorite. See http://osxdaily.com/2007/01/18/airport-the-little-known-command-line-wireless-utility/. It will show you details like the signal level, noise level, and the BSSID of the AP you're associated to.

share
1  
Cool. Eg: /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resource‌​s/airport -I Shows you detailed information on signal quality, noise, security, and other WiFi network attributes. –  username May 12 '09 at 13:30
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -restart -agent

Starts the Remote Desktop service (useful if you only have SSH access but want to do something using the GUI on your client Mac). For more options, see: http://support.apple.com/kb/HT2370

share
sqlite3 foo.db

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

share

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.

share
networksetup

Configure everything you find in the Network Preference Pane in System Preferences on the command line. Makes writing scripts, or doing things remotely much easier.

share
osascript -e 'tell application "AppName" to quit'

Lets you quit an application from the shell.

osascript -e 'tell application "Finder" to sleep'

Useful last line of a long shell script, puts Mac to sleep when script is done. I have it aliased to iSleep.

pbpaste | script.sh |pbcopy

takes contents of pasteboard (edit->copy) and pipes it to script.sh. The results are put onto the pasteboard for you to edit->paste into a document.

share
open .

Opens a finder window in the current working directory.

share
ping 224.0.0.1

Ping all devices on your subnet

share
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.

share
dscacheutil -flushcache

I find myself using that one heaps to flush the DNS cache, on 10.5+.

share
say "some text"

Famously used for getting people back into their apartments, say takes your arguments and reads them aloud through the audio output device.

share
4  
+1 for xkcd content –  username May 14 '09 at 12:27
4  
And it speaks very well -- see macosxhints.com/comment.php?mode=view&cid=107211 for a list of phrases such as My name is Dr. Smith and I live on Smith Dr., The soldier decided to desert his dessert in the desert and Since there is no time like the present, he thought it was time to present the present :-) –  Arjan Aug 11 '09 at 14:57
sw_vers

Displays the currently installed version and build of Mac OS X.

share
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).

share
system_profiler

Give you the same results as you get when you choose About This Mac -> More Info, only on the command line.

Running

system_profiler -usage

or looking at the man page will give you tips on how to use it.

A couple of examples:

system_profiler -xml > MySystem.spx
# and later,
open MySystem.spx  # or just double click on it in the Finder

this will dump the system profile to a file which can be looked at later on a different machine.

system_profiler SPUSBDataType

Tells you about all your USB devices (including their Vendor and Product IDs, which can aid in tracking down drivers).

system_profiler SPUSBDataType | grep "Product ID" -c

will tell you how many USB devices are plugged in (including internal USB devices), which is useful to see if the computer sees a device (or, if, say, Parallel's grabbed it or it is dead.) [Do note that in the System Profiler GUI App, you can choose View -> Refresh from the menu to update the list; that may just be easier.]

system_profiler SPHardwareDataType

will get you basic hardware info (useful for asset tracking), and

system_profiler SPHardwareDataType | grep Serial

will give you the machine's serial number.

share

The Command-Line Administration guide put out by Apple is invaluable.

Googling for "command line administration mac" gives good results.

Command-Line Administration for Mac OS X 10.5, 10.4, and 10.3.

Other useful guides are at http://www.apple.com/server/macosx/resources/.

share

http://www.commandlinefu.com

While not specifically a Mac resource, it is using the icon for the Terminal, and most of the list of really useful commands will work.

share
ifconfig en0 ether 00:00:00:00:00:00

Changes (spoofs) MAC address until next reboot

share

pbpaste and pbcopy to interact with the pasteboard (aka clipboard).

Examples:

# copies the directory listing
ls -l | pbcopy

# get pasteboard lines containing foo and save them in a_file
pbpaste | grep foo > a_file

I think they default to using the macroman encoding, so if you want UTF-8 (which you do) you should check out these links:

share
locate "foo"

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

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

this will let you see what sort of MCX (Managed Client) settings are being applied to a client machine.

[The GUI equivalent is to go to System Profiler, and, under the Software section, click on "Managed Client".]

It is useful to determine if a machine is managed and to see if it is getting the settings you expect.

share
drutil eject

will eject a CD.

share
last

shows who has logged into a system, how long they used it, and when the system has been restarted.

Here is a sample of the output:

clinton   ttys000                   Thu May 28 22:33   still logged in
clinton   console                   Thu May 28 08:05   still logged in
reboot    ~                         Thu May 28 08:05 
shutdown  ~                         Wed May 27 20:15 
clinton   console                   Wed May 27 17:33 - 20:15  (02:42)
...

wtmp begins Thu May 14 09:26
share
df -h

To check how many disk space I currently have on all the disk.

share

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

share
1  
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

From the command line, I like having the ability to:

Create and burn a "universal" CD/DVD:

$ mkisofs -allow-multidot -allow-leading-dots -d -hide-rr-moved \
-l -joliet-long -R -T -v \
-V VOLUME_NAME -o output.iso root-cd-dir/
$ hdiutil burn -noverifyburn output.iso

Create an ISO image from a CD/DVD:

$ diskutil unmountDisk /dev/disk2s0
$ dd if=/dev/disk2s0 of=cdname.iso bs=32m

Being able to forget the otool command when I'm seeking ldd:

$ alias ldd='printf "Sending command to \'\''otool -L\'\'' --\n" && otool -L'

Mount a disk image from the command line:

$ hdid diskimage.dmg (or .iso)

Use preview to access a man page:

$ man -t rsync | open -f -a /Applications/Preview.app
share
1  
+1 for the manpage / Preview hint. Awesome. –  Sam Halicke Oct 26 '09 at 8:35
softwareupdate

Update your mac from the CLI.

share
srm

Command line version for secure delete.

share

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