[Access to Wang masthead]

Behind the GUI

Exploring UNIX

From "Migration",  Access to Wang, September 1993
  [ Prior Article ]     [ Return to the Catalog of articles ]     [ Next Article ]  

Unix is a general-purpose operating system, so it has a great deal of breadth. There are many features and options and, therefore, many things to learn. Since most of us are busy keeping our shops together it is difficult to find time to study and practice - and practice is necessary to master Unix.

Learning Unix command syntax is a requirement for all system administrators and programmers. Even if you have maintenance applications to shield you from the detail of the operating environment, there will always be need to understand the underlying commands that these tools rely on. Therefore, this series begins with some exercises to help you gain this knowledge.

I assume here that you are set up to run the Bourne shell environment, the most universally available shell processor available for UNIX systems. Shells are roughly equivalent to the MS-DOS command interpreter COMMAND.COM: they translate commands typed at the prompt into machine actions, launch programs, and issue error messages when their syntax is violated. The choice of default shell environment is made when the user account is set up and becomes part of each individual's profile. Other shell options include the C shell, which has a syntax like that of the C language, and the Korn shell, which combines some advantages of the Bourne and C shells.

I also assume that you are working at a display terminal - probably a "dumb" terminal or terminal emulation program run on a PC - and that you have access to a prompt to try out some commands.

Getting on the system

UNIX systems are typically set up with login screens that are functionally similar to the VS. When the terminal session is started - either by switching on the workstation or starting an emulation program - the screen should display a login: prompt. Enter your user ID and press ENTER. The system will next send the Password: prompt; enter your password and press ENTER. Remember that user IDs and passwords are case-sensitive in UNIX.

If you make a mistake on the login screens, you will find that the BACKSPACE key is useless to correct it; you will only get strange error messages if you try. This is because the system does not yet understand what kind of terminal you are using and cannot interpret such commands. If you make an error at either entry, press ENTER to accept the incorrect information and try again.

If you have entered the information correctly, the terminal will pause, blink a few times, and end with a prompt a few seconds later. (On some systems you may be asked what type of terminal you have. See your system administrator to see how you should answer this question.) The prompt you see probably consists of a dollar sign, space, and the cursor.

Congratulations; you're on the system.

Where am I?

The next step is to determine where you are. Like MS-DOS and other command environments, you are always positioned within a part of the file system during a session, but it may not be clear where you are. If you are a PC user, you might expect to see the current directory location in the prompt itself, but the Bourne shell is not capable of this trick.

To see your current directory location, type pwd (print working directory) and press ENTER. The system should respond with the directory - probably /usr/UID, where UID is your user ID. (On some systems this might be /users/UID or some other variation.) This is your home directory. Your home directory is a place where you can put personal files that is out of reach of other users and can also hold special configuration files unique to your needs. The slashes in the directory name indicate the position of that directory relative to the starting point in the file system. The information contained in this display (/usr/UID) gives directions to finding this position and is thus known as the path.

(If you are a PC user, you should have noticed by now that much of this syntax is similar to MS-DOS. Many UNIX commands were "borrowed" when the CP/M and MS-DOS operating systems were developed and have remained the same since. Differences include case-sensitive file and directory names, long file names, the use of forward slashes to indicate directories, and differences in command names.)

Listing file names

Your next task is to determine the files in this directory. Drawing on your PC experience, you type dir and press ENTER; the system responds with dir: not found and the prompt returns. The dir command lists files in the PC world; the corresponding command in UNIX is ls. Repeating this experiment, type ls and press ENTER; the contents of your home directory will be listed. The display is crude: only the file names will be listed. In some cases, you might not have any file names to list, so the prompt will return instead. Since you're interested in more than just the file names, how do you get more detail on the contents of this directory?

Almost all UNIX commands accept optional parameters that modify their operation. These are known as arguments. On UNIX systems arguments are often preceded with dashes to distinguish them from file names and other types of information. The ls command has many possible options, but we are interested in two: a more detailed listing of file contents (the long or verbose format) and a display of all files, including hidden files and directories. The format for this variation is ls -a -l or ls - al, which works the same. Translated, this means "list all the files in the current directory (-a) in long form (-l). This command produces a display that is considerably different from the ls command alone and probably different from anything you've seen before. (See Figure 1.) Hint: the file (or directory) names are located on the right, not where you'd expect on the left.

Note that the first "file" entries on this listing show names of a period and two periods respectively. These represent gateways to and from this directory. Like MS-DOS, UNIX directories are really a special form of file that contains the names of files and directories within it. The single period represents the file containing this directory's information; the double period, the directory above (/usr).

The next four files have periods as the first part of their name. In UNIX systems, these are hidden files and will not be displayed with the ls command. Remember the -a we added to display all files? The next file has an unusual name (a.FILE.name) that illustrates how UNIX file names can be long, have mixed case, and are not required to fit a format like that of MS-DOS (eight characters, a period, and a three-character extension). Note that A.file.NAME, A.file.name, and a.FILE.NAME are also valid file names and are not the same file.

Next on the list is a directory named Mail. How do we know it's a directory? At the far left of the listing you will see a series of letters and dashes: this is the file protection mode, which also lists whether the entry is a file, directory, or other type. Looking down the list, you can see that entries with a d are directories, while the dash indicates a file.

Additional information in this listing includes a measure of space, the owner's initials and group identification, the number of characters, and the date and time last modified. More will be said about all of these items in the future.

If your home directory looked like mine and you entered an ls command without arguments, what would you expect to see? Any file or directory name that is not preceded with a period should show, but there will be no way to determine whether the names are for files or directories. That's why I normally use the -l argument when listing directories.

Listing files in other directories

Listing your own directory is useful, but it is also necessary to work from other parts of the file system. The ls command can also accept wildcard characters, like MS-DOS and some Wang VS utilities (BACKUP, FILEDISP, etc.). To list the contents of the /etc directory, type ls -l /etc/* and press ENTER. Your screen will display a long-form listing of the contents of the directory - a very large directory. This listing will race past your screen faster than you can read it. This example illustrates how UNIX treats your workstation as if it were a printer with unlimited paper. Almost all UNIX utilities exhibit this behavior.

There are many ways to slow down long screen listings. Like DOS, UNIX recognizes a CONTROL-S as a command to halt a listing and CONTROL-Q to continue. A better way is to send the contents of the screen into more, a utility designed to display files one page at a time. To use more, type ls -l /etc/* | more and press ENTER; now the display stops when the screen is full and waits for you to press the space bar for the next screen. Much more civilized.

How does this work? The vertical bar (|) tells the system to pipe the output from the ls command to the input of the more program. This illustrates how UNIX (and DOS) can direct the output stream from one program into the input stream of another - a very powerful feature. (To try this example on a PC, type dir *.* | more at the prompt.)

Displaying the contents of files

Once you've discovered the contents of a directory, how do you display a file? If you were using a Wang VS, you'd probably run the DISPLAY utility and enter the name and location of the file. In the UNIX world, there is nothing comparable to DISPLAY - primarily because UNIX does not understand file types. In UNIX philosophy, support for indexed records and other application- related data formats is the responsibility of the application designer; therefore, the operating system does not record such information. UNIX systems do offer a command - file - that attempts a guess as to a file's content, but it cannot discern more than a handful of file types.

Most VS users are steeped in a tradition of indexed file usage for many purposes, including system tasks, so the fact that there is no direct indexed file support may be a shock. One of the results of this situation is that all system information is contained in delimited text files - consecutive files with variable-length fields separated by a character, space, or tab. This is one of the reasons UNIX has a large selection of tools for manipulating text files: there are a large number of text files to manipulate.

Take an extreme example: the passwd file, located in the /etc directory, is the equivalent of the USERFILE on the VS. It lists valid user IDs and names, their passwords, and their starting environment. In the VS, this is an indexed file with the user ID as the key, and is accessible only to the operating system and System Security Administrators. The UNIX passwd file is a text file and can be read (but not modified) by anyone. To prove this, let's display the file.

The cat command (short for concatenate) reads text files and dumps their contents to the screen. We can use it here to display the passwd file. Type cat /etc/passwd | more and press ENTER. You're now looking at the primary security file for the entire system - passwords and all!

Before you get too alarmed I should note that password field appears as encrypted text in this file. De-encryption programs are rumored to exist, but the primary manner that computer hackers get into systems remains the same: poor password choices, employees sharing their password and account information with others, and terminals left unattended. We'll be looking carefully at security issues in the months to come.

That's all for this month. Type exit and press ENTER to log off the system; the login: screen should reappear.

UNIX Bookshelf

Beginning this month, I will include a short listing of a relevant UNIX book to help direct you to some of the many good books on UNIX. Unfortunately, no single book yet exists that covers enough of UNIX to replace all others, so plan to spend a bit of money on books.

Please forward your questions and comment to me via mail, telephone, or through CompuServe at 72762,3475.

Exploring the UNIX System (Second Edition)
Stephen G. Kochan and Patrick H. Wood
Hayden Books, Carmel, Indiana; 1991

A good general introduction to UNIX. Assumes that a UNIX system is available for practice exercises, but presumes no prior experience with any operating system. Light coverage of shell programming, the vi editor, utilities, communications, program development, and system administration. First in the Hayden Books UNIX System Library series.

Figure 1: Sample Unix Directory Listing

total 208
drwx------  15 dsb      dp           2048 Jul 11 10:21 .
drwxr-xrwx  163 sys      sys         6144 Jul  8 10:59 ..
-rwxr--r--   1 dsb      dp           748 May  4 05:48 .alias
-rw-r--r--   1 dsb      users        360 Oct 21  1992 .exrc
-rw-r--r--   1 dsb      dp             0 May 13  1992 .news_time
-rw-rw-r--   1 dsb      dp           922 Jul 11 10:48 .profile
-rwxr--r--   1 dsb      dp            12 Jun  4 07:18 a.FILE.name
drwx------   2 dsb      mail          64 May 21  1992 Mail
drwxrwxrwx   2 dsb      dp          1024 Jun  7 23:01 scripts
drwxrwxr-x   2 dsb      users      44032 Jul  9 18:34 temp
-rwxrw-r--   1 dsb      users        748 Jun  4 07:18 userfile
drwxrwxr-x   2 dsb      users       1024 Jul  9 14:34 work

  [ Prior Article ]     [ Return to the Catalog of articles ]     [ Next Article ]  

Copyright © 1993 Dennis S. Barnes
Reprints of this article are permitted without notification if the source of the information is clearly identified