
UNIX AND SHELL PROGRAMMING B.M. Harwani Founder & Owner Microchip Computer Education (MCE) Ajmer 3 Oxford University Press is a department of the University of Oxford. It furthers the University’s objective of excellence in research, scholarship, and education by publishing worldwide. Oxford is a registered trade mark of Oxford University Press in the UK and in certain other countries. Published in India by Oxford University Press YMCA Library Building, 1 Jai Singh Road, New Delhi 110001, India © Oxford University Press 2013 The moral rights of the author/s have been asserted. First published in 2013 All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, without the prior permission in writing of Oxford University Press, or as expressly permitted by law, by licence, or under terms agreed with the appropriate reprographics rights organization. Enquiries concerning reproduction outside the scope of the above should be sent to the Rights Department, Oxford University Press, at the address above. You must not circulate this work in any other form and you must impose this same condition on any acquirer. ISBN-13: 978-0-19-808216-3 ISBN-10: 0-19-808216-9 Typeset in Times by Quick Sort (India) Private Limited, Chennai Printed in India by Raj Kamal Electric Press, Kundli, Haryana Third-party website addresses mentioned in this book are provided by Oxford University Press in good faith and for information only. Oxford University Press disclaims any responsibility for the material contained therein. Dedicated to my mother, Nita Harwani Mom, whatever I am today is because of the moral values taught by you. I also pay tribute to the offi cers, men and women of all ranks, of the Indian Armed Forces. I salute these brave, patriotic, and disciplined people for serving our country. Preface Unix operating system, developed in the 1960s, is regarded as one of the most powerful operating systems, due to its portability and usage in almost all kinds of environments. It is the result of the combined efforts of many people—students, professors, researchers, and commercial companies. It is a multitasking and multi-user operating system that is portable on several hardware platforms and is very secure. It provides a rich set of tools and utilities that help administrators, programmers, and users, to a great extent, in executing their tasks. Besides this, Unix offers the fl exibility of controlling individual jobs executed by a user. Since its inception, Unix has been evolving constantly and has given rise to various products such as Linux, Ubuntu, FreeBSD, SunOS, Solaris, SCO, and AIX. In order to understand and learn these products that are widely in use, it is imperative for users to have a clear understanding of the root, that is, the actual Unix operating system—its features, management of devices and fi les, implementation of security, scheduling of CPU, and memory management. Nowadays, Unix and its by-products are used as servers and in developing mobile applications. Unix has also served as a model for the development of the Internet, thus shifting the focus of computers towards the creation of networks. ABOUT THE BOOK The book has been designed to cater to students, teachers, professionals, and developers to help them learn the fundamental concepts of the Unix operating system. It follows a bottom-up approach, that is, it explains basic commands and gradually moves towards advanced commands. Similarly, it begins with small and easy scripts and makes the reader acquainted with the fundamental statements, loops, and conditional statements in a systematic manner. Gradually, it moves on to explain large, complex, and critical scripts. The book focuses on advanced Unix commands that perform critical functions such as setting access permissions, changing ownerships of the fi les, sharing fi les among groups, performing input/output (I/O) redirections, cutting or slicing the fi le vertically, pasting content, comparing fi les, and printing documents. It explains in detail the manipulation of processes and signals and the role of system calls. All the major editors in Unix, namely, stream editor (sed), visual editor (vi), and modeless editor (emacs) are explained in detail. The book describes Bourne, Korn, and C shell programming and covers all important topics and commands associated with these shells. It also includes numerous programming scripts for better understanding of the three types of shells. The later part of the book includes dedicated chapters on language development tools (Yacc, Lex, and M4), text-formatting tools (troff and nroff), and Unix networking and administration. KEY FEATURES The book is packed with numerous student-friendly features that are described here. • Complete scripts along with their outputs are provided for easy implementation of the concepts learnt. • Each command is explained with its syntax with the help of multiple examples. Preface vii • Several options of a single command have been provided in a tabular format along with their function, description, and examples for quick understanding and usage. • Numerous notes are interspersed with the text for providing additional relevant information. • Around 1000 solved examples and over 900 end-chapter exercises (with answers to objective-type questions) are provided. • Specially designed brain teasers are provided at the end of most chapters for the readers to develop an analytical approach to problem-solving. • A variety of objective-type questions—state true or false, fi ll in the blanks, and multiple-choice questions—are provided at the end of every chapter for testing the understanding of the concepts learnt. • Several review questions and programming exercises are provided for the reader to practise the commands and scripts explained in the chapters. ONLINE RESOURCES The companion website of the book, http://oupinheonline.com/book/harwani-unix-shell-programming/ 9780198082163, provides the following additional resources: For faculty • Chapter-wise PowerPoint Slides • Answers to select programming exercises given in the book For students • Chapter-wise executable and complete shell scripts and codes for all the programs given in the book • Mail Organizer—a small project that sends mail to the desired recipient on a given date • Inventory Management System—a small project that explains maintenance of inventory using MySQL database server • Debugging exercises with solutions • Flashcards—for active recall of all important Unix commands ORGANIZATION OF THE BOOK The book is organized into 15 chapters. Chapter 1, Unix: An Introduction, focuses on the fundamentals of operating systems, history of Unix, structure of the Unix operating system, Unix environment, and different types of shells. Chapter 2, Unix File System, explains the different types of regular and device fi les, organization of a fi le system, accessing, mounting, and unmounting a fi le system, different blocks of a fi le system, and structure of inode blocks. Chapter 3, Basic Unix Commands, describes basic commands such as logging into the system, changing the password, checking who is logged in, displaying date and time of the system, and dealing with fi le operations such as creating fi les, displaying their contents, deleting fi les, creating links to fi les, renaming fi les, and moving fi les. The chapter also explains commands for maintaining directories, creating a directory, changing the current directory, removing a directory, displaying calendars, using viii Preface basic calculators, displaying information about current systems, deleting symbolic links, and exiting from a Unix system. Chapter 4, Advanced Unix Commands, discusses advanced commands such as setting access permissions for the existing fi les and directories, setting default permissions for the newly created fi les and directories, creating groups, changing ownerships of the fi les, and sharing fi les among groups. The chapter covers commands for sorting content, performing I/O redirections, cutting the fi le vertically, pasting content, splitting fi les, counting characters, words, and lines in fi les, using the pipe operator, comparing fi les, eliminating and displaying duplicate lines, among others. Chapter 5, File Management and Compression Techniques, explains the types of devices, role of device drivers, and the way in which devices are represented in the Unix operating system. It details different disk-related commands required for copying, formatting, fi nding usage, fi nding free space, and making partitions. It also covers compression and decompression of fi les. Chapter 6, Manipulating Processes and Signals, focuses on processes and their address space, structure, data structures describing the processes and process states, commands related to scheduling processes at the desired time, handling jobs, and switching jobs from the foreground to the background and vice versa. It explains suspending, resuming, and terminating jobs, executing commands in a batch, ensuring process execution even when a user logs out, increasing and decreasing the priority of processes, and killing processes. The chapter also discusses signals, their types, and the methods of signal generation, virtual memory and its role in executing large applications in a limited physical memory, and mapping of a virtual address to the physical memory. Chapter 7, System Calls, is devoted to the role of system calls in performing different tasks. The chapter explains system calls that are used in fi le handling operations such as opening, creating, reading from and writing to fi les, closing, deleting, and linking to fi les, changing fi le access permissions, accessing fi le information, and relocating and duplicating fi le descriptors. The chapter covers the system calls that perform different tasks related to directory handling such as changing, opening, and reading directories. The chapter throws light on the system calls involved in process handling operations such as the exec(), fork, and wait system calls and those that deal with memory management—allocating memory, freeing memory, changing the size of the allocated memory, fi le locking, and record locking .
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages734 Page
-
File Size-