Introduction to UNIX

UNIX is one of the standard operating systems (OS) for computers in scientific, engineering and research environments. By operating system, we mean the suite of programs which make the computer work. UNIX is used by the workstations and multi-user servers. It is the only major OS not irrevocably tied to a specific hardware architecture: there are version of UNIX for virtually any possible hardware. There are several versions of the UNIX system, which are in fact not so different on the user level. In our lab we use the Solaris OS developed by SUN Microsystems, Inc.

Most UNIX systems support the graphical user interface (GUI) provided by the X Window System. However, knowledge of UNIX is required for operations which aren't covered by a graphical program, or for when there is no X windows system available, for example, in a telnet session from a remote computer.

In our lab we use the UltraSpark and SunBlade workstations (SUN Microsystems, Inc). Please, take into account the following

IMPORTANT NOTES:

1. NEVER TURN OFF ANY OF SUN WORKSTATIONS OR MONITORS AFTER YOU FINISH YOUR UNIX SESSION. COMPUTERS AND MONITORS SHOULD STAY TURNED ON ALL THE TIME.

2. IF YOU ENCOUNTER ANY UNUSUAL PROBLEM DURING YOUR UNIX SESSION, DO NOT TRY TO FIX IT BY YOURSELF (BY REBOOTING, ETC.). ASK YOUR INSTRUCTOR OR TA FOR HELP.

The UNIX operating system

The UNIX operating system is made up of three parts; the kernel, the shell and the programs.

The kernel

The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs and handles the filestore and communications in response to system calls.

The shell

The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell. The shell is a command line interpreter (CLI). It interprets the commands the user types in and arranges for them to be carried out. The commands are themselves programs: when they terminate, the shell gives the user another prompt.

As an illustration of the way that the shell and the kernel work together, suppose a user types rm myfile (which has the effect of removing the file myfile). The shell searches the filestore for the file containing the program rm, and then requests the kernel, through system calls, to execute the program rm on myfile. When the process rm myfile has finished running, the shell then returns the UNIX prompt to the user, indicating that it is waiting for further commands.
 

The adept user can customise his/her own shell, and users can use different shells on the same machine.  Students have the csh shell by default.
 

Files and processes

Everything in UNIX is either a file or a process.

A process is an executing program identified by a unique number called PID (process identifier).

A file is a collection of data. They are created by users using text editors, running compilers, programs, etc.

Examples of files:

The Directory Structure

All the files are grouped together in the directory structure. The file-system is arranged in a hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally called root.

The Unix file structure

In the diagram above, we see that the directory ee51ab contains the subdirectory unixstuff and a file proj.txt
 

A  Work Session with Solaris

To start session you must first log in using a graphical login screen (Figure 2).
 

Figure 2.
 

In order to access the system, you need to enter your  login name in the text field and hit [Return]. The prompt will change and ask you for your password. Enter your password in the text field and hit [Return].

Your UNIX account is configured in such a way that the Open Windows (OW) GUI will start authomatically after you entered your loginname and password. Otherwise you would have to enter the command <ow> to start it. A typical desktop environment is shown in Figure 3.

   Figure 3.
 
 

To finish your work with the OpenWindows and Solaris click right button on the mouse. A menu will appear (Figure 4). Put the pointer on EXIT and click either left of right button. A confirmation prompt will appear. Confirm your wish to exit.

   Figure 4.

NOTE: If you are working from a remote computer (for example, using a telnet session), then you are not able to use the Open Windows or any other GUI. In other words you can only interact with the OS using the command line. In this case, to finish your session you have to use the command <logout>.

Example:  prompt% logout [Return]
 
 

UNIX Commands: General Information


To be able to enter UNIX commands in the Open Windows desktop you need to open a terminal window (called Command Tool or Shell Tool). To do this click the right button on the mouse anywhere on the free-of-icons desktop space. A pop-up menu Workspace will appear (Figure 5). Then place the arrow on the Programs and click the right button again. A submenu Programs will appear (Figure 5).

    Figure 5.
 
 

Then move the arrow to Command Tool... (or Shell Tool...) and click the left button on the mouse. A command tool window will appear (Figure 6).

     Figure 6.
 

This window contains a command line prompt you can use to enter your commands.

UNIX distinguishes between upper and lower cases, i.e. passwd and Passwd are not the same. The most of UNIX commands are in lower case. For example, if you type the command Passwd instead of passwd you will get an error message:

Passwd : Command not found
 

Detailed information about the usage of any UNIX command can be obtained from their manual pages. To access a manual page you should use the command man. For example, if you want to obtain information about the command passwd you must type :

prompt% man passwd

The information about the command will appear on the screen (Figure 7). Often such documents contain more than one page. To go to the next page press SPACE button.

    Figure 7.

Notes about your password

You may want to change a password you are given from a system administrator. To do this use the command passwd.
For security reason your new password must contain no less than 8 symbols and should include digits and special symbols (like %#*&, etc.).

Example:

prompt> passwd
passwd: Changing password for yourloginname
Enter login password: (Enter your current password) [Return]
Enter new password: (Enter your new password) [Return]
Re-enter new password: (Enter your new password again) [Return]

Try to remember your password and not to write it on the computer desk or any place else. Never tell your password to anybody!
 
 

How to work with files

When you logged in you are in your home directory: /u/yourloginname. At any time during your UNIX session you can find out your location in the file system using the command pwd (print working directory). Example:

  Figure 8.

You are in alexei's home directory.
 

You are permitted to create new directories and regular files in your home directory. To create a directory use the command mkdir (make directory). For example if you want to create a new directory called "my_project", you type:

  Figure 9.

You also can create a new directory using the Open Windows' File Manager program.

There are many different ways to create regular files such as text files, images, programs, etc. You can use the File Manager. If you work from a command prompt and you need to create a new text file,  you can type cat > newfilename [Return], and then Control+D.  File and directory names cannot have any spaces in them, so if you want to separate words, use periods or underlines (e.g. file.name or file_name). Do not use the following special symbols / \ & ? < > | [ ] * ;

To see a list of files in your current directory use the command ls (list). It will give you a short list. For more detailed information use the following usage: ls -l. See example in Figure 10.

  Figure 10.

You see that the directory you just created is listed, too.
 

Now let's go through the meaning of columns of the long (detailed) listing output.

drwxr-xr-x    1  alexei   staff        732     Oct 30  1997     mkinstalldirs
-rw-r--r--    1  alexei   staff      10483     Oct 30  1997     props.c
-rw-r--r--    1  alexei   staff        179     Oct 30  1997     props.h
-rw-r--r--    1  alexei   staff      10572     Aug 27 18:59     props.o

(permissions)   (owner)  (group)    (size)    (date and time   (filename)
                                               of last change)
The letter d in the first line
means directory

The first column show file permissions. The three basic operations on a file are "read", "write" and "execute". The permissions required to perform these operations are denoted by "r","w", "x". The "x" permission is needed for compiled programs and for any shell script (command file) that you intend to use directly as a executable command. For example, the file cls (in the previous figure) is executable and can be run by alexei only.
The "r","w" and "x" permissions can be specified independently for the owner of a file ("u") , for users in the owner's group ("g"), and for all other ("o"). To change permission use the command chmod. Note, you can only change permissions for the files created by you.

Example:

prompt% chmod u+x filename [Return]

You made the file filename executable (x) for owner (u). Group and others are denoted by "g" and "o", respectively.
 
 

To travel around the file system use the command cd (change directory).  Its usage is:

prompt% cd <path to folder where you want to go>.

For example, to go into the new directory called my_project, type cd my_project (Figure 11).

  Figure 11.

The command ls was used to check the content of the directory. It is empty because we did not create any file inside this directory.
 

Other commands for operating with files are:
cp - to copy files,
mv - to move files,
rm - to delete files.
cat or more - to direct a file content on the screen.

Detailed information about these commands can be obtained from the UNIX books in Room 203, from the manual pages, and from the links provided in EES254 webpage (http://www.earth.rochester.edu/ees254/lab1.html).
 

Editing Files

Editing files is one of the most important and common procedures you will perform. UNIX has several editors (vi, joe etc.) you can use in the command line mode. In the OpenWindows desktop you can use textedit program. To start this program type :

prompt% textedit <name_of_the_file>.

Alternatively you can use the Programs menu, the same way as we discussed before to start the Command Tool.

Executable command files (scripts) can be also edited by textedit tool.
 
 

Working with images

During the course you will work with image files generated by ArcView or GMT. These files may be in different formats (such as Postscript, Jpeg, Tiff, etc.). To view and print these images you can use either pageview or imagetool commands. Both commands will open a window containing the image.

Example:

prompt% imageview image.ps & [Return]

(To learn why the ampersand symbol is used at the end see the section "More About Commands" below.
 
 

How to print


All the workstations are connected to a laser postscript printer. To print your text or image file use the command lp <yourfilename>.

Example:

prompt% lp image.ps
 

Many files can also be printed directly from application programs such as textedit, pageview, or imagetool.
 
 
 

More about commands


1. If you start a command or a program from the command line, you cannot use the command line again until the previous command (program) is finished. To be able to work with the command line while your program is running, you need to use a background mode. To do this add the symbol & after the command name.

Example:

prompt% textedit & [Return] (text editor window will appear)
prompt% (ready to accept new command)
 
 

2. You can redirect the output of any command to a specified file instead of a terminal window by using > symbol. The format of a command line that redirects output follows:

command [arguments] > filename

Example:

prompt% cat progr.f > myfile  (the content of the file "progr.f" will be directed into the file "myfile")

Using >> instead of > will append the output to the end of the file instead of replacing its content.

NOTE: This method is used in GMT-scripts to create postscript images. So it is very important to understand the difference between > and >> to be able to successfully work with GMT-scripts.

Standart output of a command (a program) can be directed into the input of another program by using symbol | (pipe). This feature of UNIX is also often used in GMT-scripts.

Example:

prompt% cat progr.f | lp

[the content of "progr.f" (output of the cat command) will serve as the input of the lp command. As a result the "progr.f" content will be printed]
 
 

Electronic mail and remote access


As far as you have a UNIX account (login name) in our computer system you can receive and send electronic mail. Your e-mail address is:

yourloginname@earth.rochester.edu

To read and to send e-mail you can use the Mailtool programof  the OpenWindows or the commands mail or mailx.  Also a very popular mail program is pine, which can be started for the command line.

You can work with UNIX from a remote computer. It is important to realize that in this case you cannot use the advantages of the GUI and will have to use the command line.