Sie sind auf Seite 1von 5

Unix and Shell Programming

Introduction to Unix
It is widely used Multi-user Operating System, Originally developed by Bell Laboratories
in 1969 to provide an environment in which multiple users can work in the same kind of
environment. After that Dennis Ritchie and Thompson rewrote this OS in C Language
with lots of new isolating features.
Requirements (Min.)
-8 MB RAM
-10 MBard Disk
-16 bit processor
USERS
Architecture
Unix system has layered architecture. UTILITIES
-Hardware
-Kernel
-Shell
-Utilities
KERNEL
-User

HARDWARE

The Kernel
The kernel is a part of the OS that interacts directly with the hardware of a
computer. It provides set of services that can be used by programs.
- The kernel controls the computer resources.
-It keeps track of all the various programs being run.
-Allotting time to each, deciding when one stops and another starts.
-It servers as an interface between the shell and the unix commands on the one hand
and the hardware on the other hand.
-Manage memory, to control access to the computer.
-Maintain file system.
-Handle errors.
-Allow to interact with terminals, storage devices and to allocate the resources to the
computers.
The Shell
The shell read commands and interprets them as requests to execute a program. It is
also called as command Line Interpreter.
-Shell sends a prompt symbol ($) to the screen then waits for input from the user.
-Shell translates typed commands to actions.
-It contains few in-built commands.
-The shell is also a programming language.
There are Three types of Shell in Unix
1.Bourne Shell
2.C Shell
3.Korn Shell
1. Bourne Shell –
•This is the original Unix shell written by Steve Bourne of Bell Labs. It is available on all UNIX
systems.
•This shell does not have the interactive facilities provided by modern shells such as the C shell
and Korn shell. You are advised to to use another shell which has these features.
•The Bourne shell does provide an easy to use language with which you can write shell scripts.
2. C Shell
This shell was written at the University of California, Berkeley. It provides a C-like
language with which to write shell scripts - hence its name.
3.Korn Shell
•This shell was written by David Korn of Bell labs. It is now provided as the standard shell on Unix
systems.
•It provides all the features of the C and SH shells together with a shell programming language
similar to that of the original Bourne shell.
•It is the most efficient shell. Consider using this as your standard interactive shell.
Comparison
Bourne C Korn command history
No Yes Yes Command alias No
Yes Yes
shell scripts Yes Yes Yes
Command line editing No No Yes
job control No Yes Yes Yes

Utilities
The Unix system contains several hundred utilities or user programs. Commands are
also called as tools. Unix utilities can be divided into following groups-
- Commands
general purpose
File and directory
administrator etc.
-Text Processing
text editing
formatting etc.
-Software Development
-Communication
-Graphics
-Games

Features
MultiUser and MultiTasking – Unix OS is Multi-user OS i.e many users can work with the
Operating system. It is also a Multitasking system, because a single user can carry out more than
one task at a time.e.g. use can work on typing tutor as well as you can take printouts also etc.
Open source Code – The source code of the Unix system is not just executable code, has
been made available to users and programmers. This openness has led to the introduction of a
wide range of new features and versions.
Utilities and Tools - Unix provides many tools and utilities, which can be used to perform
various functions and jobs. Tools can be of different type like for graphics, games, text formatting
etc.
Portability – The Unix system is far easier to port to new machine than other OS. It needs far
less work and hardware requirement to port into the any machine.
Inbuilt Networking – It provides excellent networking environment. Unix contains various
commands related with networking or which helps in communication like socket programming,
mailing etc.

Files and Directories


Information stored on the disk is organized in the form of files and directories by OS through File
system utilities.
Types of Unix Files-
1.Ordinary file
2.Directory File
3.Special File / Device file
- Character device file
- Block Device file
Ordinary File – To store general purpose data ordinary files are created. Data stored by user
like editor file, program file, command file are comes in the category of ordinary files. Character
used to represent ordinary files is “-”.

Directory Files – These file contains list of files rather than data. The directory file contains
two fields for each file – name of the file and its inode no. represented by “d”.
Special Files – Files used in the reference of physical devices, such as printer, hard disk etc.
These files read and write same as ordinary files and are only activated by the reference of
physical devices request. These are of 2 types
•Character File – stores and retrieve information character by character. Represented by “c”
•Block Files – work block wise (block is a collection of bytes). Represented by “b”.

File Creation –
several things happen when a user creates a file in unix.

-Kernel allocate space in the memory.


-An inode entry is created for a file. An inode contains-
a) location on the disk

b) Size
c) Time when file was last used
d) Last modified
e) Permissions
f) Owner of the file
g) Group of the file
etc.
-A directory entry is created which contains-
a) inode no. of a file
b) user defined name of the file.
System Calls and Library functions
System calls are the functions used in the kernel itself, used to create files, to provide the
basic input output services, to access the system clock, to determine file-use permissions
and to perform other such fundamental tasks.
e.g.
•access() – determine the accessibility of a file
•Chmod() change permissions of a file
•Open(), close() etc.

These functions offer some of the most basic services of an OS like – allotting memory, running
processes, maintain file system etc.

Library functions contain several kind of C and any other language programs. Many are
extensions of the system calls. There is a standard I/O package, it includes all the standard
‘C’ I/O functions (printf(), fgets() etc) it also includes file related functions like fopen(), close()
etc.

VI Editor
Editing includes both creating new file and modifying an existing file.
There are two types of editors :
•Line editor
In this editor changes are applied to a line or group of lines.
Ex. Ed, sed editor
•Screen Editor
A screen editor presents a whole screen of text at a time. We can move the cursor around
the screen and select a part of the text.
e.g. vi

Vi editor
It is a screen editor . There are two basic modes of this editor :
•Command mode
•Text Mode

Command Mode

Any key pressed by the user is considered a command. Commands are used to move
cursor, to delete or change part of the text etc.

Text mode

any key that is pressed by the user is considered text. The keyboard act like a typewriter.

vi editor Commands
I Insert text before the current character
I Insert text at the beginning of the current line.
A Appends text after the current character
A Appends text at the end of the current line.
O Insert empty line after current line
O Insert empty line before current line.
Dd Delete current line
X Delete current character
J Join next line to the current line
Ctrl+y Scroll up one line
Ctrl+e Scroll down one line
Ctrl+u Scrolls up half a screen
Ctrl+d Scrolls down half a screen
Ctrl+b Scroll up whole screen
Ctrl+f Scroll down whole screen
U Undo last command
:w Save
:zz Save and exit
:wq Save and exit
:q Exit
:q! Exit without save

Das könnte Ihnen auch gefallen