macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

An Introduction to Tiger Terminal, Part 2

by Mary Norbury-Glaser
06/14/2005

Part One of this series introduced the Terminal application in Mac OS X with the assumption that you're now running OS X 10.4.x (Tiger). If you made it through Part One unscathed, then you're ready to get some real work done.

In Part Two, you'll learn how to use the terminal app to look at external volumes, then enable ssh to access files, scp to securely copy them remotely, sftp for secure ftp, and finally how to use rsync to synchronize files between two computers.

What Do We Have Here?

Whenever you add a new hard disk, flash drive, network drive, iPod, CD, or DVD to your system, these additional disks are mounted onto the filesystem in the directory /Volumes. Open your terminal app and type ls /Volumes to see a basic listing of what you have mounted. On my 12" Powerbook, three disks show up:

Last login: Sun May 29 12:57:23 on ttyp1
Mary's Tiger!
tiger12:~ norburym$ ls /Volumes
BIG TIKI   DevilDuckie  Untitled
tiger12:~ norburym$ 

BIG TIKI is my 1GB USB drive housed in a Tiki statue, DevilDuckie is my red devil rubber duckie flash drive and Untitled is my internal boot disk. (Gee, I should get more creative with my local drive!)
Run a long listing with the option -l to get more information:

tiger12:~ norburym$ ls -l /Volumes
total 72
drwxrwxrwx 1 norburym norburym 16384 May 29 13:13 BIG TIKI
drwxrwxrwx 1 norburym norburym 16384 May 29 13:02 DevilDuckie
lrwxr-xr-x 1 root  admin     1 May 29 09:51 Untitled -> /
tiger12:~ norburym$

Total 72 gives me the amount of storage in blocks (each block is 1024 bytes) used by all the items in /Volumes. The following shows how to "decode" the rest of the information displayed:

Figure 1: Long listing of /Volumes (modeled after p. 41, Learning Unix for Mac OS X Panther, O'Reilly) Figure 1: Long listing of /Volumes (modeled after p. 41, Learning Unix for Mac OS X Panther, O'Reilly)

Notice that the type for Untitled is listed with the letter "l" which means it's a link pointing to root (/). Both BIG TIKI and DevilDuckie are listed with a "d" for directory.

Let's put in a DVD (Casablanca) and attach one of my iPods (Marys U2Pod):

tiger12:~ norburym$ ls -l /Volumes
total 76
drwxrwxrwx 1 norburym norburym 16384 May 29 13:13 BIG TIKI
dr-xr-xr-x 4 norburym norburym   136 Aug 30 2004  Casablanca
drwxrwxrwx 1 norburym norburym 16384 May 29 13:02 DevilDuckie
drwxr-xr-x 18 norburym norburym 714 May 27 11:25 Marys U2Pod
lrwxr-xr-x 1 root     admin     1 May 29 09:51 Untitled -> /
tiger12:~ norburym$

Let's use the terminal to look at the files on my iPod using the -F option with ls. If you man the command ls and read about the -F option, you'll see this description:

"Display a slash (/) immediately after each pathname that is a directory, an asterisk (*) after each that is executable, an at sign (@) after each symbolic link."

Control-Z to stop the man page and get back to your shell prompt.

Here are two ways to look at the files on your iPod:

  1. Without actually changing to the /Volumes directory, you can give the pathname to the directory. Using this method leaves you in your home directory:

    tiger12:~ norburym$ ls -F /Volumes/Marys\ U2Pod
    SlashdotReviews/   Desktop DB   Temporary Items/
    Calendars/    Desktop DF   iPod_Control/
    Contacts/     Icon?
    Desktop/      Notes/
    tiger12:~ norburym$
    

    Note that because the name of my iPod has a space in it (Marys U2Pod), I need to tell the shell about the space. To do this, you can use the backslash character directly before the space like this: Marys\ U2Pod (The backslash preserves the character immediately following which is, in this case, the space.) or enclose the name in single or double quotes* like this: 'Marys U2Pod' so the command becomes:

    tiger12:~ norburym$ ls -F /Volumes/'Marys U2Pod'

    *man bash and read the Quoting section to learn about the differences between using the single and double quotes. In this case, either can be used.

  2. Change to the /Volumes directory first and then use the -F option:

    tiger12:~ norburym$ cd /Volumes
    tiger12:/Volumes norburym$ ls -F /Volumes/'Marys U2Pod'
    SlashdotReviews/   Desktop/   Icon?     iPod_Control/
    Calendars/    Desktop   DB Notes/
    Contacts/    Desktop DF   Temporary Items/
    tiger12:/Volumes norburym$ 

    In this case, you end up in the directory that you changed into: the /Volumes directory. Let's go take a look in the iPod_Control directory. Change into the iPod volume and the iPod_Control directory and then do a listing with the -F option:

    tiger12:/Volumes norburym$ cd 'Marys U2Pod'/iPod_Control/
    tiger12:/Volumes/Marys U2Pod/iPod_Control norburym$ ls -F
    Device/   Music/   iPodPrefs*   iTunes/
    tiger12:/Volumes/Marys U2Pod/iPod_Control norburym$

    Remember, I have to use the single quotes (or backslash) to maintain the space character in the name of my iPod but notice that resulting file path (tiger12:/Volumes/Marys U2Pod/iPod_Control) simply shows the space. The -F option shows my directories (Device, Music and iTunes) and one executable (iPodPrefs), which is indicated by the asterisk. Let's take a look in the Music directory:

    tiger12:/Volumes/Marys U2Pod/iPod_Control 
    norburym$ ls -F Music
    F00/ F04/ F08/ F12/ F16/ F20/ F24/ F28/
    F01/ F05/ F09/ F13/ F17/ F21/ F25/ F29/
    F02/ F06/ F10/ F14/ F18/ F22/ F26/ F30/
    F03/ F07/ F11/ F15/ F19/ F23/ F27/ F31/
    (etc)

    Look in any of these directories and you'll see your audio files:

    tiger12:/Volumes/Marys U2Pod/iPod_Control norburym$ ls Music/F20
    01 Blow It Out.m4p            1-16 Thieves In The Temple.aif
    01 Clarity.m4p                    10 The Thrill Is Gone.m4a
    01 The Lady Is A Tramp.aif        11 Sweet Surrender.aif
    04 The Wind Cries Mary _Liv.mp3   13 Goin_ Down.aif
    (etc)

    This is a great example of how the terminal excels over the GUI: you can quickly see all the hidden ("protected-from-the-users-for-their-own-good") files and see how directories and their related files are structured.

ssh Will Help You Administer Clients Without Having to Get Out of Your Aeron Chair

When you're working on a network, there will be times that you need to access your second Mac or, if you're an administrator, another user's Mac. You may be lounging in bed with your PowerBook on a cold winter's night and need to copy critical files from that G5 way down in the basement office. Or perhaps you've taken the day off from work and a user halfway across town is having a problem with an application that won't quit.

The solution is to enable Remote Login on your networked computers so you can access the remote shell from your local Mac and solve these and other vexing problems from the comfort of your own chair (bed, or from the bar in Mazatlan... been there, done that).

To enable Remote Login, make a one-time visit to the networked Macs you want to access. Log in with an administrator's credentials, go to the Sharing preference panel (pref pane) in System Preferences and under the Services tab, select the Remote Login option. Remote Login will start automatically.

Figure 2: Enabling Remote Login. Figure 2: Enabling Remote Login.

Pages: 1, 2

Next Pagearrow