macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

An Introduction to Tiger Terminal

by Mary Norbury-Glaser
05/20/2005

Mac OS X: Not Just A Pretty Face

OS X revolutionized the Mac by building an elegant GUI over a BSD kernel. Most users didn't much care about the inherent security and stability of the UNIX foundation, but experienced UNIX users recognized the power underneath the Aqua interface. This article will introduce you to some of the power the built-in Terminal app and command-line interface (CLI) can unleash for Tiger users.

The Terminal

In /Applications/Utilities, you'll find the Terminal app. The Terminal is the doorway to the UNIX workings of Mac OS X. Keep in mind that both the Finder and the Terminal communicate with the underlying UNIX engine, but it's the user who chooses one method of inputting commands over another. In the GUI, the user clicks on icons to issue commands; via the CLI, the user types commands that accomplish the same tasks. The CLI displays something like this:

The Command Line Interface (CLI)
The command-line interface (CLI)

Underneath the "Welcome to Darwin!" greeting is the command line prompt. My 12" PowerBook is named tigerbeta; the ~ (tilde character) is a shortcut for one's home directory; tigerbeta1 is my short user name (in other words, the user who is logged in); all of this is followed by the $ sign. Just as files live in directories (/Applications/Utilities), the shell has a working directory. Let's issue our first command and type pwd to see the full path to the shell's current working directory (pwd stands for "print working directory," where "print" actually means display):

Last login: Tue Feb  22 17:35:46 on ttyp1
Welcome to Tiger Beta!
tigerbeta:~ tigerbeta1$ pwd
/Users/tigerbeta1
tigerbeta:~ tigerbeta1$

The full path to your home directory should be similar to mine (/Users/tigerbeta1), beginning with the forward slash character /, which denotes the root, or top directory, of your filesystem.

A Shell Aside

At the top of the window, you'll see Terminal - bash - 74x18 (your screen size will be a bit different). The bash title tells you what shell you're using. A shell is a UNIX program that takes the commands you type and passes them to the system kernel. Another way to describe the shell is a "command interpreter." There are several different shells available in Mac OS X. Jaguar included the default tcsh (an enhanced version of the Berkeley UNIX C shell) and Panther introduced the default bash shell (GNU Bourne Again SHell) which has better international text features and is common in the Linux world. Tiger continues the default bash option, but let's try out another command to see what other shells are included. After the $ prompt, type cat /etc/shells (with a space after cat) and hit Return:

tigerbeta:~ tigerbeta1$ cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
tigerbeta:~ tigerbeta1$ 

The cat command ("concatenate") is run against the shells file in the /etc directory and gives us the output of the shells that are supported on Mac OS X. We see that a new addition to Tiger is ksh, or the korn shell. This will make many korn shell fans happy; previously, to install korn, one had to download and install a pre-compiled binary of the korn shell for the Mac. Having the korn shell provides maximum compatibility for Solaris users.

Welcome To My World

Let's start simple by changing the default greeting when our Terminal app launches. This lesson will introduce the command sudo, the text processor nano, and some new commands.

When you open the Terminal, you'll see the default greeting: "Welcome to Darwin!" (Darwin is a combination of technologies that make up Mac OS X, including the core BSD-based UNIX distribution). We can replace the Darwin greeting with something more personal and unique by editing the motd file (which resides in the /etc directory) using a text processor.

Remember that we're in our home directory when we open Terminal, so we'll change directories to the /etc directory using the cd command:

tigerbeta:~ tigerbeta1$ cd /etc
tigerbeta:/etc tigerbeta1$

Note that the prompt is now showing us our current working directory, which has changed from our Home directory (tigerbeta:~) to the destination directory (tigerbeta:/etc). You can look at a listing of the files in this directory by using the command ls:

tigerbeta:/etc tigerbeta1$ ls
6to4.conf         httpd            protocols
X11               inetd.conf       racoon
afpovertcp.cfg    mail.rc          rmtab
bashrc            master.passwd    rpc
crontab           motd             shells
cups              mail             sudoers

This is a partial listing; there are many more files in this directory than are shown above. (For the curious: the crontab file still exists in Tiger, but it merely directs the user to /System/Library/LaunchDaemons.) We'll start by making a backup copy of the motd file in case we need to restore the file to its default. We'll try the the cp (copy) command to make a copy of motd and rename it all in one step:

tigerbeta:/etc tigerbeta1$ cp motd motd.bak
cp: motd.bak: Permission denied
tigerbeta:/etc tigerbeta1$

Unfortunately, we hit a roadblock: we don't have permission to write to the /etc directory. In fact, only root can write to /etc and I'm logged in as merely my administrator self. As administrator, I have power--but not enough power to change core system files.

Pages: 1, 2, 3

Next Pagearrow