58
votes

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

8
  • agreed, this site seems to be far more negative that stackoverflow, people seem poised to 'down' any post they don't think meets their standards - it's enough to make me walk away. Commented May 12, 2009 at 13:15
  • thx, chopper3. maybe it was voted down for being mac related. i can understand not wanting to see a lot of apple stuff, but really just add /ignore "mac" to your tags, and it's sorted Commented May 12, 2009 at 13:23
  • 2
    there's loads of apple specific stuff on this site, people here just seem to enjoy being negative. Commented May 12, 2009 at 13:29
  • 2
    to be expected i suppose... we are sysadmins :-) Commented May 12, 2009 at 13:32
  • 1
    I like your username...username :) Commented May 12, 2009 at 13:35

55 Answers 55

28
votes
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.

1
  • 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 :-) Commented Aug 11, 2009 at 14:57
23
votes

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:

19
votes
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.

2
17
votes
open . 

Opens a finder window in the current working directory.

3
  • for launching other apps, use something like: open -a "activity monitor" Commented May 13, 2009 at 9:24
  • Freunde schöner Götterfunke...I mean, thank you, thank you, thank you!! I was looking for a Windows like "start ." and this is it! Commented May 19, 2009 at 11:09
  • 'open filename' acts the same as double-clicking on a file in the Finder -- it'll launch the associated application and open the file. Commented May 25, 2009 at 18:44
13
votes

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 
0
12
votes

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.

1
  • 1
    Cool. Eg: /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I Shows you detailed information on signal quality, noise, security, and other WiFi network attributes. Commented May 12, 2009 at 13:30
11
votes
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

2
  • 4
    Of course, if you're used to Linux, 'ifconfig en0' works just as well. Commented May 14, 2009 at 11:38
  • Or use en1 if you're on wireless. Commented Feb 7, 2011 at 18:39
11
votes
drutil tray open 

Invaluable (over ssh) when there's no keyboard connected since the eject button on Apple optical drives isn't accessible from outside the case.

11
votes

It can't be said enough, "open" is great. You can open documents in their GUI program and you can select the GUI program with -a as well. For example,

open -a vlc movie.avi 

will open VLC and tell it to load movie.avi in your current dir.

open movie.avi 

would open it with whatever program is the default. If you just want to open a program, you can do that too:

open -a system\ preferences 

will run System Preferences. You can open Urls too:

open vnc://myserver:5900 

will open Screen Sharing and connect to myserver.

Check out

man open 

to see all flags you can use.

10
votes
softwareupdate 

Update your mac from the CLI.

9
votes
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.

8
votes
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.

8
votes
dscacheutil -flushcache 

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

3
  • Of note, this only works in Mac OS X 10.5 Commented Oct 7, 2009 at 23:08
  • I just checked, it also works on 10.6. Commented Oct 9, 2009 at 0:53
  • Upvoted as I find myself having to run this more often than not, however don't remember having to flush the Linux or Windows DNS cache. Perhaps OS X is particularly aggressive at DNS caching? Commented Dec 31, 2009 at 23:42
7
votes
ping 224.0.0.1 

Ping all devices on your subnet

7
votes
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 
7
votes
srm 

Command line version for secure delete.

7
votes
 lsof 

list open files

Handy when you want to eject your USB drive and are told that it is in use and to please quit all applications and try again.

$ sudo lsof /Volumes/CLINTON COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 55966 clinton cwd DIR 14,12 16384 2 /Volumes/CLINTON lsof 56042 root cwd DIR 14,12 16384 2 /Volumes/CLINTON lsof 56043 root cwd DIR 14,12 16384 2 /Volumes/CLINTON 

In this instance, I had cded onto the drive and so bash was accessing the volume.

Note that if you see 'mds' entries, it means that spotlight is indexing the drive.

7
votes

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

6
votes

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.

6
votes
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.

5
votes
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.

5
votes
sw_vers 

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

4
votes
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.

4
votes
ifconfig en0 ether 00:00:00:00:00:00 

Changes (spoofs) MAC address until next reboot

1
  • I came across this a few days ago here: krypted.com/mac-os-x/… - handy for testing your DHCP service settings Commented May 19, 2009 at 2:31
4
votes
df -h 

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

4
votes
dns-sd -B _ssh dns-sd -B _rfb dns-sd -B _services._dns-sd._udp 

List servers advertising in Bonjour. The last suggestion lists the types of service that you can list. The listing is live, hit Ctrl-C when you've seen enough.

The same command comes in recent Linuxes and in the Bonjour SDK for Windows.

4
votes
opendiff file1 file2 

Runs FileMerge (a graphical diff that comes with Apple Developer Tools) on file1 and file2.

4
votes
sudo opensnoop 

in Leopard and newer, reports which processes open files, whether successfully or not. You can ask it to look at all files being opened across the system, by a specific process, or if any process is opening a given file, with different sorts of timestamps, and to show if errors occur.

Here are some more details:

opensnoop is a dtrace script; there are many others in /usr/bin that look at things like which system calls a process is making, what processes it is creating and what I/O it is doing. Run apropos DTrace for a list, and look at man pages for details.


I found out about opensnoop when struggling to diagnose why a Comic Life Magiq 1.1 was crashing on OS 10.5.8 for users with network accounts.

I ran (several times, on different accounts, via ssh):

sudo opensnoop -e -n Comic > output.txt 

The last file opened by network users was something like this (with a full path):

/Network/Servers/.../username/Library/Icons/WebpageIcons.db 

which reminded me that Safari 5.0 was crashing for network users, and we worked around it by either managing a preference to not cache favicons or by redirecting a file. Apple apparently fixed the issue in Safari 5.0.1, and when I upgraded to Safari 5.0.2 yesterday, it fixed the crash for Comic Life Magiq users.

3
votes
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

3
votes
drutil eject 

will eject a CD.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.