The owner or authorized user of a valid copy of
Mac OS X Server software may reproduce this
publication for the purpose of learning to use such
software. No part of this publication may be reproduced
or transmitted for commercial purposes, such as selling
copies of this publication or for providing paid-for
support services.
Every effort has been made to ensure that the
information in this manual is accurate. Apple Computer,
Inc., is not responsible for printing or clerical errors.
Apple
1 Infinite Loop
Cupertino CA 95014-2084
www.apple.com
The Apple logo is a trademark of Apple Computer, Inc.,
registered in the U.S. and other countries. Use of the
“keyboard” Apple logo (Option-Shift-K) for commercial
purposes without the prior written consent of Apple
may constitute trademark infringement and unfair
competition in violation of federal and state laws.
Apple, the Apple logo, AppleShare, AppleTalk, Mac,
Macintosh, QuickTime, Xgrid, and Xserve are trademarks
of Apple Computer, Inc., registered in the U.S. and other
countries. Finder is a trademark of Apple Computer, Inc.
Adobe and PostScript are trademarks of Adobe Systems
Incorporated.
UNIX is a registered trademark in the United States and
other countries, licensed exclusively through
X/Open Company, Ltd. Apache is a registered trademark
of the Apache Software Foundation, and is used with
permission.
Other company and product names mentioned herein
are trademarks of their respective companies. Mention
of third-party products is for informational purposes
only and constitutes neither an endorsement nor a
recommendation. Apple assumes no responsibility with
regard to the performance or use of these products.
019-0635/2-15-2006
Contents
1
Preface15About This Guide
16
Using This Guide
16
Understanding Notation Conventions
16
16
16
17
17
18
18
Summary
Commands and Other Terminal Text
Command Parameters and Options
Default Settings
Commands Requiring Root Privileges
Getting Documentation Updates
Getting Additional Information
Chapter 121Executing Commands
21
Opening Terminal
22
Specifying Files and Folders
23
Modifying Flow Control
23
24
25
26
26
26
26
26
27
27
28
28
Redirecting Input and Output
Using Environment Variables
Executing Commands and Running Tools
Correcting Typing Errors
Repeating Commands
Including Paths Using Drag and Drop
Searching for Text Within a File
Commands Requiring Root Privileges
Terminating Commands
Scheduling Tasks
Sending Commands to a Remote Computer
Viewing Command Information
Chapter 231Connecting to Remote Computers
31
Understanding Secure Shell
31
32
33
How SSH Works
Password-Less Logins Using SSH Keys
Updating SSH Key Fingerprints
3
34
34
35
35
36
What is an SSH Man-in-the-Middle Attack?
Controlling Access to SSH Service
Connecting to a Remote Computer
Using SSH
Using Telnet
Chapter 337Installing Server Software and Finishing Basic Setup
37
Installing Server Software
38
39
39
40
40
40
41
43
43
47
47
48
48
48
49
49
50
51
Locating Computers for Installation
Specifying the Target Computer Volume
Preparing the Target Volume for a Clean Installation
Installing from Multiple CDs
Restarting After Installation
Automating Server Setup
Creating a Configuration File
Working with an Encrypted Configuration File
Customizing a Configuration File
Storing a Configuration File in an Accessible Location
Configuring the Server Remotely from the Command Line
Changing Server Settings
Using the serversetup Tool
Using the serveradmin Tool
General and Network Preferences
Viewing, Validating, and Setting the Software Serial Number
Updating Server Software
Moving a Server
Chapter 453Restarting or Shutting Down a Computer
53
Restarting a Computer
53
54
54
54
55
Automatic Restart
Changing a Remote Computer’s Startup Disk
Shutting Down a Computer
Manipulating Open Firmware NVRAM Variables
Monitoring and Restarting Critical Services
Chapter 557Setting General System Preferences
57
Viewing or Changing the Computer Name
57
Viewing or Changing the Date and Time
58
58
58
58
59
4
Viewing or Changing the System Date
Viewing or Changing the System Time
Viewing or Changing the System Time Zone
Viewing or Changing Network Time Server Usage
Viewing or Changing the Energy Saver Settings
Contents
59
59
60
60
61
61
61
61
62
Viewing or Changing Sleep Settings
Viewing or Changing Automatic Restart Settings
Changing the Power Management Settings
Viewing or Changing the Startup Disk Settings
Viewing or Changing the Sharing Settings
Viewing or Changing Remote Login Settings
Viewing or Changing Apple Event Response
Viewing or Changing the International Settings
Viewing and Changing the Login Settings
Chapter 663Setting Network Preferences
63
Configuring Network Interfaces
64
Managing Network Interface Information
64
64
65
65
65
65
65
66
66
67
69
70
70
70
72
72
73
73
74
75
76
76
77
77
77
77
78
78
78
79
Viewing Port Names and Hardware Addresses
Viewing or Changing MTU Values
Viewing or Changing Media Settings
Managing Network Port Configurations
Creating or Deleting Port Configurations
Activating Port Configurations
Changing Configuration Precedence
Managing TCP/IP Settings
Changing a Server’s IP Address
Viewing or Changing IP Address, Subnet Mask, or Router Address
Viewing or Changing DNS Servers
Enabling TCP/IP
Working with VLANs
Collecting SNMP Information from the Host
Managing Proxy Settings
Viewing or Changing FTP Proxy Settings
Viewing or Changing Web Proxy Settings
Viewing or Changing Secure Web Proxy Settings
Viewing or Changing Streaming Proxy Settings
Viewing or Changing Gopher Proxy Settings
Viewing or Changing SOCKS Firewall Proxy Settings
Viewing or Changing Proxy Bypass Domains
Managing AirPort Settings
Managing the Computer, Host, and Bonjour Names
Contents
5
79
79
80
80
81
Computer Name
Hostname
Bonjour Name
Managing Preference Files and the Configuration Daemon
Changing Network Locations
Chapter 783Working with Disks and Volumes
83
Understanding Disks, Partitions, and the File System
83
Mounting and Unmounting Volumes
84
84
Mounting Volumes
Unmounting Volumes
85Displaying Disk Information
85Monitoring Disk Space
86Reclaiming Disk Space Using Log-Rolling Scripts
87Erasing, Modifying, Verifying, and Repairing Disks
89Partitioning and Formatting Disks
89Partitioning a Disk
90Labeling a Disk
90Formatting a Disk
90Checking for Disk Problems
91Managing Disk Journaling
91Checking to See If Journaling is Enabled
91Enabling Journaling for an Existing Volume
92Enabling Journaling When You Erase a Disk
92Disabling Journaling
92Understanding Spotlight Technology
92Enabling and Disabling Spotlight
93Performing Spotlight Searches
98Administering and Creating Accounts
98Creating a Local Administrator User Account for a Server
99Creating a Domain Administrator User Account
10 0Checking a User’s Administrator Privileges
10 0Creating a Nonadministrator User Account
10 3Retreiving a User’s GUID
10 3Removing a User Account
10 4Revoking a User’s Right to Access His or Her Account
10 6Checking a Server User’s Name, UID, or Password
6
Contents
10 7Modifying a User Account
10 8Creating a Mobile User Account
10 9Managing Home Folders
11 0Administering Group Accounts
111Creating a Group Account
112Removing a Group Account
113Adding a User to a Group
11 4Removing a User from a Group
11 6Creating and Deleting Nested Group
117Editing Group Records
11 8Creating a Group Folder
11 8Viewing the Workgroup a User Selects at Login
11 9Importing Users and Groups
12 0Creating a Character-Delimited User Import File
12 3Setting Permissions
12 3Viewing Permissions
12 4Setting the umask for Individual Users
12 5Changing Permissions
12 6Changing the Owner
12 6Changing the Group
12 6Securing System Accounts
12 6Securing Initial System Accounts
12 7Securing the Root Account
12 7Restricting Use of the sudo Tool
12 8Securing Single-User Boot
12 9Setting Password Policy
131Finding User Account Information
Chapter 9133Working with File Services
13 3Managing Share Points
13 4Listing Share Points
13 4Creating a Share Point
13 5Modifying a Share Point
13 6Disabling a Share Point
13 6Managing the AFP Service
13 6Starting and Stopping AFP Service
13 6Checking AFP Service Status
13 6Viewing AFP Settings
13 7Changing AFP Settings
13 7List of AFP Settings
14 0List of AFP serveradmin Commands
141Listing Connected Users
14 2Sending a Message to AFP Users
Contents7
14 2Disconnecting AFP Users
14 3Canceling a User Disconnect
14 4Listing AFP Service Statistics
14 5Viewing AFP Log Files
14 6Managing the NFS Service
14 6Starting and Stopping NFS Service
14 6Checking NFS Service Status
14 6Viewing NFS Service Settings
14 6Changing NFS Service Settings
14 7Managing the FTP Service
14 7Starting FTP Service
14 7Stopping FTP Service
14 7Checking FTP Service Status
14 7Viewing FTP Service Settings
14 8Changing FTP Service Settings
14 8List of FTP Service Settings
15 0List of FTP serveradmin Commands
15 0Viewing the FTP Transfer Log
15 0Checking for Connected FTP Users
151Managing the SMB/CIFS Service
151Starting and Stopping SMB/CIFS Service
151Checking SMB/CIFS Service Status
151Viewing SMB/CIFS Service Settings
15 2Changing SMB/CIFS Service Settings
15 2List of SMB/CIFS Service Settings
15 5List of SMB/CIFS serveradmin Commands
15 5Listing SMB/CIFS Users
15 6Disconnecting SMB/CIFS Users
15 6Listing SMB/CIFS Service Statistics
157Updating Share Point Information
157Viewing SMB/CIFS Service Logs
157Managing ACLs
15 8Using chmod to Modify ACLs
Chapter 10161Working with the Print Service
161Understanding the Print Process
162Performing Print Service Tasks
162Starting and Stopping Print Service
163Checking the Status of Print Service
163Viewing Print Service Settings
163Changing Print Service Settings
166Managing the Print Service
167Listing Queues
8Contents
167Pausing a Queue
167Listing Jobs and Job Information
168Holding a Job
169Viewing Print Service Log Files
169Viewing Cover Pages
Chapter 11171Working with NetBoot Service and System Images
171Understanding the NetBoot Service
171Starting and Stopping NetBoot Service
17 2Checking NetBoot Service Status
17 2Viewing NetBoot Settings
17 2Changing NetBoot Settings
17 3Changing General Netboot Service Settings
17 3Storage Record Array
174Filters Record Array
174Image Record Array
17 5Port Record Array
17 6Working with System Images
17 6Updating an Image
17 6Booting from an Image
17 6Using hdiutil to Work with System Images
17 7Using asr to Restore System Images
17 7Imaging Multiple Clients Using Multicast asr
17 8Choosing a Boot Device Using systemsetup
Chapter 12179Working with the Mail Service
17 9Understanding the Mail Service
17 9Postfix Agent
18 0Cyrus
18 0Mailman
181Managing the Mail Service
181Starting and Stopping Mail Service
181Checking the Status of Mail Service
181Viewing Mail Service Settings
181Changing Mail Service Settings
18 2Mail Service Settings
19 4Mail serveradmin Commands
19 4Listing Mail Service Statistics
19 5Viewing the Mail Service Logs
19 6Backing Up the Mail Files
19 7Reconstructing the Mail Database
19 8Setting Up SSL for Mail Service
19 8Generating a CSR and Creating a Keychain
Contents9
200Obtaining an SSL Certificate
200Importing an SSL Certificate into the Keychain
200Accessing the Server Certificates
201Creating a Password File
202Configuring Mailboxes
202Enabling Sieve Scripting
203Enabling Sieve Support
Chapter 13207Working with Web Technologies
207Understanding Web Technology
208Managing the Web Service
208Starting and Stopping Web Service
208Checking Web Service Status
208Viewing Web Settings
209Changing Web Settings
209serveradmin and Apache Settings
209Changing Settings Using serveradmin
210Web serveradmin Commands
210Listing Hosted Sites
210Viewing Service Logs
210Viewing Service Statistics
212Example Script for Adding a Website
213Tuning the Server Performance
214Working with Application Servers and Java
214Apache Tomcat
214JBoss Server
215MySQL Database
Chapter 14217Working with Network Services
217Managing Network Services
218Managing the DHCP Service
218Starting and Stopping DHCP Service
218Checking the Status of DHCP Service
218Viewing DHCP Service Settings
219Changing DHCP Service Settings
219DHCP Service Settings
220DHCP Subnet Settings Array
222Adding a DHCP Subnet
223Adding a DHCP Static Map
224List of DHCP serveradmin Commands
224Viewing the DHCP Service Log
225Managing the DNS Service
225Starting and Stopping the DNS Service
10Contents
225Checking the Status of DNS Service
225Viewing DNS Service Settings
226Changing DNS Service Settings
226DNS Service Settings
226List of DNS serveradmin Commands
226Viewing the DNS Service Log
226Listing DNS Service Statistics
227Configuring IP Forwarding
227Managing the Firewall Service
228Firewall Startup
228Starting and Stopping Firewall Service
228Checking the Status of Firewall Service
228Viewing Firewall Service Settings
229Changing Firewall Service Settings
229Firewall Service Settings
230Defining Firewall Rules
234Viewing Firewall Service Log
234Using Firewall Service to Simulate Network Activity
234Managing the NAT Service
235Starting and Stopping NAT Service
235Checking the Status of NAT Service
235Viewing NAT Service Settings
235Changing NAT Service Settings
236NAT Service Settings
236NAT serveradmin Commands
237Port Mapping
237Viewing the NAT Service Log
238Managing the VPN Service
238Starting and Stopping VPN Service
238Checking the Status of VPN Service
238Viewing VPN Service Settings
239Changing VPN Service Settings
239List of VPN Service Settings
242List of VPN serveradmin Commands
242Viewing the VPN Service Log
243Site-to-Site VPN
243Configuring Site-to-Site VPN
244Adding a VPN Keyagent User
245Setting Up IP Failover
245IP Failover Prerequisites
245IP Failover Operation
Contents11
246Enabling IP Failover
247Configuring IP Failover
248Enabling PPP Dial-In
248Restoring the Default Configuration for Server Services
Chapter 15251Working with Open Directory
251Understanding Open Directory
251Using General Directory Tools
251Testing Your Open Directory Configuration
252Modifying a Directory Domain
252Testing Open Directory Plug-ins
252Registering URLs with SLP
252Changing Open Directory Service Settings
253Managing OpenLDAP
253Configuring LDAP
254Configuring slapd and slurpd Daemons
255Idle Rebinding Options
255Searching the LDAP Server
258Using LDIF Files
259Additional Information About LDAP
259Managing NetInfo
259Configuring NetInfo
260Managing Open Directory Passwords
260Open Directory Password Server
261Kerberos and Apple Single Sign-On
263Using Directory Service Tools
263Operating on Directory Service Directory Domains
264Finding Network Information
264Manipulating a Single Named Group Record
265Adding or Removing LDAP Server Configurations
265Configuring the Active Directory Plug-In
Chapter 16267Working with QuickTime Streaming Server
267Understanding QuickTime Streaming Server
267Performing QTSS Service Tasks
268Starting and Stopping the QTSS Service
268Checking QTSS Service Status
268Viewing QTSS Settings
268Changing QTSS Settings
269QTSS Settings
272Managing QTSS
272Listing Current Connections
273Viewing QTSS Service Statistics
12Contents
274Viewing Service Logs
274Forcing QTSS to Reread its Preferences
275Preparing Older Home Folders for User Streaming
275Configuring Streaming Security
275Resetting the Streaming Server Admin User Name and Password
276Controlling Access to Streamed Media
276Creating an Access File
278Accessing Protected Media
278Adding User Accounts and Passwords
278Adding or Deleting Groups
278Making Changes to the User or Group File
279Manipulating QuickTime and MP4 Movies
279Creating Reference Movies
Chapter 17281Configuring System Logging
281Logging System Events
281Configuring the Log File
281Configuring Your System Logging
282Local Logging
283Remote Logging
Appendix285PCI RAID Card Command Reference
Glossary289
Index299
Contents13
14Contents
About This Guide
This guide describes Mac OS X Servers command-line
interface tools and commands, including the syntax, purpose,
and parameters, as well as examples of usage and any output
that they generate.
This guide is written for system administrators familiar with administering and
managing servers, storage, and networks.
Beneath the interface of Mac OS X is a core operating system commonly known as
Darwin. Darwin integrates a number of technologies, most importantly Mach 3.0,
operating-system services based on Berkeley Software Distribution (BSD) release 4.4
high-performance networking facilities, and support for multiple integrated file
systems.
Preface
Darwin maintains most of the functionality of 4.4BSD commands. While some
commands are modified to function differently, most of the commands are either kept
as is, or their functionality has been extended to support Apple-specific technologies.
This guide focuses on commands developed by Apple to allow administrators to
perform funtions available in the graphical interface from the command line. The guide
also highlights BSD commands that have been modified or extended to support Applespecific functionality. Finally, the guide describes important commands commonly
used by UNIX system administrators.
Note: Because Apple frequently releases new versions and updates to its software,
images shown in this book may be different from what you see on your screen.
15
Using This Guide
This guide describes commands that perform functions used to configure and manage
Mac OS X computers. Chapters in this guide describe sets of commands that work for
specific aspects of the operating system.
Use this guide to:
 Learn which commands are available for specific tasks
 Learn how the commands work, and how to execute them
 Review examples of command usage
Understanding Notation Conventions
The following conventions are used throughout this book.
Summary
NotationIndicates
monospaced fontA command or other text typed in a Terminal window
$A shell prompt
[text_in_brackets]An optional parameter
(one|other)Alternative parameters (enter one or the other)
italicized
[...]A parameter that may be repeated
<angle brackets>A displayed value that depends on your server configuration
A parameter you must replace with a value
Commands and Other Terminal Text
Commands or command parameters that you might enter, along with other text that
normally appears in a Terminal window, are shown in this font. For example:
You can use the doit command to get things done.
When a command is shown on a line by itself in this manual, it is preceded by a dollar
sign and a space that represent the shell prompt. For example:
$ doit
To use this command, enter it without the dollar sign and the space in a Terminal
window, and then press the Return key. (Terminal is found in /Applications/Utilities).
Command Parameters and Options
Most commands require one or more parameters to specify command options or the
item to which the command is applied.
16Preface About This Guide
Parameters You Must Enter as Shown
If you must enter a parameter as shown, it appears following the command in the
same font. For example:
$ doit -w later -t 12:30
To use the command in this example, enter the entire line as shown (without the $ and
space).
Parameter Values You Provide
If you must provide a value, its placeholder is italicized and has a name that indicates
what you need to provide. For example:
$ doit -w later -t hh:
mm
In this example, you replace hh with the hour and mm with the minute, as shown in the
previous example.
Optional Parameters
If a parameter is not required, it appears in square brackets. For example:
$ doit [-w later]
To use the command in this example, enter either doit or doit -w later. The result
might vary, but the command will be performed either way.
Alternative Parameters
If you must enter one of a number of parameters, they’re separated by a vertical line
and grouped within parentheses (|). For example:
$ doit -w (now|later)
To perform this command, enter either doit -w now or doit -w later.
Default Settings
Descriptions of server settings usually include the default value for each setting. When
this default value depends on your configuration (such as the name or IP address of
your server), it’s enclosed in angle brackets.
For example, the default value for the IMAP mail server is the host name of your server.
This is indicated by mail:imap:servername = "<hostname>".
Commands Requiring Root Privileges
Throughout this manual, commands that require root privileges begin with sudo. See
“Commands Requiring Root Privileges” on page 26.
Preface About This Guide17
Getting Documentation Updates
Periodically, Apple posts revised guides and solution papers. To download the latest
guides and solution papers in PDF format, go to the Mac OS X Server documentation
webpage: www.apple.com/server/documentation.
Getting Additional Information
For more information, consult these resources:
Read Me documents—Important updates and special information. Look for them on the
server discs.
Man pages (developer.apple.com/documentation/Darwin/Reference/ManPages/)—The
Apple Developer Connection (ADC) Reference Library contains man pages for many
BSD and POSIX functions and applications included with Mac OS X.
Mac OS X Server website (www.apple.com/macosx/server/)—Gateway to extensive
product and technology information.
AppleCare Service & Support website (www.apple.com/support/)—Access to hundreds of
articles from Apple’s support organization.
Apple customer training (train.apple.com)—Instructor-led and self-paced courses for
honing your server administration skills.
Apple discussion groups (discussions.info.apple.com)—A way to share questions,
knowledge, and advice with other administrators.
Apple mailing list folder (www.lists.apple.com)—Subscribe to mailing lists so you can
communicate with other administrators using email.
The public source website (developer.apple.com/darwin/)—Access to Darwin source
code, developer information, and FAQs.
Mac OS X Server suite documentation (www.apple.com/server/documentation/)—The
Mac OS X Server documentation includes a suite of guides that explain the available
services and provide instructions for configuring, managing, and troubleshooting those
services.
This guide ...tells you how to:
Mac OS X Server Getting Started
for Version 10.4 or Later
Mac OS X Server Upgrading and
Migrating to Version 10.4 or Later
Mac OS X Server User
Management for Version 10.4 or
Later
18Preface About This Guide
Install Mac OS X Server and set it up for the first time.
Use data and service settings that are currently being used on
earlier versions of the server.
Create and manage users, groups, and computer lists. Set up
managed preferences for Mac OS X clients.
This guide ...tells you how to:
Mac OS X Server File Services
Administration for Version 10.4 or
Later
Mac OS X Server Print Service
Administration for Version 10.4 or
Later
Mac OS X Server System Imaging
and Software Update
Administration for Version 10.4 or
Later
Mac OS X Server Mail Service
Administration for Version 10.4 or
Later
Mac OS X Server Web
Technologies Administration for
Version 10.4 or Later
Mac OS X Server Network Services
Administration for Version 10.4 or
Later
Mac OS X Server Open Directory
Administration for Version 10.4 or
Later
Mac OS X Server QuickTime
Streaming Server Administration
for Version 10.4 or Later
Mac OS X Server Windows
Services Administration for
Version 10.4 or Later
Mac OS X Server Migrating from
Windows NT for Version 10.4 or
Later
Mac OS X Server Java Application
Server Administration For Version
10.4 or Later
Mac OS X Server Command-Line
Administration for Version 10.4 or
Later
Mac OS X Server Collaboration
Services Administration for
Version 10.4 or Later
Mac OS X Server High Availability
Administration for Version 10.4 or
Later
Share selected server volumes or folders among server clients
using these protocols: AFP, NFS, FTP, and SMB/CIFS.
Host shared printers and manage their associated queues and print
jobs.
Use NetBoot and Network Install to create disk images from which
Macintosh computers can start up over the network. Set up a
software update server for updating client computers over the
network.
Set up, configure, and administer mail services on the server.
Set up and manage a web server, including WebDAV, WebMail, and
web modules.
Set up, configure, and administer DHCP, DNS, VPN, NTP, IP firewall,
and NAT services on the server.
Manage directory and authentication services.
Set up and manage QuickTime streaming services.
Set up and manage services including PDC, BDC, file, and print for
Windows computer users.
Move accounts, shared folders, and services from Windows NT
servers to Mac OS X Server.
Configure and administer a JBoss application server on Mac OS X
Server.
Use commands and configuration files to perform server
administration tasks in a UNIX command shell.
Set up and manage weblog, chat, and other services that facilitate
interactions among users.
Manage IP failover, link aggregation, load balancing, and other
hardware and software configurations to ensure high availability of
Mac OS X Server services.
Preface About This Guide19
This guide ...tells you how to:
Mac OS X Server Xgrid
Administration for Version 10.4 or
Later
Mac OS X Server
Glossary: Includes Terminology for
Mac OS X Server, Xserve, Xserve
RAID, and Xsan
Manage computational Xserve clusters using the Xgrid application.
Interpret terms used for server and storage products.
20Preface About This Guide
1Executing Commands
1
In this chapter you will find out how to execute commands
and view online information about commands and tools.
A command-line interface is a way for you to manipulate your computer in situations
where a graphical approach is not available. The Terminal application is the Mac OS X
gateway to the BSD command-line interface (UNIX shell command prompt). Each
window in Terminal contains a complete execution context, called a shell, that is
separate from all other execution contexts. The shell itself is an interactive
programming language interpreter, with a specialized syntax for executing commands
and writing structured programs, called shell scripts.
Different shells feature slightly different capabilities and programming syntax. Although
you can use any shell of your choice, the examples in this book assume that you are
using bash, the standard Mac OS X shell.
Opening Terminal
To enter shell commands or run server command-line tools, you need access to a UNIX
shell prompt. Both Mac OS X and Mac OS X Server include Terminal, an application you
can use to start a UNIX shell command-line session on the local server or on a remote
server.
To open Terminal, click the Terminal icon in the dock or double-click the application
icon in the Finder (located in /Applications/Utilities/).
Terminal presents a prompt when it is ready to accept a command. The prompt you see
depends on your Terminal and shell preferences, but often includes the name of the
host you’re logged in to, your current working folder, your user name, and a prompt
symbol.
21
For example, if you’re using the default bash shell and the prompt displays as:
server1:~ anne$
Where you are logged in to a computer named “server1” as the user named “anne,” and
your current folder is anne’s home folder (~).
Throughout this manual, wherever a command is shown as you might enter it, the
prompt is abbreviated as $.
Specifying Files and Folders
Most commands operate on files and folders, the locations of which are identified
by paths. The folder names that make up a path are separated by slash characters.
For example, the path to the Terminal application is
/Applications/Utilities/Terminal.app.
Some of the standard shortcuts used to represent specific folders in the computer are
shown in the following table. Because they are relative to the current folder, these
shortcuts eliminate the need to enter full paths in many situations.
Path stringDescription
.A single period represents the current folder. This value is often used as a shortcut to
eliminate the need to enter in a full path. For example, the string “./Test.c” represents
the Test.c file in the current folder.
..Two periods represents the parent folder of the current folder. This string is used
for navigating up one level from the current folder through the folder hierarchy.
For example, the string “../Test” represents a sibling folder (named Test) of the current
folder.
~The tilde character represents the home folder of the user currently logged in.
In Mac OS X, this folder resides either in the local /Users folder or on a network server.
For example, to specify the Documents folder of the current user, you would specify ~/
Documents.
File and folder names traditionally include only letters, numbers, a period, or the
underscore character. Most other characters, including space characters, should be
avoided. Although some Mac OS X file systems permit the use of these other
characters, including spaces, you may have to add single or double quotation marks
around any pathnames that contain them. For individual characters, you can also
“escape” the character—that is, put a backslash character immediately before the
character in your string. For example, the pathname My Disk would become either
“My Disk” or My\ Disk.
22Chapter 1 Executing Commands
Modifying Flow Control
Many commands are capable of receiving text input from the user and printing text
out to the console. They do so using standard pipes, which are created by the shell and
passed to the command automatically.
The standard pipes include:
 stdin—The standard input pipe is the means through which data enters a
command. By default, this is data entered by the user from the command-line
interface. You can also redirect the output from files or other commands to stdin.
 stdout—The standard output pipe is where the command output is sent. By default,
command output is sent back to the command line. You can also redirect the output
from the command to other commands and tools.
stderr—The standard error pipe is where error messages are sent. By default, errors
Â
are displayed on the command line like standard output.
Redirecting Input and Output
From the command line, you may redirect input and output from a command to a file
or another command. Redirecting output lets you capture the results of running the
command and store it in a file for later use. Similarly, providing an input file lets you
provide a command with preset input data, instead of having to enter that data.
RedirectDescription
>Use the greater-than character to redirect command output to a file.
<Use the less-than character to use the contents of a file as input to the command.
>>Use a double greater-than to append output from a command to a file.
In addition to using file redirection, you can also redirect the output of one command
to the input of another using the vertical bar character, or pipe. You can combine
commands in this manner to implement more sophisticated versions of the same
commands. For example, the command man bash | grep “commands” passes the
formatted contents of the bash man page to the grep tool, which searches those
contents for any lines containing the word “commands.” The result is a listing of only
those lines with the specified text, instead of the entire man page.
See the bash man page for more information about redirection.
Chapter 1 Executing Commands23
Using Environment Variables
Some commands require the use of environment variables for their execution.
Environment variables are variables inherited by all commands executed in the shell’s
context. The shell itself uses environment variables to store information, such as the
name of the current user, the name of the host computer, and the paths to any
commands. You can also create environment variables and use them to control the
behavior of your command without modifying the command itself. For example, you
might use an environment variable to tell your command to print debug information to
the console.
To set the value of an environment variable, you use the appropriate shell command to
associate a variable name with a value. For example, to set the variable PATH to the
value
/bin:/sbin:/user/bin:/user/sbin:/system/Library/, you would enter the
This will modify the environment variable PATH with the value assigned. To view all of
the environment variables, enter the following:
$ env
When you launch an application from a shell, the application inherits much of the
shell’s environment, including any exported environment variables. This form of
inheritance can be a useful way to configure the application dynamically. For example,
your application can check for the presence (or value) of an environment variable and
change its behavior accordingly. Different shells support different semantics for
exporting environment variables, so see the man page for your preferred shell for
further information.
PATH
Although child processes of a shell inherit the environment of that shell, shells are
separate execution contexts that do not share environment information with one
another. Thus, variables you set in one Terminal window are not set in other Terminal
windows. Once you close a Terminal window, any variables you set in that window are
gone. If you want the value of a variable to persist between sessions and in all Terminal
windows, you must set it in a shell startup script.
Another way to set environment variables in Mac OS X is with a special property list in
your home folder. At login, the computer looks for the ~/.MacOSX/environment.plist
file. If the file is present, the computer registers the environment variables in the
property-list file.
24Chapter 1 Executing Commands
Executing Commands and Running Tools
To execute a command in the shell, you must enter the complete pathname of the
tool’s executable file, followed by any arguments, and then press the Return key. If a
command is located in one of the shell’s known folders, you can omit any path
information and just enter the command name. The list of known folders is stored in
the shell’s PATH environment variable and includes the folders containing most of the
command-line tools.
For example, to run the ls command in the current user’s home folder, you could
simply enter it at the command line and press the Return key.
host:~ anne$ ls
To run a command in the current user’s home folder, you would precede it with the
folder specifier. For example, to run MyCommandLineProg, you would use something
like the following:
host:~ anne$ ./MyCommandLineProg
To launch a tool package, you can either use the open command (open MyProg.app) or
launch the tool by typing the pathname of the executable file inside the package,
usually something like ./MyProg.app/Contents/MacOS/MyProg.
When entering commands, if you get the message command not found, check your
spelling.
server:/ anne$ serversetup -getAllPort
serversetup: Command not found.
If the error recurs, the command you’re trying to run might not be in your default
search path. You can add the path before the command name, for example:
To correct a typing error before you press Return to execute the command, press Left
Arrow or Right Arrow to skip over parts of the command you don’t want to change,
press the Delete key to remove characters, enter regular characters to insert them, and
finally press Return to execute the command.
To ignore what you have entered and start again, press Control–U.
Repeating Commands
To repeat a command, press Up Arrow until you see the command, make any
modifications, and then press Return.
Including Paths Using Drag and Drop
To include a fully qualified filename or folder path in a command, you can drag and
drop the folder or file from a Finder window into the Terminal window.
Searching for Text Within a File
To locate a unique string within a file, use the grep tool. The grep tool searches the
named input files for lines containing a match to the given pattern. By default, grep
prints the matching lines.
To search for a unique string in a file:
$ grep
where filename is the name of the file you wish to search through and sunshine is the
unique string.
sunshine filename
Commands Requiring Root Privileges
Many commands used to manage a server must be executed by the root user. If you
get a message such as permission denied, the command probably requires root
privileges.
To execute a single command as the root user, begin the command with sudo (short for
super user do). For example:
$ sudo serveradmin list
You’re prompted for the root password if you haven’t used sudo recently. The root user
password is set to the administrator user password when you install Mac OS X Server.
To switch to the root user so you don’t have to repeatedly enter sudo, use the su
command:
$su root
You’re prompted for the root user password and then are logged in as the root user
until you log out or use the su command to switch to another user.
26Chapter 1 Executing Commands
Important: As the root user, you have sufficient privileges to do things that can cause
your server to stop working properly. Don’t execute commands as the root user unless
you know what you’re doing. Logging in as an administrator user and using
sudo
selectively might prevent you from making unintended changes.
Terminating Commands
To terminate the currently running command, enter Control-C. This keyboard shortcut
sends an abort signal to the command. In most cases this causes the command to
terminate, although commands may install signal handlers to trap this signal and
respond differently.
Scheduling Tasks
You can create scheduled tasks using the cron tool. cron is a daemon that executes
scheduled commands from a crontab file. The cron tool searches the /var/cron/tabs
folder for crontab files that are named after accounts in /etc/passwd, and loads the files
into memory. cron also searches for crontab files in the /etc/crontab folder, which are in
a different format. cron then cycles every minute, examining all stored crontab files and
checking each command to see if it should be run in the current minute.
When commands execute, any output is mailed to the owner of the crontab file or to
the user named in the MAILTO environment variable in the crontab file, if such exists.
When a crontab file has been modified, cron needs to be restarted. crontab is the
program used to install, deinstall, or list the tables used to drive the cron daemon.
Each user can have their own crontab file.
To configure your crontab file, use the crontab -e command. This displays an empty
crontab file.
The following crontab entry schedules a scan operation to run on the uz folder at 10:15
a.m. every Saturday in accordance with options specified in a configuration file conf1:
You must connect to a remote computer before you can execute commands on it.
You can send commands to a remote computer using:
 Secure Shell (SSH), a tool for logging in to a remote computer and for executing
commands on a remote computer.
 Telnet, a tool for communicating with another computer using the TELNET protocol.
See Chapter 2, “Connecting to Remote Computers,” on page 31 for information about
sending commands to remote computers.
Viewing Command Information
Most command-line documentation comes in the form of man pages. These are
formatted pages that provide reference information for shell commands, tools, and
high-level concepts. You can also access command information using the help
command, and sometimes information is displayed if you enter the command without
any parameters or options.
To access a man page:
$ man
command
where
command
detailed information about the command, its options, parameters, and proper use. For
help using the man command, enter:
$ man man
If the man pages are so long that they do not fit on your screen, you can use the more
or less command to automatically paginate the file. This allows you to view the file
faster by loading full screens of the man page at a time, rather than the entire file.
$ man serveradmin | less
28Chapter 1 Executing Commands
is the topic you want to find information about. The man page contains
When you use more or less, an information bar appears at the bottom of the screen.
When you see the bar, you can press the Space bar to go to the next page, the B key to
go back a page, or the Return key to scroll the file forward one line at a time. When you
get to the end of a file, more will return you to the prompt and less will wait for you
to press the Q key to quit.
Several third-party Mac OS X applications are available for viewing formatted man
pages in scrollable windows. You can find one by choosing Mac OS X Software from the
Apple menu, and then seraching for “man page.”
Note: Not all commands and tools have man pages. For a list of available man pages,
look in /usr/share/man.
To access command help, enter the command followed by the -help, -h, --help,
or help parameter:
$ hdiutil help
$ dig -h
$ diff --help
To view a pop-up list of options and parameters you can use with the command,
enter the command without any options or parameters:
$ sudo serveradmin
Note: Not all techniques work for all commands, and some commands don’t have
onscreen help.
Chapter 1 Executing Commands29
30Chapter 1 Executing Commands
Loading...
+ 274 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.