Выбрать главу

100 SHELL PROGRAMS

IN UNIX

By

Sarika Jain

Head, MCA Department

ABSS, Meerut (U.P.)

Shivani Jain

Senior Lecturer, Department of Computer Science

VCE, Meerut (U.P.)

FIREWAL MEDIA

(An Imprint of Laxmi Publications Pvt. Ltd.)

BANGALORE CHENNAI COCHIN GUWAHATI HYDERABAD

JALANDHAR KOLKATA LUCKNOW MUMBAI RANCHI

NEW DELHI

Published by :

FIREWAL MEDIA

(An Imprint of Laxmi Publications Pvt. Ltd.)

113, Golden House, Daryaganj,

New Delhi-110002

Phone : 011-43 53 25 00

Fax : 011-43 53 25 28

www.laxmipublications.com

info@laxmipublications.com

Copyright © 2009 by Laxmi Publications Pvt. Ltd. All rights reserved with the Publishers. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise without the prior written permission of the publisher.

First Edition

 : 2009

OFFICES

 Bangalore

080-26 61 15 61

 Chennai

044-24 34 47 26

 Cochin

0484-239 70 04

 Guwahati

0361-254 36 69, 251 38 81

 Hyderabad

040-24 65 23 33

 Jalandhar

0181-222 12 72

 Kolkata

033-22 27 43 84

 Lucknow

0522-220 95 78

 Mumbai

022-24 91 54 15, 24 92 78 69

 Ranchi

0651-221 47 64

FSH-3030-100-100 SHELL PROG IN UNIX

C—17102/09/02

Typeset at

: Kalyani Computer Services, New Delhi.

Printed at

: Mehra Offset Press, Delhi.

CONTENTS

Preface

1.    Introduction

I. An Overview

II. Salient Features of Unix

III. Hardware Requirements for Unix

IV. Getting Started

V. Unix Architecture

VI. Unix Basic Commands

VII. Portability with C

2.    Programs

PREFACE

The UNIX system is so successful. Why? First, because UNIX is portable, i.e., runs on a range of computers and adapts to particular requirements. Second, the UNIX programming environment is unusually rich and productive. The UNIX system has become very popular, and there are number of versions in wide use. Regardless of the version you run on your system, the difference in coding you find will be minor.

The book’s small size is meant to keep your investment in time down to a minimum but with the greatest possible amount of knowledge. This book is organized as follows: Part I is an introduction to the most basic use of the system. It covers logging in, the file system, commonly used commands, and logging out. Part II contains 100 programs (including shell script and programs in C).

The best way to learn something is by doing it. Kindly practice the programs and verify or contradict what we say. All the examples in this text are actual, runnable code tested on UNIX system.

As a reader of this book, you are the most important critic and commentator. You can email or write to us directly to let us know what you did or didn’t like about this book – as well as what we can do to make our book stronger.

—AUTHORS

ACKNOWLEDGEMENT

We are grateful to many people for constructive comments and criticisms, and for their help in improving our code. The work of an author is only as good as the support from their family members and friends. Sarika Jain would like to specially thank her husband, Anuj Jain for letting her off all her household chores while working in the tree house on this project. Likewise, Shivani Jain wants to thank her all family members for their understanding and encouragement throughout this project. We cound not have done this without all of you.

—AUTHORS

PART I

INTRODUCTION

I. AN OVERVIEW

UNIX is an operating system which was first developed in the 1960s, and has been under constant development ever since. By operating system, we mean the suite of programs, which make the computer work. It is a stable, multi-user, multi-tasking system for servers, desktops and laptops. UNIX systems also have a graphical user interface (GUI) similar to Microsoft Windows, which provides an easy to use environment. UNIX (and Linux, which is Linus Torvald’s version of UNIX) has deep roots in the computer industry. UNIX is a very powerful multitasking and multi-user system. Multitasking means a user can run multiple programs simultaneously with in one single login of the system. Multi-user means that many users can simultaneously and securely use the same machine with their separate dumb terminals. The following figure shows a typical UNIX setup:

II. SALIENT FEATURES OF UNIX

Among many salient features the UNIX offers, few are listed below:

Multi-user

Multitasking

Communication

Security

Portability

Capability

Time sharing

Command interpreter & background processing

Hierarchical file system

Dos-Unix interface

Simple command

System administration & job accounting

Tools & utilities

Shell programming

Availability of 4GL and RDBMS

Library of application packages

III. HARDWARE REQUIREMENTS FOR UNIX

There are some prerequisites for a system that can host and take best advantage of UNIX. These are a PC/AT or higher with an 80 MB hard disk and at least 4MB of RAM on a 16-bit microprocessor (80286/80386/80486). The dumb terminals are connected to the host machine through a 4/8/16 port controller card installed in the expansion slot on the motherboard of the host machine. More the number of terminals more should be the memory on the host machine. Out of 80 MB disk space, almost 40MB is eaten away by the actual UNIX OS files and another 10-20 MB is used as swap space. For each terminal to be supported, 0.75 to 1 MB should be present in the host machine.