Computer Science & Engineering LINUX

Transcription

LINUXwith OperatingSystem ConceptsRichard Fox

LINUXwith OperatingSystem Concepts

LINUXwith OperatingSystem ConceptsRichard FoxNorthern Kentucky UniversityHighland Heights, Kentucky, USA

CRC PressTaylor & Francis Group6000 Broken Sound Parkway NW, Suite 300Boca Raton, FL 33487-2742 2015 by Taylor & Francis Group, LLCCRC Press is an imprint of Taylor & Francis Group, an Informa businessNo claim to original U.S. Government worksVersion Date: 20140714International Standard Book Number-13: 978-1-4822-3590-6 (eBook - PDF)This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have beenmade to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyrightholders of all material reproduced in this publication and apologize to copyright holders if permission to publish in thisform has not been obtained. If any copyright material has not been acknowledged please write and let us know so we mayrectify in any future reprint.Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from thepublishers.For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923,978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. Fororganizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged.Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only foridentification and explanation without intent to infringe.Visit the Taylor & Francis Web site athttp://www.taylorandfrancis.comand the CRC Press Web site athttp://www.crcpress.com

With all my love toCheri Klink, Sherre Kozloff, and Laura Smith

ContentsPreface, xixAcknowledgments and Contributions, xxiHow to Use This Textbook, xxiiiAuthor, xxvChapter 1 Introduction to Linux11.1WHY LINUX?11.2OPERATING SYSTEMS31.3THE LINUX OPERATING SYSTEM: GUIs51.3.1User Account and Logging In61.3.2Gnome71.3.3KDE Desktop Environment1.413THE LINUX COMMAND LINE151.4.1The Interpreter151.4.2The Shell161.4.3The CLI over the GUI171.5VIRTUAL MACHINES191.6UNIX AND LINUX211.7TYPES OF USERS231.8WHAT IS A COMPUTER?251.8.1The IPOS Cycle251.8.2Computer Hardware261.8.3Software and Users281.8.4Types of Computers291.9THIS TEXTBOOK311.10 CHAPTER REVIEW32REVIEW QUESTIONS34vii

viii        ContentsChapter 2  The Bash Shell372.1INTRODUCTION372.2ENTERING LINUX COMMANDS382.2.1Simple Linux Commands392.2.2Commands with Options and Parameters402.3MAN PAGES432.4BASH FEATURES462.4.1Recalling Commands through History462.4.2Shell Variables472.4.3Aliases512.4.4Command Line Editing522.4.5Redirection542.4.6Other Useful Bash Features572.5OTHER SHELLS592.6INTERPRETERS612.6.1Interpreters in Programming Languages612.6.2Interpreters in Shells622.6.3The Bash Interpreter632.7CHAPTER REVIEWREVIEW QUESTIONSChapter 3  Navigating the Linux File System3.13.23.3646771INTRODUCTION713.1.1File System Terminology723.1.2A Hierarchical File System73FILENAME SPECIFICATION743.2.1The Path743.2.2Specifying Paths above and below the Current Directory763.2.3Filename Arguments with Paths763.2.4Specifying Filenames with Wildcards77FILE SYSTEM COMMANDS793.3.1Directory Commands803.3.2File Movement and Copy Commands813.3.3File Deletion Commands853.3.4Creating and Deleting Directories86

Contents        ix3.43.53.3.5Textfile Viewing Commands873.3.6File Comparison Commands883.3.7File Manipulation Commands893.3.8Other File Commands of Note913.3.9Hard and Symbolic Links92LOCATING FILES933.4.1The GUI Search Tool943.4.2The Find Command943.4.3Other Means of Locating Files97PERMISSIONS993.5.1What Are Permissions?993.5.2Altering Permissions from the Command Line1003.5.3Altering Permissions from the GUI1033.5.4Advanced Permissions1043.6LINUX FILE SYSTEM STRUCTURE1053.7SECONDARY STORAGE DEVICES1073.7.1The Hard Disk Drive1083.7.2Magnetic Tape1103.7.3Optical Disk and USB Drive1113.83.9FILE COMPRESSION1133.8.1Types of File Compression1133.8.2The LZ Algorithm for Lossless Compression1133.8.3Other Lossless Compression Algorithms115CHAPTER REVIEWREVIEW QUESTIONSChapter 4  Managing Processes1161181254.1INTRODUCTION1254.2FORMS OF PROCESS MANAGEMENT1274.2.1Single Process Execution1284.2.2Concurrent Processing1294.2.3Interrupt Handling1324.34.4STARTING, PAUSING, AND RESUMING PROCESSES1334.3.1Ownership of Running Processes1334.3.2Launching Processes from a Shell135MONITORING PROCESSES138

x        Contents4.4.1GUI Monitoring Tools1384.4.2Command-Line Monitoring Tools1404.5MANAGING LINUX PROCESSES1454.6KILLING PROCESSES1474.6.1Process Termination1474.6.2Methods of Killing Processes1494.6.3Methods to Shut Down Linux1504.7CHAPTER REVIEWREVIEW QUESTIONSChapter 5 Linux Applications1511551595.1INTRODUCTION1595.2TEXT EDITORS1605.2.1vi (vim)1615.2.2emacs1645.2.3gedit1705.3PRODUCTIVITY SOFTWARE1715.4LATEX1725.5ENCRYPTION SOFTWARE1755.5.1What Is Encryption?1755.5.2Openssl1775.65.75.8EMAIL PROGRAMS1805.6.1Sending Email Messages1815.6.2Reading Email Messages182NETWORK SOFTWARE1835.7.1Internet Protocol Addressing1845.7.2Remote Access and File Transfer Programs1855.7.3Linux Network Inspection Programs188CHAPTER REVIEWREVIEW PROBLEMSChapter 6  Regular CTERS2036.2.1Controlling Repeated Characters through *, , and ?2036.2.2Using and Modifying the ‘.’ Metacharacter2056.2.3Controlling Where a Pattern Matches206

Contents        xi6.2.4Matching from a List of Options2076.2.5Matching Characters That Must Not Appear2096.2.6Matching Metacharacters Literally2106.2.7Controlling Repetition2116.2.8Selecting between Using grep/egrep2166.4.2Useful egrep Options2196.4.3Additional egrep Examples2216.4.4A Word of Caution: Use Single Quote Marks224SED2256.5.1Basic sed Syntax2256.5.2Placeholders228awk2306.6.1Simple awk Pattern-Action Pairs2316.6.2BEGIN and END Sections2346.6.3More Complex Conditions2356.6.4Other Forms of Control239CHAPTER REVIEW240REVIEW QUESTIONS241Chapter 7  Shell Scripting2457.1INTRODUCTION2457.2SIMPLE SCRIPTING2467.2.1Scripts of Linux Instructions2467.2.2Running Scripts2477.2.3Scripting Errors2487.3VARIABLES, ASSIGNMENTS, AND PARAMETERS2497.3.1Bash Variables2497.3.2Assignment Statements2507.3.3Executing Linux Commands from withinAssignment Statements2527.3.4Arithmetic Operations in Assignment Statements2547.3.5String Operations Using expr2567.3.6Parameters257

xii        Contents7.47.57.67.77.87.9INPUT AND OUTPUT2587.4.1Output with echo2587.4.2Input with read260SELECTION STATEMENTS2637.5.1Conditions for Strings and Integers2637.5.2File Conditions2667.5.3The If-Then and If-Then-Else Statements2687.5.4Nested Statements2707.5.5Case Statement2727.5.6Conditions outside of Selection Statements276LOOPS2777.6.1Conditional Loops2777.6.2Counter-Controlled Loops2787.6.3Iterator Loops2797.6.4Using the Seq Command to Generate a List2817.6.5Iterating over Files2817.6.6The While Read Statement284ARRAYS2857.7.1Declaring and Initializing Arrays2867.7.2Accessing Array Elements and Entire Arrays2877.7.3Example Scripts Using Arrays288STRING MANIPULATION2897.8.1Substrings Revisited2897.8.2String Regular Expression Matching290FUNCTIONS2937.9.1Defining Bash Functions2937.9.2Using Functions2957.9.3Functions and Variables2967.9.4Exit and Return Statements2987.10 C-SHELL SCRIPTING2997.10.1 Variables, Parameters, and Commands2997.10.2 Input and Output3007.10.3 Control Statements3017.10.4 Reasons to Avoid csh Scripting3037.11 CHAPTER REVIEW304REVIEW QUESTIONS307

Contents        xiiiChapter 88.18.28.3 Installing Linux313INTRODUCTION3138.1.1Installation Using Virtual Machines3148.1.2Preinstallation Questions314THE LINUX-OPERATING SYSTEM3168.2.1Operating Systems and Modes of Operation3168.2.2System Calls3178.2.3The Kernel3188.2.4Loading and Removing Modules320INSTALLING CENTOS 63218.3.1The Basic Steps3218.3.2Disk-Partitioning Steps3258.3.3Finishing Your Installation3308.4INSTALLING UBUNTU3318.5SOFTWARE INSTALLATION CHOICES3348.6VIRTUAL MEMORY3358.7SETTING UP NETWORK CONNECTIVITY AND A PRINTER3388.7.1Establishing Network Connections3388.7.2Establishing Printers3398.88.9SELINUX3418.8.1SELinux Components3428.8.2Altering Contexts3438.8.3Rules344CHAPTER REVIEW345REVIEW PROBLEMSChapter 9  User Accounts3473519.1INTRODUCTION3519.2CREATING ACCOUNTS AND GROUPS3529.2.1Creating User and Group Accounts through the GUI3529.2.2Creating User and Group Accounts from the Command Line3549.2.3Creating a Large Number of User Accounts3589.3MANAGING USERS AND GROUPS3619.3.1GUI User Manager Tool3619.3.2Command Line User and Group Management362

xiv        Contents9.49.59.6PASSWORDS3659.4.1Ways to Automatically Generate Passwords3659.4.2Managing Passwords3679.4.3Generating Passwords in Our Script368PAM3709.5.1What Does PAM Do?3709.5.2Configuring PAM for Applications3709.5.3An Example Configuration File372ESTABLISHING COMMON USER RESOURCES3739.6.1Populating User Home Directories with Initial Files3739.6.2Initial User Settings and Defaults3759.7THE SUDO COMMAND3779.8ESTABLISHING USER AND GROUP POLICIES3809.8.1We Should Ask Some Questions before Generating Policies3809.8.2Four Categories of Computer Usage Policies3819.9CHAPTER REVIEWREVIEW QUESTIONSChapter 10  The Linux File System38338539110.1 INTRODUCTION39110.2 STORAGE ACCESS39210.2.1 Disk Storage and Blocks39210.2.2 Block Indexing Using a File Allocation Table39310.2.3 Other Disk File Details39410.3 FILES39410.3.1 Files versus Directories39510.3.2 Nonfile File Types39510.3.3 Links as File Types39710.3.4 File Types39810.3.5 inode39910.3.6 Linux Commands to Inspect inodes and Files40210.4 PARTITIONS40510.4.1 File System Redefined40510.4.2 Viewing the Available File Systems40610.4.3 Creating Partitions40910.4.4 Altering Partitions411

Contents        xv10.4.5 Using a Logical Volume Manager to Partition41110.4.6 Mounting and Unmounting File Systems41410.4.7 Establishing Quotas on a File System41710.5 LINUX TOP-LEVEL DIRECTORIES REVISITED41910.5.1 Root Partition Directories41910.5.2 /dev, /proc, and /sys42210.5.3 The /etc Directory42410.5.4 /home42610.5.5 /usr42610.5.6 /var42710.5.7 Directories and Changes42710.6 OTHER SYSTEM ADMINISTRATION DUTIES42810.6.1 Monitoring Disk Usage42810.6.2 Identifying Bad Blocks and Disk Errors42910.6.3 Protecting File Systems43010.6.4 Isolating a Directory within a File System43510.7 CHAPTER REVIEW436REVIEW PROBLEMS439Chapter 11  System Initialization and Services44511.1 INTRODUCTION44511.2 BOOT PROCESS44611.2.1 Volatile and Nonvolatile Memory44611.2.2 Boot Process44711.3 BOOT LOADING IN LINUX44811.3.1 Boot Loaders44811.3.2 Loading the Linux Kernel44911.4 INITIALIZATION OF THE LINUX OPERATING SYSTEM45011.4.1 inittab File and Runlevels45011.4.2 Executing rcS.conf and rc.sysinit45311.4.3 rc.conf and rc Scripts45411.4.4 Finalizing System Initialization45611.5 LINUX SERVICES45711.5.1 Categories of Services45711.5.2 Examination of Significant Linux Services45811.5.3 Starting and Stopping Services463

xvi        Contents11.5.4 Examining the atd Service Control Script46511.6 CONFIGURING SERVICES THROUGH GUI TOOLS47111.6.1 Firewall Configuration Tool47211.6.2 kdump Configuration Tool47311.7 CONFIGURING SERVICES THROUGH CONFIGURATIONFILES47511.7.1 Configuring Syslog47511.7.2 Configuring nfs47711.7.3 Other Service Configuration Examples47811.8 CHAPTER REVIEW480REVIEW PROBLEMS481Chapter 12  Network Configuration48512.1 INTRODUCTION48512.2 COMPUTER NETWORKS AND TCP/IP48612.2.1 Broadcast Devices48612.2.2 The TCP/IP Protocol Stack48712.2.3 Ports49012.2.4 IPv649112.2.5 Domains, the DNS, and IP Aliases49212.3 NETWORK SERVICES AND FILES49412.3.1 The Network Service49412.3.2 The /etc/sysconfig/network-scripts Directory’s Contents49512.3.3 Other Network Services49712.3.4 The xinetd Service49912.3.5 Two /etc Network Files50212.4 OBTAINING IP ADDRESSES50312.4.1 Static IP Addresses50312.4.2 Dynamic IP Addresses50412.4.3 Setting up a DHCP Server50512.5 NETWORK PROGRAMS50712.5.1 The ip Program50712.5.2 Other Network Commands50912.6 THE LINUX FIREWALL51012.6.1 The iptables-config File51112.6.2 Rules for the iptables File511

Contents        xvii12.6.3 Examples of Firewall Rules12.7 WRITING YOUR OWN NETWORK SCRIPTS51551712.7.1 A Script to Test Network Resource Response51812.7.2 A Script to Test Internet Access51912.7.3 Scripts to Compile User Login Information52112.8 CHAPTER REVIEW522REVIEW QUESTIONS526Chapter 13  Software Installation and Maintenance53113.1 INTRODUCTION53113.2 SOFTWARE INSTALLATION QUESTIONS53213.3 INSTALLING SOFTWARE FROM A GUI53313.3.1 Add/Remove Software GUI in CentOS53313.3.2 Ubuntu Software Center53513.4 INSTALLATION FROM PACKAGE MANAGER53613.4.1 RPM53713.4.2 YUM54013.4.3 APT54413.5 INSTALLATION OF SOURCE CODE54613.5.1 Obtaining Installation Packages54713.5.2 Extracting from the Archive54713.5.3 Running the configure Script54913.5.4 The make Step54913.5.5 The make install Step55113.6 THE GCC COMPILER55313.6.1 Preprocessing55313.6.2 Lexical Analysis and Syntactic Parsing55313.6.3 Semantic Analysis, Compilation, and Optimization55413.6.4 Linking55513.6.5 Using gcc55713.7 SOFTWARE MAINTENANCE55813.7.1 Updating Software through rpm and yum55813.7.2 System Updating from the GUI56013.7.3 Software Documentation56113.7.4 Software Removal561

xviii        Contents13.8 THE OPEN SOURCE MOVEMENT56213.8.1 Evolution of Open Source56213.8.2 Why Do People Participate in the Open Source Community?56513.9 CHAPTER REVIEW566REVIEW QUESTIONS569Chapter 14  Maintaining and Troubleshooting Linux57114.1 INTRODUCTION57114.2 BACKUPS AND FILE SYSTEM INTEGRITY57214.2.1 Examining File System Usage57214.2.2 RAID for File System Integrity57314.2.3 Backup Strategies57614.3 TASK SCHEDULING57814.3.1 The at Program57914.3.2 The crontab Program58114.4 SYSTEM MONITORING58414.4.1 Liveness and Starvation58414.4.2 Fairness58714.4.3 Process System-Monitoring Tools58814.4.4 Memory System-Monitoring Tools59014.4.5 I/O System-Monitoring Tools59214.5 LOG FILES59414.5.1 syslogd Created Log Files59514.5.2 Audit Logs59814.5.3 Other Log Files of Note60114.5.4 Log File Rotation60214.6 DISASTER PLANNING AND RECOVERY60414.7 TROUBLESHOOTING60714.8 CHAPTER REVIEW613REVIEW QUESTIONS616BIBLIOGRAPHY, 621APPENDIX: BINARY AND BOOLEAN LOGIC, 631

PrefaceLook around at the Unix/Linux textbook market and you find nearly all of thebooks target people who are looking to acquire hands-on knowledge of Unix/Linux,whether as a user or a system administrator. There are almost no books that serve as textbooks for an academic class. Why not? There are plenty of college courses that cover orinclude Unix/Linux. We tend to see conceptual operating system (OS) texts which includeperhaps a chapter or two on Unix/Linux or Unix/Linux books that cover almost no OSconcepts. This book has been written in an attempt to merge the two concepts into a textbook that can specifically serve a college course about Linux.The topics could probably have been expanded to include more OS concepts, but atsome point we need to draw the line. Otherwise, this text could have exceeded 1000 pages!Hopefully we have covered enough of the background OS concepts to satisfy all students,teachers, and Linux users alike.Another difference between this text and the typical Unix/Linux text is the breadth oftopics. The typical Unix/Linux book either presents an introduction to the OS for users oran advanced look at the OS for system administrators. This book covers Linux from boththe user and the system administrator position. While it attempts to offer thorough coverage of topics about Linux, it does not cover some of the more advanced administrationtopics such as authentication servers (e.g., LDAP, Kerberos) or network security beyonda firewall, nor does it cover advanced programming topics such as hacking open sourcesoftware.Finally, this book differs from most because it is a textbook rather than a hands-on, howto book. The book is complete with review sections and problems, definitions, concepts andwhen relevant, foundational material (such as an introduction to binary and Boolean logic,an examination of OS kernels, the role of the CPU and memory hierarchy, etc.).Additional material is available from the CRC Website: http://crcpress.com/product/isbn/9781482235890.xix

Acknowledgmentsand ContributionsFirst, I am indebted to Randi Cohen and Stan Wakefield for their encouragementand patience in my writing and completing this text. I would also like to thank GaryNewell (who was going to be my coauthor) for his lack of involvement. If I was workingwith Gary, we would still be writing this! I would like to thank my graduate student officemate from Ohio State, Peter Angeline, for getting me into Unix way back when and givingme equal time on our Sun workstation.I am indebted to the following people for feedback on earlier drafts of this textbook. Peter Bartoli, San Diego State University Michael Costanzo, University of California Santa Barbara Dr. Aleksander Malinowski, Bradley University Dr. Xiannong Meng, Bucknell University Two anonymous reviewersI would like to thank the NKU (Northern Kentucky University) students from CIT 370and CIT 371 who have given me feedback on my course notes, early drafts of this textbook,and the labs that I have developed, and for asking me questions that I had to researchanswers to so that I could learn more about Linux. I would like to specifically thank thefollowing students for feedback: Sohaib Albarade, Abdullah Saad Aljohani, Nasir Al Nasir,Sean Butts, Kimberly Campbell, Travis Carney, Jacob Case, John Dailey, Joseph Driscoll,Brenton Edwards, Ronald Elkins, Christopher Finke, David Fitzer, James Forbes, AdamFoster, Joshua Frost, Andrew Garnett, Jason Guilkey, Brian Hicks, Ali Jaouhari, MatthewKlaybor, Brendan Koopman, Richard Kwong, Mousa Lakshami, David Lewicki, DustinMack, Mariah Mains, Adam Martin, Chris McMillan, Sean Mullins, Kyle Murphy, LauraNelson, Jared Reinecke, Jonathan Richardson, Joshua Ross, Travis Roth, Samuel Scheuer,Todd Skaggs, Tyler Stewart, Matthew Stitch, Ayla Swieda, Dennis Vickers, ChristopherWitt, William Young, John Zalla, and Efeoghene Ziregbe.xxi

xxii        Acknowledgments and ContributionsI would like to thank Charlie Bowen, Chuck Frank, Wei Hao, Yi Hu, and Stuart Jaskowiakfor feedback and assistance. I would like to thank Scot Cunningham for teaching me aboutnetwork hardware.I would also like to thank everyone in the open source community who contribute theirtime and expertise to better all of our computing lives.On a personal note, I would like to thank Cheri Klink for all of her love and support,Vicki Uti for a great friendship, Russ Proctor for his ear whenever I need it, and Jim Hughesand Ben Martz for many hours of engaging argumentation.

How to Use This TextbookThis textbook is envisioned for a 1- or 2-semester course on Linux (or Unix). For a1- semester course, the book can be used either as an introduction to Linux or as a system administration course. If the text is used for a 1-semester junior or senior level course,it could potentially cover both introduction and system administration. In this case, theinstructor should select the most important topics rather than attempting complete coverage. If using a 2-semester course, the text should be as for both introduction and systemadministration.The material in the text builds up so that each successive chapter relies, in part, on previously covered material. Because of this, it is important that the instructor follows the chapters in order, in most cases. Below are flow charts to indicate the order that chapters shouldor may be covered. There are three flow charts; one each for using this text as a 1-semesterintroductory course, a 1-semester system administration course, and a 1-semester coursethat covers both introduction and system administration. For a 2-semester sequence, usethe first two flow charts; one per semester. In the flow charts, chapters are abbreviated as“ch.” Chapters appearing in brackets indicate optional material.1-semester introductory course: ch 4 ch 1 ch 2 [appendix] ch 3 ch 6 ch 7 ch 8 ch 5 1-semester system administration course:[ch 5] [ch 6] ch 8 ch 9 ch 10 ch 11 [appendix][ch 7] ch 12 ch 13 ch 14 ch 151-semester combined course:[ch 1] appendix* ch 2 ch 3 ch 4 ch 5* ch 6* ch 7 ch 8* ch 9 ch 10 ch 11 ch 12 ch 13* ch 14xxiii

xxiv        How to Use This TextbookAs the 1-semester combined course will be highly compressed, it is advisable that chapters denoted with an asterisk (*) receive only partial coverage. For Chapter 5, it is recommended that only vi be covered. For Chapter 6, it is recommended that the instructor skipsthe more advanced material on sed and awk. In Chapter 8, only cover operating systeminstallation. In Chapter 13, the instructor may wish to skip material on open source installation and/or gcc.The following topics from the chapters are considered optional. Omitting them will notreduce the readability of the remainder of the text. Chapter 1: the entire chapter (although a brief review of the Gnome GUI would beuseful) Chapter 2: interpreters Chapter 3: Linux file system structure (if you are also going to cover Chapter 10);secondary storage devices; compression algorithms Chapter 5: all material excluding vi Chapter 6: sed and awk Chapter 8: the Linux kernel; virtual memory, SELinux Chapter 12: writing your own network scripts Chapter 13: the gcc compiler; the Open Source Movement Chapter 14: disaster planning and recovery Chapter 15: the entire chapterThis textbook primarily describes Red Hat version 6 and CentOS version 2.6. As thistextbook is being prepared for publication, new versions of Linux are being prepared byboth Red Hat (version 7) and CentOS (version 2.7). Although most of these changes do notimpact the material in this textbook, there are a few instances where version 7 (and 2.7)will differ from what is described here. See the author’s website at www.nku.edu/ foxr/linux/ which describes the significant changes and provides additional text to replace anyoutdated text in this book.

AuthorRichard Fox is a professor of computer science at Northern Kentucky University(NKU). He regularly teaches courses in both computer science (artificial intelligence,computer systems, data structures, computer architecture, concepts of programming languages) and computer information technology (IT fundamentals, Unix/Linux, web serveradministration). Dr. Fox, who has been at NKU since 2001, is the current chair of NKU’sUniversity Curriculum Committee. Prior to NKU, Dr. Fox taught for nine years at theUniversity of Texas—Pan American. He has received two Teaching Excellence awards,from the University of Texas—Pan American in 2000 and from NKU in 2012.Dr. Fox received a PhD in computer and information sciences from Ohio StateUniversity in 1992. He also has an MS in computer and information sciences fromOhio State (1988) and a BS in computer science from University of Missouri Rolla (nowMissouri University of Science and Technology) from 1986.Dr. Fox published an introductory IT textbook in 2013 (also from CRC Press/Taylor &Francis). He is also author or coauthor of over 45 peer-reviewed research articles primarilyin the area of artificial intelligence. He is currently working on another textbook with acolleague at NKU on Internet infrastructure.Richard Fox grew up in St. Louis, Missouri and now lives in Cincinnati, Ohio. He is a bigscience fiction fan and progressive rock fan. As you will see in reading this text, his favoritecomposer is Frank Zappa.xxv

Chapter1Introduction to LinuxThis chapter’s learning objects are To understand the appeal behind the Linux operating system To understand what operating systems are and the types of things they do for the user To know how to navigate using the two popular Linux GUIs (graphical user interfaces) To understand what an interpreter is and does To understand virtual machines (VMs) To understand the history of Unix and Linux To understand the basic components of a computer system1.1 WHY LINUX?If you have this textbook, then you are interested in Linux (or your teacher is making youuse this book). And if you have this textbook, then you are interested in computers andhave had some experience in using computers in the past. So why should you be interested in Linux? If you look around our society, you primarily see people using Windows,Macintosh OS X, Linux, and Unix in one form or another. Below, we see an estimatedbreakdown of the popularity of these operating systems as used on desktop computers.* Microsoft Windows: 90.8% Primarily Windows 7 but also Vista, NT, XP, and Windows 8 Macintosh: 7.6% Mac OS X* Estimates vary by source. These come from New Applications as of November 2013. However, they can be inaccuratebecause there is little reporting on actual operating system usage other than what is tracked by sales of desktop units andthe OS initially installed there.1

2        Linux with Operating System Concepts Linux or Unix: 1.6% There are numerous distributions or “flavors” of Linux and UnixIf we expand beyond desktop computers, we can find other operating systems whichrun on mainframe computers, minicomputers, servers, and supercomputers. Some of theoperating systems for mainframe/minicomputer/server/supercomputer are hardwarespecific such as IBM System i (initially AS/200) for IBM Power Systems. This harkensback to earlier days of operating systems when each operating system was specific to oneplatform of hardware (e.g., IBM 360/370 mainframes). For mobile devices, there are stilla wide variety of systems but the most popular two are iOS (a subset of Mac OS X) andAndroid (Linux-based).With such a small market share for Linux/Unix, why should we bother to learn it?Certainly for your career you will want to learn about the more popular operating system(s).Well, there are several reasons to learn Linux/Unix.First, the Macintosh operating system (Mac OS X) runs on top of a Unix operatingsystem (based on the Mach Unix kernel). Thus, the real market share is larger than it firstappears. Additionally, many of the handheld computing devices run a version of Linux(e.g., Google Android). In fact, estimates are that Android-based devices make up at least20% of the handheld device market. There are other hardware devices that also run Linuxor Unix such as firewalls, routers, and WiFi access points. So Linux, Unix, Mac OS X, andthe operating systems of many handheld devices comes to more than 15% of the total operating system usage.*Second, and more significant, is the fact that a majority of the servers that run on theInternet run Linux or Unix. In 2011, a survey of the top 1 million web servers indicatedthat nearly 2/3s ran Unix/Linux while slightly more than 1/3 ran Microsoft Windows. Theusage of Unix/Linux is not limited to web servers as the platform is popular for file servers,mail servers, database servers, and domain name system servers.That still might not explain why you should study Linux. So consider the following points. Open source (free)—The intention of open source software is to make the source codeavailable. This gives programmers the ability to add to, enhance or alter the code andmake the new code available. It is not just the Linux operating system that is opensource but most of its application software. Enhancements can help secure softwareso that it has fewer security holes. Additions to the software provide new features.Alterations to software give users choices as to which version they want to use. Linux,and all open source software, continues to grow at an impressive rate as more andmore individuals and groups of programmers contribute. As a side effect, most opensource software is also freely available. This is not true of all versions of Linux (e.g.,Red Hat Enterprise Linux is a commercial product) but it is true of most versions.* Other sources of operating system statistics aside from Net Applications include NetMarketShare, StatCounter,ComputerWorld, AT Internet, canalys, Gartner, zdnet, and Linux Journal. See, for instance, marketshare.hitslink.com.

Introduction to Linux        3 Greater control—Although Windows permits a DOS shell so that the user can entercommands, the DOS commands are limited in scope. In Linux/Unix, the commandline is where the power comes from. As a user, you can specify a wide variety ofoptions in the commands entered via the command line and thus control the operating system with greater precision. Many users become frustrated with the Windowsapproach where most control is removed from the users’ hands. The Windowsapproach is one that helps the naive user who is blissfully unaware of how the operating system works. In Linux, the user has the option to use the GUI but for those whowant to be able to more directly control the operating system rather than be controlled by the operating system, the command line gives that level of access. Learning about operating systems—As stated in the last bullet point, Windows helpsshelter users from the details of what the operating system is doing. This is fine formost users who are using a computer to accomplish some set of tasks (or perhapsare being entertained). But som

2.1 INTRODUCTION 37 2.2 ENTERING LINUX COMMANDS 38 2.2.1 Simple Linux Commands 39 2.2.2 Commands with Options and Parameters 40 2.3 MAN PAGES 43 2.4 BASH FEATURES 46 2.4.1 Recalling Commands through History 46 2.4.2 Shell Variables 47 2.4.3 Aliases 51 2.4.4 Command Line Editing 52