Sie sind auf Seite 1von 10

Topic1

Introduction
toUNIX

LEARNING OUTCOMES
By the end of this topic, you should be able to:
1.
2.

Identify the key features of the UNIX environment; and


Discuss the syntax of UNIX commands.

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

THE UNIX KERNEL

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

Figure 1.1: UNIX kernel, utilities and shell

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 UNIX SHELL

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

GETTING STARTED: A GUIDED TOUR OF


UNIX

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:

Connect to the UNIX computer remotely,

Identify your working shell,

Change your password,

Enter UNIX commands and

Use online help.

1.3.1

Connecting to the UNIX Computer

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.

Click the Start button of Windows 95. Click Run.


In the Run dialog box, type telnet. Click OK (please refer to Figure
1.2).

Figure 1.2: Telnet windows

TOPIC 1

3.

INTRODUCTION TO UNIX

Click Connect on the menu bar. Then click Remote System.


The Connect dialog box appears, as shown in Figure 1.3.

Figure 1.3: Connect dialog box

4.

In the Host Name text box, type the server and domain name, i.e.

unix.oum.edu.my.
5.

Click the Connect button. You see a login prompt, similar to


Figure 1.4.

Figure 1.4: Remote login prompt

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

Figure 1.5: Login screen

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.

Figure 1.6: Logging out of UNIX

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

UNIX Shell Identification

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.

One simple technique for identifying your shell is to check your


command prompt. If your prompt contains a %, you probably are
using the C shell. If your prompt contains $, you could be using the
Bourne shell, the Korn shell or the Bash shell.

2.

Another easy way is to check the value of your SHELL environment


variable with the echo command. Type echo $SHELL and
press Enter. You will see the following output D (please refer to
Figure 1.7):

Figure 1.7: Shell identification

3.

What kind of shell you are now working on?

1.3.3

TOPIC 1

INTRODUCTION TO UNIX

Changing Your Password

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.

Enter the passwd at the command prompt.


$ passwd
Changing password for s1234567
(current) UNIX password: (a123456 in this case)
New UNIX password: (for example: a123)
You will be warned if the chosen password is too short!

BAD PASSWORD: it is too short.


New UNIX password: (for example: a234567)
You will be warned if the chosen password is too
simplistic/systematic!

BAD PASSWORD: it is too simplistic/systematic.


New UNIX password: (for example: ct212tobychan
2002)
The system accepts your password in this time. It will ask you to
retype your password.

Retype new UNIX password: (ct212tobychan2002)


The system accepts your password and generates the following
message:

Password: all authentication tokens updated


successfully.
Important note
You must choose a password that is both memorable and secure.
Many of the modern UNIX systems have some heuristics or smarts
built in to the passwd command. The heuristics check to determine
whether what youve entered is reasonably secure. Also, you should
remember your new password. If you forget the password, your
account must be deleted and recreated a new account for you, i.e. all
your data will be lost.
2.

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):

command_name [-options] [arguments]


where:

The command-name specifies what operation to perform.

Command options modify the way in which a command works. Options


are often single letters prefixed with a dash (-) and set off by any number of
spaces or tabs. Multiple options in one command line can be set off
individually. Sometimes, you can combine them after a single dash.

Command arguments follow command options, separated by a space.


Commands arguments are usually file and directory names.

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.

Type date in the command line. Press Enter.

2.

Type date u in the command line. Press Enter.

3.

Type cal in the command line. Press Enter.

4.

Type who in the command line. Press Enter.

5.

Type who am i in the command line. Press Enter.

6.

Type clear in the command line. Press Enter.

7.

Type man who in the command line. Press Enter.

8.

Type whatis who in the command line. Press Enter.

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

Das könnte Ihnen auch gefallen