Beruflich Dokumente
Kultur Dokumente
Introduction
toUNIX
LEARNING OUTCOMES
By the end of this topic, you should be able to:
1.
2.
INTRODUCTION
This topic introduces you to the UNIX environment. These skills and knowledge
are important for you to learn before proceeding to network programming. As
you may have no programming experience, the first section gives you a brief
introduction to the UNIX operating system and some important UNIX concepts.
After you explore essential background information about UNIX, you begin to
get access to UNIX in the second section, and we provide you with a brief
guided tour through UNIX.
1.1
In Figure 1.1, you can see the UNIX operating system represented as consisting of
three components:
Kernel,
Utilities, and
Shell.
TOPIC 1
INTRODUCTION TO UNIX
Shell
Utilities
Kernel
The kernel is the most hidden part of the operating system. It contains code
called drivers, which allow the system to control all of the system hardware, the
disk drives, the peripherals, and so on.
The next circle represents the system utilities and commands. When you run a
UNIX command (e.g. vi), it uses routines from the kernel to display output on
your screen, to get input from the keyboard, and to save files on the disk.
1.2
The outermost circle represents the UNIX shell. The shell is a program that
accepts commands from a user and starts the requested commands. The shell is
all that the user sees of the UNIX operating system: All you see is the outermost
shell layer and none of the complexity inside. A number of shell programs are
available on UNIX, and users can use their preferred, different shells at the same
time on one system. The Bourne, C, and Korn shells are usually available on most
commercial UNIX systems today. The Bash and tcsh shell are usually found on
Linux systems. In this course, you access a Linux Server to practise your
programming techniques. The Bash shell is chosen when the system
administrator sets up student user accounts. However, you can switch from one
shell to another by typing the shells name (such as sh or csh) on your command
line. You work in that shell until you log in again or type another shell name on
the command line.
TOPIC 1
INTRODUCTION TO UNIX
Table 1.1 shows the shells with the command used to invoke the shell, and a
description of the shell.
Table 1.1: List of UNIX shells
Shell Name
Bourne shell
C shell
Korn shell
Bash shell
tcsh shell
Command
sh
csh
ksh
bash
tcsh
Description
Available on all UNIX systems
Uses C programming-like syntax
A superset of the Bourne shell
Contains both C and Korn shell features
Works like the C shell
For a beginner, the differences between most shells are slight. You will have a
chance to practise working in the Bash shell environment and in Bourne shell
programming in a later topic.
1.3
Its time for you to log into the system and try some commands. This section
focuses on learning the basics of interacting with the UNIX computer. You will
learn how to:
1.3.1
Before you can start using UNIX facilities, you must have a user account. Think
of this account as your office its your place in the UNIX environment. In
addition to knowing what your account name is, you may need to know the
hostname (name) of the computer that has your account (i.e. unix.oum.edu.my
for this course).
To get into the UNIX environment, you first connect to a UNIX computer using
your OUMs username and password.
Note: Both login account name and password must be in lowercase. If you have
problems with the login account, please contact your tutor or OUM.
TOPIC 1
INTRODUCTION TO UNIX
The steps you take to connect to a UNIX system vary according to the kind of the
connection you use. The simplest connection is that of a user terminal directly
connected to a communications port on the UNIX computer. Alternatively, you
use the local area network on campus to connect to a remote UNIX computer.
You can also access the Internet through an Internet Service Provider (ISP) and
connect to a remote UNIX host. The following activity lets you practise this
connection procedure, using Telnet.
Telnet is a terminal emulation program for the Internet. It runs on your computer
and connects your PC to a host on the network. You can then log into a UNIX
host and begin working with UNIX. Each computer on the Internet has an
Internet Protocol (IP) address such as 202.40.157.138. Most systems on the
Internet also have a domain name such as unix.oum.edu.my. Both the IP address
and the domain name identify a system on the network. Programs such as Telnet
use IP addresses or domain names to access remote systems.
ACTIVITY 1.1
After your computer is connected to local area network on campus or has
a dial-up connection to your ISP, do the following:
1.
2.
TOPIC 1
3.
INTRODUCTION TO UNIX
4.
In the Host Name text box, type the server and domain name, i.e.
unix.oum.edu.my.
5.
6.
Type your username and password to log into the system. When you
log in successfully, you will get some system messages and then the
UNIX shell prompt (where you can enter UNIX commands). A
successful login to the system would look something like Figure 1.5:
TOPIC 1
INTRODUCTION TO UNIX
After you log in, you are ready to begin using the system.
7.
When you finish your days work or leave the terminal for any reason,
log out of the UNIX system. Logging out ends your current process
and indicates to UNIX that you have finished. How you log out
depends on the shell you are using. For the Bourne, Korn or Bash
shells, type exit on the command line, or press Ctrl-D (please refer to
Figure 1.6). In the C shell, type logout on the command line.
8.
When you finish your session, click Connect on the menu bar. Then
click Exit. The Telnet program ends your session and closes.
TOPIC 1
1.3.2
INTRODUCTION TO UNIX
Once youve logged in, youre working with a program called the shell. As
mentioned in the above section, the shell interprets the commands you enter (e.g.
exit in Activity 1.1 item 7), runs the program youve asked for, and generally
coordinates what happens between you and the UNIX operating system. If you
plan to do a lot of work in the UNIX environment, you will want to learn more
about the shell and its set of specific commands. The following activity shows
you how to identify the shell that you are using.
ACTIVITY 1.2
You can use many different approaches to identify which shell youre
using. The easiest, however, is to type echo $SHELL after the
command prompt.
1.
2.
3.
1.3.3
TOPIC 1
INTRODUCTION TO UNIX
The UNIX/LINUX system allows users to modify the password assigned. Once
you have decided on a password, you tell the system to use it from now on with
the passwd command. Activity 1.3 allows you to practise changing your
password.
ACTIVITY 1.3
1.
Try to log out your account and re-log in with your new password.
TOPIC 1
1.3.4
INTRODUCTION TO UNIX
Commands
To interact with UNIX, you enter a command text you type after the command
prompt. When you finish typing the command, press Enter. UNIX is casesensitive, that is, it distinguishes between uppercase and lowercase letters, so
that Toby differs from toby. When you enter a command, you should follow
correct syntax. Otherwise, you will receive a message that UNIX cannot interpret
your command. Commands use the following syntax (or format):
You can practise using some UNIX commands in the next activity.
ACTIVITY 1.4
Log in the UNIX system with your account. Try to explain the following
commands:
1.
2.
3.
4.
5.
6.
7.
8.
10 X
1.3.5
TOPIC 1
INTRODUCTION TO UNIX
Online Help
You can get online information on almost any UNIX command, by using man.
For example, to get information on all of the options available for the ls
command, type:
man ls
and a detailed description of everything ls does will then appear on the screen.
In this way, this description will be automatically piped through more. Just hit
the spacebar when you are ready to go to another screenfull.
At the end of the output, there will also be pointers to other commands related to
the one requested, as well as lists of any files used by the command, such as
startup files via which the command will have certain options set before
execution.
This topic has introduced you to the UNIX environment. The skills and
knowledge that you gained in this topic are important for you before
proceeding to network programming.
By now you should be able to identify the key features of the UNIX
environment and be able to discuss the syntax of UNIX commands.
UNIX
Kernel
Utilities
Shell
Bourne shell
C shell
Korn shell
Bash shell
tcsh shell