UNIX INTRODUCTION

By Charles Severance

This section is designed to give the beginning user a sense of the user interface to UNIX.

The user interface discussion is broken into the following areas:

GENERAL INTERFACE ISSUES

UNIX is a line-oriented system similar to MS-DOS and VMS. Each command to the operating system is terminated by the "return" or "enter" key.

UNIX uses the ASCII character set and supports upper and lower case. UNIX is the only widely used operating system which respects upper and lower case. The disadvantage of using both upper and lower case is that commands and file names must be typed in the correct case. Most of the UNIX commands and file names are in lower case. This is different from VMS and MS-DOS where everything is mapped into upper case.

UNIX does not use or directly support function keys. Special functions are generally invoked using the CONTROL KEY. For example a running command can be aborted by pressing the CONTROL key (sometimes labeled "CTRL") and the letter C. The short form for this is generally CTRL-C or ^C.

Using control keys instead of special function keys is sometimes difficult for users to remember at times. The advantage of using control keys for special commands is that nearly every terminal and terminal program supports the control keys allowing UNIX to be used from a wide variety of different terminals.

Some editors and applications provide a full screen user interface on certain terminals.

UNIX FILE SYSTEM

Throughout this document the UNIX user interface has been characterized as less friendly than many other operating systems. However in the area of file systems, UNIX is clearly (in my opinion) the simplest and easiest file system to use today.

UNIX is the precursor of many of the tree structured file systems of today including MS-DOS, VMS, and Macintosh. These file systems all consist of a tree of directories and sub-directories. There are commands (or mouse clicks) which allow you to move about the directory structure. These commands are generally quite similar between systems. In UNIX these commands are as follows:

  cd or chdir - change directory
  pwd - print working directory
  mkdir - make a new directory
  ls - list the contents of the directory (like dir in MS-DOS)

In any tree structured file system the concept of where you are at in the tree is very important. There are two types of file references which can be done. You can refer to a file relative to the current directory or refer to a file by its complete name. When the complete name of a file is given the current position in the directory tree is ignored.

When a user logs in to the system, they are placed into their "home directory". When an account is created, the home directory is created and associated with the account. To find the name of the home directory simply type 'pwd' after you log in:

   login: example
   Password:

$ pwd /usr/example $

To list the files in your home directory, you use the 'ls' command. There are many options to the ls command which you can look at by typing 'man ls'. The most useful options are the '-l' option and the '-a' options. The command 'ls -l' will list the files and directories in your current directory with extended information. A UNIX convention is that files with the first character are not listed by the ls command unless the '-a' option is given. This convention has lead to a number of special configuration files having periods as the first character of the name. You may also create files beginning with a period if you do not want them to show up in a normal ls command. The following are several examples of the ls command:

   $ ls
   fileone     two      proj1
   $ ls -l 
   -rw-------  1 example     10028 Sep 26 11:00 fileone
   -rw-rw----  1 example       281 Oct  5 14:21 two
   drwx------  2 example       638 Aug 21 17:27 proj1
   $ ls -a
   .login      .cshrc    fileone     two      proj1
   $ 

In the output from the 'ls -l' the additional information regarding the file permissions, owner of the file, size, modification date and file name.

In the output from 'ls -a' the additional files '.login' and '.cshrc' are shown. Both of these files are executed when the user is logged in much like AUTOEXEC.BAT is executed when a MS-DOS personal computer is booted. The user can place commands in these files which can be used to customize each user's individual environment.

Sub-directories are generally used to group files associated with one particular project or files of a particular type. For example, a person might store all of their memorandums in a directory called 'memo'.

The mkdir command is used to create directories and the chdir (or cd) command is used to move into directories. The pwd command can be used to keep track of the current sub-directory.

   $ ls
   fileone     two      proj1
   $ mkdir memo
   $ ls
   fileone     two      proj1    memo
   $ ls -l 
   -rw-------  1 example     10028 Sep 26 11:00 fileone
   -rw-rw----  1 example       281 Oct  5 14:21 two
   drwx------  2 example       638 Aug 21 17:27 proj1
   drwx------  2 example       638 Aug 22 14:47 memo
   $ pwd
   /usr/example
   $ cd proj1
   $ pwd
   /usr/example/proj1
   $ ls
   main.c     sub.c      a.out
   $ cat main.c
	  - contents of main.c -
   $ cd ..
   $ pwd
   /usr/example
   $ cat /usr/example/proj1/main.c
	  - contents of main.c -
   $ cat proj1/main.c
	  - contents of main.c -
   $ cat main.c
   main.c not found.
   $

At the end of this example, the 'cat' command is used to show the use of relative and absolute file names. The first cat command shows the contents of main.c in the sub-directory proj1 of user example's home directory. This reference is a relative reference because it does not start with the slash (/) character. The command cd can be given the parameter of two dots to indicate to go back up to the parent of the current directory. After the 'cd ..' command the pwd shows that we are "back" in the home directory.

The next cat command shows the use of an absolute file name which starts with a slash. This cat succeeds because the file name is completely specified as the complete path name and the file name. The following command 'cat proj1/main.c' also succeeds because relative to the home directory, the sub-directory and file name are correctly specified.

The command 'cat main.c' in the home directory does not find the file stored in the sub-directory.

The UNIX file system is one of the simplest tree structured file systems to use. There are no syntax extensions for accessing system files, files belonging to other users, or files on network mounted file systems. The file system is one place where UNIX has a more friendly user interface than most systems.

Other file system commands:

  rm - remove a file
  mv - rename a file or group of files
  cp - copy a file to another file or a set of files into a directory

YOUR LOGIN ENVIRONMENT

Nearly all operating systems have some way to customize your login environment by editor configuration files. On UNIX there is a file which is executed for every login called '.login'

An example .login follows:

   $ cd
   $ pwd
   /usr/example
   $ cat .login
   set path=(/usr/local/bin /usr/ucb /bin /usr/bin )
   set term=vt100
   $

The cd command without any parameters generally moves you to your home directory. This example .login file contains two set commands to set "environment variables". The first variable is 'path'. This variable specifies where programs are located. The second variable is the terminal type for the session. In this example, the terminal type is set to a vt100 terminal. To find a list of the valid terminals, ask your system administrator.

Another interesting way to find a list of terminals is in the section titles "LEARNING ABOUT OPERATING SYSTEMS USING UNIX".

USING THE UNIX EDITOR

The UNIX editor is called 'vi' which stands for visual editing. Most people find vi a very difficult editor to learn compared to many of the microcomputer based editors today.

If you end up frustrated using vi, do not assume that it is because your lack of skill. You will eventually figure it out and become somewhat proficient at using it. There is no on-screen help or nice keyboard templates you just have to remember the control sequences for the various commands.

One very easy way to learn about vi is to use the 'learn' command available on some systems.

This is not a complete training on the use of the editor just a survival quide. The most important thing to remember about vi is that it has three "modes" a "move around mode", an "edit mode", and a "command mode".

-------------------------------------------------------------------------------
|                              Vi Survival Guide                               |
+------------------------------------------------------------------------------|
|vi filename    | How to start up vi. Good luck!                               |
----------------+--------------------------------------------------------------
|ESC ESC CTRL-L | Panic.  Usually fixes things up.                             |
+------------------------------------------------------------------------------|
|ESC            | Gets you out of insert mode.  Does nothing  in  move  around |
|               | mode.  Gets you out of command mode.                         |
----------------+--------------------------------------------------------------
|CTRL-L         | Redisplays the screen                                        |
+------------------------------------------------------------------------------|
|Arrow keys     | Move you around if your terminal is set up right.            |
----------------+--------------------------------------------------------------
|k              | Up one line (Move mode)                                      |
+------------------------------------------------------------------------------|
|CR             | Down one line (Move mode)                                    |
----------------+--------------------------------------------------------------
|CTRL-H         | Left one space (Move mode)                                   |
+------------------------------------------------------------------------------|
|space          | Right one space (Move mode)                                  |
----------------+--------------------------------------------------------------
|$              | Move to the end of the line (Move mode)                      |
+------------------------------------------------------------------------------|
|0              | Move to the beginning of the line (Move mode)                |
----------------+--------------------------------------------------------------
|10G            | Go to line 10 (Move mode)                                    |
+------------------------------------------------------------------------------|
|0G             | Got to the last line in the file (Move mode)                 |
----------------+--------------------------------------------------------------
|i              | Begin inserting just before the character the cursor is  on. |
|                 Finish with ESCAPE. (Move mode)                              |
+-----------------------------------------------------------------------------|
|a              | Begin inserting just after the character your cursor is  on. |
|               | Finish with ESCAPE.                                          |
+---------------+--------------------------------------------------------------
|ESCAPE         | Terminates insert mode                                       |
+------------------------------------------------------------------------------|
|dd             | Deletes the line your cursor is on                           |
+---------------+--------------------------------------------------------------
|d SPACE        | Deletes the character your cursor is on.                     |
+------------------------------------------------------------------------------|
|dw             | Deletes the word your cursor is on.                          |
----------------+--------------------------------------------------------------
|d10d           | Deletes 10 lines starting from the line your cursor is on.   |
+------------------------------------------------------------------------------|
|u              | Undoes your last edit.                                       |
----------------+--------------------------------------------------------------
|cw             | Changes the current word you are on.  Terminate with ESCAPE. |
+------------------------------------------------------------------------------|
|r character    | Replaces the character directly under the cursor.            |
----------------+--------------------------------------------------------------
|R              | Goes into replace mode.  Allows you to type over characters. |
|               | Terminate with ESCAPE.  Cursor movements are not allowed.    |
+------------------------------------------------------------------------------|
|:wq CR         | Command mode.  Write the file and quit.                      |
----------------+--------------------------------------------------------------
|:w CR          | Command mode.  Write the file and stay.                      |
+------------------------------------------------------------------------------|
|:q CR          | Command mode. Quit the file if no changes.                   |
----------------+--------------------------------------------------------------
|:quit! CR      | Command mode. Quit the file and abandon changes.             |
+------------------------------------------------------------------------------|
|ESCAPE         | Terminates command mode. Does not execute command.           |
-------------------------------------------------------------------------------

UNIX COMMANDS

This section will list a number of UNIX commands and key strokes in the following categories:

GENERAL COMMAND SYNTAX

The general command syntax is a command followed by some options, and then some parameters. If a command reads input, the default input for the command will generally come from the interactive terminal. The output from a command (if any) will generally be printed out on the users terminal.

The command syntax allows the input and outputs for a program to be redirected into a file or the output of one program can be passed as the input to another program.

General command syntax is as follows:

  cmd
  cmd -options
  cmd -options parameters

To cause the program to read from a file rather than the terminal, the < sign is used on the command line:

  cmd -options parameters < input 
  cmd -options parameters > output
  cmd -options parameters < input > output

To cause the output from one program to be passed to another program as input the vertical bar (|) is used.

  cmd -options parameters | cmd2

This feature is called "piping" the output of one program into the input of another. Several useful examples of this are shown in the example commands.

The following are some examples of the ls command showing the different command formats:

  ls
  ls -la
  ls -la mydat
  ls -la | more
  ls -la /etc > tmpout
  more < tmpout

THE USE OF WILDCARDS AS FILE PARAMETERS

Generally when a UNIX command expects a file name such as the more command:

     more filename

it is possible to specify a group of files using one or more wild card expressions.

Unlike other operating systems UNIX allows wild cards on any command. The reason for this is that wild cards are processed by the operating system and not the individual program.

The special characters which cause wild card searching to be performed are as follows:

    * Matches any string of characters zero or longer
    ? Matches any single character

The following are some examples of commands using wild card characters:

   more dat*
   more d?t
   more ???crs
   more */*.c
   more */raisememo

The second to last example will search all sub-directories in the current directory for files ending in '.c' and show you those files. The last example will search all of the sub directories in the current directory for files named raisememo and show you the files, pausing between each file.

A very useful command which allows searching through many files for a pattern is the grep command. The first parameter to grep is a search pattern. If no files are specified, grep will scan its "standard input" for lines containing the pattern and write them to output. You may also specify a list of file names on the grep command. For example if you had a bunch of different C programs in several sub-directories and wanted to find the one which called the fopen subroutine, you could use the following command:

   grep fopen */*.c

Wild cards are more flexible in UNIX than any other operating system. This flexibility makes them more powerful but you must also be careful not to when using them in potentially destructive commands such as rm (remove file).

UNIX COMMANDS AND KEYSTROKES

The following table contains a list of the important key strokes used in UNIX.

-----------------------------------------
|         Important key strokes          |
+----------------------------------------|
|CTRL-D | Log off the system             |
--------+--------------------------------
|CTRL-C | Abort a running process        |
+----------------------------------------|
|CTRL-Z | Stop a running process         |
-----------------------------------------

The following commands allow you to access on-line documentation and tutorials.

-----------------------------------------------
|Commands to get information about the system  |
+----------------------------------------------|
|man ls       | Gets you a manual page on  the |
|             | ls command.                    |
--------------+--------------------------------
|man -k batch | Gets you the title  lines  for |
|             | every  command  with  batch in |
|             | the title.                     |
+----------------------------------------------|
|learn        | Runs a number of tutorials  on |
|             | the  file  system, editor, and |
|             | other areas.  Does not run  on |
|             | all systems.                   |
-----------------------------------------------

Thenext table lists some common commands to change your personal setup.

--------------------------------------------
|  Commands to change your personal setup   |
+-------------------------------------------|
|passwd    | Change your log in password    |
-----------+--------------------------------
|vi .login | Command   to    change    your |
|          | automatic login script.        |
--------------------------------------------

The following table allows you to look at what is happening on the syste,

-------------------------------------------------
|     Looking at the system and other users      |
+------------------------------------------------|
|uptime         | Shows  the  time   since   the |
|               | system   was   last  rebooted. |
|               | Also shows the "load average". |
|               | Load   average  indicates  the |
|               | number of jobs in  the  system |
|               | ready  to run.  The higher the |
|               | load  average  the  slower   a |
|               | system will run.               |
----------------+--------------------------------
|who            | Shows who is logged on to  the |
|               | system.                        |
+------------------------------------------------|
|w              | Shows who is logged in to  the |
|               | system   and   what  they  are |
|               | doing.                         |
----------------+--------------------------------
|ps             | Shows your processes.          |
+------------------------------------------------|
|ps -aux        | Shows all of the processes  on |
|               | the  system  in  a long format |
|               | with the user name  associated |
|               | with  the  process sorted from |
|               | the  heaviest  user   to   the |
|               | lightest user.                 |
----------------+--------------------------------
|ps -aux | head | Shows    the    15    heaviest |
|               | processes.                     |
+------------------------------------------------|
|finger user    | Gets  information  about   the |
|               | user.                          |
-------------------------------------------------

The following table is a summary of the commands which affect the file system and access files.

--------------------------------------------------------
|                 File system Commands                  |
+-------------------------------------------------------|
|ls                    | Shows your files.              |
-----------------------+--------------------------------
|ls -l                 | Shows your files  in  extended |
|                      | format      including     file |
|                      | size,ownership,            and |
|                      | permissions.                   |
+-------------------------------------------------------|
|ls -la                | Shows  all   of   your   files |
|                      | including  the system files (. |
|                      | files) in your account.        |
-----------------------+--------------------------------
|du                    | Shows the file usage for  your |
|                      | current directory.             |
+-------------------------------------------------------|
|cat filename          | Shows the contents of  a  file |
|                      | at your terminal.              |
-----------------------+--------------------------------
|more filename         | Shows  the  contents  of  your |
|                      | file  at  the terminal pausing |
|                      | to allow you to press space to |
|                      | continue.    Good   for  large |
|                      | files.                         |
+-------------------------------------------------------|
|head filename         | Shows the first few lines of a |
|                      | file.                          |
-----------------------+--------------------------------
|tail filename         | Show the last few lines  of  a |
|                      | file.                          |
+-------------------------------------------------------|
|grep pattern filename | Show the  lines  in  the  file |
|                      | which  contain  the  specified |
|                      | pattern.                       |
-----------------------+--------------------------------
|wc filename             Counts    the    number     of |
|                      | characters  words and lines in |
|                      | a file.                        |
+-------------------------------------------------------|
|cp file1 file2        | Copies file1  to  file2.   Any |
|                      | previous contents of file2 are |
|                      | lost.                          |
-----------------------+--------------------------------
|lpr -Pprinter file    | Prints the specified  file  on |
|                      | the specified printer.         |
+-------------------------------------------------------|
|mv file1 file2        | Renames file1 to file2.        |
-----------------------+--------------------------------
|mv file directory     | Moves the specified file  into |
|                      | the     specified    directory |
|                      | keeping  the   original   file |
|                      | name.                          |
+-------------------------------------------------------|
|rm filename           | Removes a file.                |
-----------------------+--------------------------------
|chmod perm file       | Changes the permissions  of  a |
|                      |   file.    See   man  chmod  for
|                      |   details.                     |
+-------------------------------------------------------|
|pwd                   | Print    Working    Directory. |
|                      | Shows  you where you are at in |
|                      | the file system.  Very  useful |
|                      | when you get confused.         |
-----------------------+--------------------------------
|mkdir directory       | Makes  a  directory  in   your |
|                      | current directory.             |
+-------------------------------------------------------|
|rmdir directory       | Removes a  sub-directory  from |
|                      | your     current    directory. |
|                      | Directory  must  be  empty  to |
|                      | remove the directory.          |
-----------------------+--------------------------------
|rm -r directory       | Removes  all  the  files,  and |
|                      | subdirectories  of a directory |
|                      | and    then    removes     the |
|                      | directory.   Very  convienent, |
|                      | useful and dangerous.          |
+-------------------------------------------------------|
|cd                    | Move  back  into   your   home |
|                      | directory.                     |
-----------------------+--------------------------------
|cd directory          | Move  into  a  directory  from |
|                      | your current directory.        |
+-------------------------------------------------------|
|cd /tmp               | Move    into    a    directory |
|                      | regardless   of  your  current |
|                      | directory.                     |
--------------------------------------------------------

The following commands provide simple access to networking capabilities in UNIX.

--------------------------------------------------------------
|                    Networking commands                      |
+-------------------------------------------------------------|
|grep string /etc/hosts      | Look up in the hosts file  for |
|                            | host  names with the specified |
|                            | string in their name.   Useful |
|                            | for  finding  host names which |
|                            | you have forgotten.            |
-----------------------------+--------------------------------
|ftp host                    | Files    transfer    protocol. |
|                            | Allows   a   limited   set  of |
|                            | commands.  ( dir cd put get  ) |
|                            | help gives help.               |
+-------------------------------------------------------------|
|telnet host                 | Connects to  another  ethernet |
|                            | connected host.                |
-----------------------------+--------------------------------
|mail                        | Allows you  to  read,  delete, |
|                            | and  reply  to  your  incoming |
|                            | mail.                          |
+-------------------------------------------------------------|
|mail user@host              | Mails   a   message   to   the |
|                            | specified  user.   The message |
|                            | is terminated by CTRL-D.       |
-----------------------------+--------------------------------
|talk user                   | Allows you to have an  on-line |
|                              full    screen   dialog   with |
|                            | another user  on  the  system. |
|                            | Talk  may also be able to talk |
|                            | between  systems.   The   form |
|                            | talk   user@host  is  used  in |
|                            | these cases.                   |
+-------------------------------------------------------------|
|rlogin host                 | Connects to the specified host |
|                            | and  logs  you on.  Similar to |
|                            | telnet but used where a  group |
|                            | of  systems  are being treated |
|                            | as   a   single    distributed |
|                            | system.                        |
-----------------------------+--------------------------------
|rcp hosta:filea hostb:fileb | Copies  the  specified   filea |
|                            | from  hosta to fileb on hostb. |
|                            | Requires special security.     |
+-------------------------------------------------------------|
|rsh host command            | Executes the specified command |
|                            | on the remote host sending the |
|                            | command input from the current |
|                            | host.  The output is sent back |
|                            | to the  current  host  as  the |
|                            | standard  output  of  the  rsh |
|                            | command.                       |
-----------------------------+--------------------------------
|rexec host command          | Similar to rsh.                |
+-------------------------------------------------------------|
|mount filesystem            | Mount a NFS file system at the |
|                            | designated     mount    point. |
|                            | (System managers only)         |
+-------------------------------------------------------------|
|umount filesystem           | Unmount  a  NFS  file  system. |
|                            | (System managers only)         |
--------------------------------------------------------------

All of these commands have on-line documentation available through the man pages.

LEARNING ABOUT COMPUTERS USING UNIX

One interesting aspect of UNIX which is different from many operating systems is that ordinary user can type the system administrator commands and look at system configuration information. Ordinary users generally cannot change the system configuration files but it is often interesting looking at system configuration files.

Nearly all of the system configuration information is available to ordinary users and man pages are included.

This is one of the reasons that UNIX is very popular as a tool for teaching how operating systems work. This also simplifies the work of system administrators because the system administration tools are often just the normal text editor.

The following are just some examples of the things which a normal user can do looking at the system configuration files. These techniques are only shown to raise your curiousity about the UNIX system administration.

Don't be concerned if the information you look at seems confusing. Experienced system managers often have to look at the man pages for some of the formats of the configuration files.

FINDING A LIST OF VALID TERMINALS

In a previous section on the login environment, the way to find the available terminal types was simply to "call the system administrator".

Another interesting way to find a list of terminals is to type the command:

  $ more /etc/termcap

The more command will display a file pausing each 24 lines to allow you to read the screen full of text before showing the next 24 lines of text. Pressing space advances the display and entering 'q' or 'CTRL-C' will stop the display.

This will show you the internal configuration file the system administrator uses to define the different terminals which are supported. Don't expect to understand the entire format of this file but you may be able to pick out the terminal names from the file. If you want to learn more about this file you can type 'man termcap'.

FINDING A VALID PRINTER NAME

The technique for finding a valid printer name is similar to the previous technique except that the file which is viewed is '/etc/printcap'.

  more /etc/printcap

This file specifies the locally attached and remote printers available to users using the lpr command. Like the termcap file printcap also has a man page detailing its format.

FINDING A NETWORK HOST NAME

Suppose you want to find the name of a network host but you only remember that is is from the University of California at Berkeley.

The grep command can be used to scan the file /etc/hosts for all hosts with 'berk' as part of their name with the following command:

  grep berk /etc/hosts | more

By piping the output of grep into more, if there are more than 24 hosts at Berkeley (which there are) the screen will pause after each 24 lines waiting for you to press return.

LEARNING ABOUT FILE SYSTEMS

In UNIX all of the files are part of the same file tree starting at the root directory. Although it is not necessary from a user perspective to understand just how the file system is put together, users who are curious might find the command 'df' and the contents of the file /etc/fstab interesting.

The file /etc/fstab contains the different disks and remote mounts which make up the system disk system. The df command shows the currently active portions of the file system.

OTHER FILES WHICH YOU MIGHT FIND INTERESTING

The following is a list of system administrator files which you might look at if you are curious. Each has an associated man page.

  /etc/passwd
  /usr/lib/sendmail.cf
  /usr/lib/aliases
  /etc/rc

On small systems, the owner often acts as the system administrator and must actually modify these files.

CONCLUSION

This document is intended to give you some perspective on the UNIX system and guide you toward learning more about the UNIX system.

You must understand that UNIX is not the easiest computer system to learn. Have patience, ask questions, and don't get down on yourself just because it doesn't seem as easy as other computer operating systems. The power and flexibility of UNIX is worth the extra effort.

UNIX still has a long way to go before it becomes the "operating system of the future". But for more and more computing environments today, UNIX is becoming the operating system of the present.

Have a great time.


Press here to return to the Basic Unix Help Menu