Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
BSIT - 43
Kuvempu University
In
col l aborati on
w i th
II
First Edition
: May 2005
Second Edition : December 2010
Third Edition : May 2012
Printed at :
III
Smt. Bhuvaneshwari K V
Lecturer, Department of IS&E
BIET, Davanagere
and
Dr. Shreedhara K S
Professor, Department of CS&E
University BDT College of Engineering
Davanagere
IV
V
a
Pr ef ac e
WHAT IS UNIX?
UNIX is operating system software that manages the hardware and software resources of a
computer. UNIX is one of the most widely used operating systems in industry, government, and
education. It is especially popular in academia: according to AT&T, where UNIX was developed,every
major university in the United States now has at least one computer system running under UNIX.
UNIX is not a user-friendly operating system. Novice user can not directly work on the UNIX
operating system but a smart programmer uses this environment and its tools to turn out programs
faster.
Which Version of UNIX?
UNIX versions can be broadly divided into two schools the System V school from AT&T Bell
Laboratories and the Berkeley school from the University of California, Berkeley. More specifically,
versions tend to be looked at as being either based on SVR4 (System V Release 4 AT&Ts last
release before winding up to its UNIX operations) or on BSD UNIX (Berkeley System Distribution).
While many of the features of UNIX are common to all systems.
From the users standpoint, these versions of UNIX are quite similar. Most can trace their
ancestry to either AT&T UNIX or Berkeley UNIX; some are amalgams of both. This book presents
features that are found on almost all UNIX systems, with special emphasis on those that are
common to AT&T System V and Berkeley System Distribution (BSD) 4.3 UNIX.
Who Should Read This Book?
This book is intended for anyone who wants to acquire a working knowledge of UNIX without
VI
having to become a UNIX expert. It is especially appropriate for students of science, engineering,
or business who are taking their first computer programming course.
What Does This Book Cover?
This book covers the basics of the UNIX operating system. It has mainly two parts: i.e.
PART- A and PART-B.
In PART-A, you will find an overview of the UNIX operating system You will learn about the
background of the Unix operating system, using simple Unix commands, the Unix file system,
handling ordinary files and the attributes of files. You will also learn about the powerful editing
features of the vi editor.
In PART-B, you will find the basics of shell, how to manipulate processes in UNIX system?,
How to establish communication in UNIX operating system, How to use different filters? and also
at the end you will how to write shell scripts in UNIX operating system.
How to Use This Book?
Anyone who is just starting with UNIX should read straight through PART-A and PART-B.
Those who are familiar with basics of UNIX can directly go through PART-B.
Each part of this book begins with a chapter explaining the material without requiring the use of
the computer. You should plan to spend about an hour at the terminal to cover each tutorial.
At the end of each section, you will find some short exercises. To derive the maximum benefit
from this text, be sure to work through all of the exercises.
VII
a
Contents
PART A
Chapter 1
INTRODUCTION TO UNIX AND ITS BACKGROUND
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1
2
2
3
4
5
5
6
Chapter 2
UNDERSTANDING THE UNIX COMMANDS
2.1
2.2
2.3
2.4
2.5
2.6
2.7
7
8
8
8
9
10
11
11
VIII
Chapter 3
GENERAL-PURPOSE UTILITIES
12
3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8
3.9
3.10
3.11
3.12
3.13
3.14
3.15
12
14
15
15
16
17
18
19
20
21
21
23
23
25
26
26
Chapter 4
THE FILE SYSTEM
27
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
4.10
4.11
4.12
27
28
28
29
30
30
31
31
32
32
36
37
37
Chapter 5
MANAGING ORDINARY FILES
38
5.1
38
IX
5.2
5.3
5.4
5.5
5.6
5.7
5.8
5.9
5.10
5.11
5.12
5.13
5.14
38
39
40
40
42
43
43
44
45
46
47
47
48
48
Chapter 6
BASIC FILE ATTRIBUTES
49
6.1
6.2
6.3
6.4
6.5
49
50
51
54
54
54
56
57
58
60
60
6.6
6.7
6.8
Chapter 7
THE VI EDITOR
61
7.1
7.2
7.3
7.4
7.5
7.6
7.7
61
61
62
63
64
65
65
X
7.8 Pattern search and Replace...............................................................
7.9 Miscellaneous operators in command mode........................................
7.10 Conclusion........................................................................................
Exercises..........................................................................................
66
66
67
67
Chapter 8
THE SHELL
68
8.1
8.2
8.3
8.4
8.5
8.6
8.7
8.8
8.9
8.10
8.11
68
68
69
70
71
74
75
76
77
77
79
79
Chapter 9
THE PROCESS
80
9.1
9.2
9.3
9.4
9.5
9.6
9.7
9.8
9.9
9.10
9.11
80
82
83
84
85
86
87
88
89
90
91
91
Basics of process..............................................................................
Process status: ps.............................................................................
System process.................................................................................
Mechanism of process creation..........................................................
Running jobs in background................................................................
Jobs execution with low priority: nice.................................................
Killing process with signals................................................................
Execute later: at and batch...............................................................
Running jobs periodically: cron...........................................................
Timing processes: time......................................................................
Conclusion........................................................................................
Exercises.........................................................................................
Chapter 10
COMMUNICATION AND ELECTRONIC MAIL
92
92
XI
10.2
10.3
10.4
10.5
10.6
10.7
93
93
94
96
99
99
100
Chapter 11
SIMPLE FILTERS
101
11.1
11.2
11.3
11.4
11.5
101
102
102
103
103
104
104
105
107
107
109
110
111
112
113
113
11.6
11.7
11.8
11.9
11.10
11.11
Chapter 12
SHELL PROGRAMMING
114
12.1
12.2
12.3
12.4
12.5
12.6
12.7
114
115
116
116
118
119
120
XII
12.8
12.9
12.10
12.11
12.12
12.13
12.14
12.15
Control structures..............................................................................
The if statement and test command....................................................
The elif and else statements...............................................................
The case statement...........................................................................
for loops...........................................................................................
while loops.......................................................................................
until loops.........................................................................................
Conclusion........................................................................................
Exercises.........................................................................................
121
122
122
123
124
125
125
126
126
Chapter 13
DEVELOPING SHELL SCRIPTS
127
13.1
13.2
13.3
13.4
13.5
13.6
127
128
130
131
132
134