Guide to UNIX Using Linux PDF

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Summary

This book is a guide to using UNIX and Linux operating systems. It covers topics such as understanding operating systems, introducing shells, choosing user names and passwords, and using commands. Readers will also learn about file systems, security, using editors, and processing files.

Full Transcript

Guide to UNIX Using Linux FOURTH EDITION Michael Palmer Australia Brazil Japan Korea Mexico Singapore Spain United Kingdom United States Guide to UNIX Using Linux, Fourth Edition © 2008 Course...

Guide to UNIX Using Linux FOURTH EDITION Michael Palmer Australia Brazil Japan Korea Mexico Singapore Spain United Kingdom United States Guide to UNIX Using Linux, Fourth Edition © 2008 Course Technology, Cengage Learning Michael Palmer ALL RIGHTS RESERVED. No part of this work covered by the copyright herein may be reproduced, transmitted, stored or used in any form or by Acquisitions Editor: Nick Lombardi any means graphic, electronic, or mechanical, including but not limited to Publisher, Senior Vice President: photocopying, recording, scanning, digitizing, taping, Web distribution, Kristen Duerr information networks, or information storage and retrieval systems, except Senior Editor: Lisa Egan as permitted under Section 107 or 108 of the 1976 United States Copyright Senior Product Manager: Alyssa Pratt Act, without the prior written permission of the publisher. Product Managers: Molly Belmont and Alyssa Pratt For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706 Development Editor: Deb Kaufmann For permission to use material from this text or product, submit all Technical Editor: John Bosco requests online at cengage.com/permissions Executive Editor: Steve Helba Further permissions questions can be emailed to [email protected] Content Project Manager: Philippa Lehar Editorial Assistant: Claire Jeffers ISBN-13: 978-1-4188-3723-5 Marketing Manager: Gayathri Baskaran ISBN-10: 1-4188-3723-7 Cover Design: Course Technology Design Department Course Technology 25 Thomson Place Text Designer: GEX Publishing Services Boston, Massachusetts 02210 Compositor: GEX Publishing Services USA Cengage Learning is a leading provider of customized learning solutions with office locations around the globe, including Singapore, the United Kingdom, Australia, Mexico, Brazil, and Japan. Locate your local office at: international.cengage.com/region Cengage Learning products are represented in Canada by Nelson Education, Ltd. For your lifelong learning solutions, visit course.cengage.com Purchase any of our products at your local college store or at our preferred online store www.ichapters.com Printed in the United States of America 2 3 4 5 6 7 8 9 TW 12 11 10 09 08 TABLE OF Contents PREFACE XV CHAPTER ONE The Essence of UNIX and Linux 1 Understanding Operating Systems 2 PC Operating Systems 2 Server Operating Systems and Networks 3 Introducing the UNIX and Linux Operating Systems 5 A Brief History of UNIX 5 UNIX Concepts 6 Linux and UNIX 7 Introducing UNIX/Linux Shells 8 Choosing Your Shell 8 Switching from Shell to Shell 9 Choosing User Names and Passwords 10 Connecting to UNIX/Linux Using Telnet or SSH 11 Logging In to UNIX/Linux 13 Using Commands 14 The date Command 15 The cal Command 16 The who Command 18 The clear Command 18 The man Program 18 The whatis Command 21 Command-line Editing 22 Multiple Command Entries 23 The Command-line History 23 Logging Out of UNIX/Linux 23 Understanding the Role of the UNIX/Linux System Administrator 24 The System Administrator’s Command Line 24 The Ordinary User’s Command Line 24 Changing Passwords 25 Viewing Files Using the cat, more, less, head, and tail Commands 26 Redirecting Output 26 Chapter Summary 27 Command Summary: Review of Chapter 1 Commands 28 Key Terms 29 Review Questions 32 Hands-On Projects 36 Discovery Exercises 51 iv Guide to UNIX Using Linux, Third Edition CHAPTER TWO Exploring the UNIX/Linux File Systems and File Security 53 Understanding UNIX/Linux File Systems 54 Understanding the Standard Tree Structure 58 Using UNIX/Linux Partitions 59 Setting Up Hard Disk Partitions 60 Using Inodes 63 Exploring the Root Hierarchy 63 The /bin Directory 64 The /boot Directory 64 The /dev Directory 64 The /etc Directory 66 The /home Directory 68 The /lib Directory 68 The /mnt Directory 68 The /media Directory 69 The /proc Directory 69 The /root Directory 69 The /sbin Directory 69 The /tmp Directory 69 The /usr Directory 69 The /var Directory 70 Using the mount Command 70 Using Paths, Pathnames, and Prompts 72 Using and Configuring Your Command-Line Prompt 72 The pwd Command 74 Navigating the File System 75 Using Dot and Dot Dot Addressing Techniques 76 Listing Directory Contents 77 Using Wildcards 79 Creating and Removing Directories 80 Copying and Deleting Files 81 Configuring File Permissions for Security 82 Chapter Summary 88 Command Summary: Review of Chapter 2 Commands 89 Key Terms 90 Review Questions 93 Hands-On Projects 97 Discovery Exercise 109 CHAPTER THREE Mastering Editors 111 Understanding UNIX/Linux Files 112 ASCII Text Files 112 Binary Files 112 Executable Program Files 113 Using Editors 114 Using the vi Editor 114 Creating a New File in the vi Editor 115 Inserting Text 116 Repeating a Change 116 Moving the Cursor 116 Deleting Text 117 Undoing a Command 118 Searching for a Pattern 118 Searching and Replacing 119 Saving a File and Exiting vi 120 Adding Text from Another File 120 Leaving vi Temporarily 121 Changing Your DisplayWhile Editing 121 Copying or Cutting and Pasting 122 Printing Text Files 122 Canceling an Editing Session 123 Getting Help in vi 123 Using the Emacs Editor 123 Creating a New File in Emacs 125 Navigating in Emacs 127 Deleting Information 127 Copying, Cutting, and Pasting Text 127 Searching in Emacs 127 Reformatting a File 128 Getting Help in Emacs 128 Chapter Summary 128 Command Summary: Review of Chapter 3 Commands 129 Key Terms 130 Review Questions 131 Hands-On Projects 136 Discovery Exercises 153 CHAPTER FOUR UNIX/Linux File Processing 157 UNIX and Linux File Processing 158 Reviewing UNIX/Linux File Types 158 Understanding File Structures 158 Processing Files 160 Using Input and Error Redirection 161 Manipulating Files 161 Creating Files 162 Deleting Files 163 Removing Directories 163 Copying Files 164 Moving Files 166 Finding Files 166 Combining Files 167 Combining Files with the paste Command 168 Extracting Fields Using the cut Command 170 Sorting Files 171 Creating Script Files 172 Using the join Command on Two Files 174 A Brief Introduction to the Awk Program 176 Chapter Summary 178 Command Summary: Review of Chapter 4 Commands 179 Key Terms 181 Review Questions 182 Hands-On Projects 186 Discovery Exercises 210 vi Guide to UNIX Using Linux, Third Edition CHAPTER FIVE Advanced File Processing 213 Advancing Your File-Processing Skills 214 Using the Selection Commands 215 Using the Pipe Operator 215 Using the grep Command 216 Using the uniq Command 218 Using the comm Command 220 Using the diff Command 221 Using the wc Command 222 Using Manipulation and Transformation Commands 223 Introducing the sed Command 223 Translating Characters Using the tr Command 224 Using the pr Command to Format Your Output 225 Designing a New File-Processing Application 226 Designing Records 227 Linking Files with Keys 227 Creating the Programmer and Project Files 229 Formatting Output 231 Using a Shell Script to Implement the Application 232 Running a Shell Script 233 Putting It All Together to Produce the Report 234 Chapter Summary 234 Command Summary: Review of Chapter 5 Commands 235 Key Terms 236 Review Questions 237 Hands-On Projects 241 Discovery Exercises 268 CHAPTER SIX Introduction to Shell Script Programming 271 Previewing the Application 272 The Program Development Cycle 273 Using High-Level Languages 273 Using UNIX/Linux Shell Scripts 275 Prototyping an Application 277 Using Comments 277 The Programming Shell 278 Variables 279 Environment and ConfigurationVariables 279 ShellVariables 283 Shell Operators 285 Defining Operators 285 Evaluating Operators 286 Arithmetic and Relational Operators 286 Redirection Operators 288 Exporting Shell Variables to the Environment 289 Modifying the PATH Variable 289 More About Wildcard Characters 291 Table of Contents vii Shell Logic Structures 291 Sequential Logic 292 Decision Logic 293 Looping Logic 295 The While Loop 297 Case Logic 298 Using Shell Scripting to Create a Menu 299 Debugging a Shell Script 300 Customizing Your Personal Environment 301 The trap Command 302 Putting it All Together in an Application 303 Chapter Summary 304 Command Summary: Review of Chapter 6 Commands 305 Key Terms 306 Review Questions 308 Hands-On Projects 313 Discovery Exercises 337 CHAPTER SEVEN Advanced Shell Programming 339 Understanding Program Design and Analysis 340 Flowcharting 340 Writing Pseudocode 343 Ensuring the Correct Shell Runs the Script 344 Setting the Default Shell 345 Using Bash Login and Logout Scripts 346 Setting Defaults for Using the vi Editor 348 Using the test Command 348 Performing Relational Integer Tests with the test Command 350 Performing String Tests with the test Command 351 Testing Files with the test Command 352 Performing Boolean Tests with the test Command 352 Formatting Record Output 353 Deleting Phone Records 354 Clearing the Screen 355 Creating an Algorithm to Place the Cursor 356 Protecting Against Entering Duplicate Data 358 Using Shell Functions 359 Defining a Function from the Command Line 360 Creating Functions Inside Shell Scripts 361 Troubleshooting a Shell Script 362 Chapter Summary 363 Command Summary: Review of Chapter 7 Commands 364 Key Terms 364 Review Questions 365 Hands-On Projects 369 Discovery Exercises 396 viii Guide to UNIX Using Linux, Third Edition CHAPTER EIGHT Exploring the UNIX/Linux Utilities 399 Understanding UNIX/Linux Utilities 400 Classifying UNIX/Linux Utilities 401 Using the dd Command 405 Checking Hard Disk Usage 407 Using the df Utility 407 Using the du Utility 408 Removing Garbage Files 410 Using System Status Utilities 410 Using the top Command 411 Using the uptime Command 411 Using the free Command 412 Forwarding top and free Output 413 Managing Processes 413 Running Processes in the Background 414 Monitoring Processes 414 Killing Processes 415 Checking the Spelling of a Document 416 Comparing Files 417 Formatting Text in UNIX/Linux 418 Archiving and Backing Up Files 420 Using the dump Command 420 Using the restore Command 422 Using mail to Send Mail 423 Using Networking Utilities 424 Using the ifconfig Utility 425 Using the ping Utility 426 Using the traceroute Utility 426 Using the netstat Utility 427 Sharing Resources Using Network File System 428 Accessing MicrosoftWindows Systems Through Samba 429 Chapter Summary 430 Command Summary: Review of Chapter 8 Commands 431 Key Terms 431 Review Questions 432 Hands-On Projects 436 Discovery Exercises 454 CHAPTER NINE Perl and CGI Programming 457 Introduction to Perl 458 Identifying Data Types 463 Variables and Constants 463 Scalars 463 Numbers 464 Strings 464 Arrays 465 Hashes 467 Perl Versus the Awk Program 467 How Perl Accesses Disk Files 471 Table of Contents ix Using Perl to Sort 473 Using Perl to Sort Alphanumeric Fields 473 Using Perl to Sort Numeric Fields 475 Setting Up a Web Page 478 Creating a SimpleWeb Page 479 CGI Overview 481 Chapter Summary 483 Command Summary: Review of Chapter 9 Commands 483 Key Terms 483 Review Questions 485 Hands-On Projects 489 Discovery Exercises 502 CHAPTER TEN Developing UNIX/Linux Applications in C and C++ 505 Introducing C Programming 506 Creating a C Program 507 C Keywords 508 The C Library 509 Program Format 509 Including Comments 510 Using the Preprocessor #include Directive 510 Specifying Data Types 511 Character Constants 512 Using Strings 512 Including Identifiers 513 Declaring Variables 513 Understanding the Scope of Variables 514 Using Math Operators 514 Generating Formatted Output with printf() 516 Using the C Compiler 517 Using the if Statement 518 Using C Loops 519 Defining Functions 520 Using Function Arguments 521 Using Function ReturnValues 522 Working with Files in C 523 Using the make Utility to Maintain Program Source Files 524 DebuggingYour Program 528 Creating a C Program to Accept Input 529 Introducing C++ Programming 530 Creating a Simple C++ Program 531 Creating a C++ Program That Reads a Text File 532 How C++ Enhances C Functions 533 Chapter Summary 534 Command Summary: Review of Chapter 10 Commands 535 Key Terms 536 Review Questions 537 Hands-On Projects 542 Discovery Exercises 560 x Guide to UNIX Using Linux, Third Edition CHAPTER ELEVEN The X Window System 563 What Is the XWindow System? 564 XWindow Clients and Servers 566 Using Window Managers 567 Using a Desktop 568 Using GNOME 568 Using KDE 569 Starting the XWindow System 569 Configuring Linux to Automatically Start the XWindow System 570 Interacting with the XWindow System Using GNOME 571 Interacting with Windows 572 More About the Window Menu Button 574 Interacting with the Panel 575 Using Nautilus 577 Configuring the Desktop 578 Changing the Background 578 Changing the Screensaver 578 Configuring the Panel 578 Adding a Menu to the Panel 579 Adding a New Panel 579 Shutting Down from the GNOME Desktop 580 Interacting with the XWindow System Using KDE 580 Interacting with Konqueror 581 Interacting with Kicker 583 Configuring the KDE Desktop 585 Changing the Background in KDE 585 Configuring the Screensaver 585 Configuring Additional Desktops 586 Shutting Down from the KDE Desktop 586 OpenOffice.org and Open Source Software 586 Chapter Summary 587 Command Summary: Review of Chapter 11 Commands 588 Key Terms 588 Review Questions 589 Hands-On Projects 594 Discovery Exercises 611 APPENDIX A HOW TO ACCESS A UNIX/LINUX OPERATING SYSTEM 613 Accessing UNIX/Linux Computers from an Attached Terminal 614 Using Telnet 614 Using SSH 615 Accessing a UNIX/Linux System from a MicrosoftWindows Computer 616 Configuring the Telnet Service 617 Starting a Telnet Session 618 Using a UNIX/Linux Computer to Provide Access or to Access Another Computer 618 Where Is My Telnet or SSH Client Program? 618 Enabling Telnet and SSH 619 Connecting via Telnet or SSH 622 Using Mac OS X and SSH to Access a Remote Computer 622 Enabling Remote Login as a Service and Through the Firewall 622 Using SSH via a TerminalWindow 623 Table of Contents xi APPENDIX B SYNTAX GUIDE TO UNIX/LINUX COMMANDS 625 APPENDIX C HOW TO INSTALL FEDORA AND HOW TO USE THE KNOPPIX CD 641 How to Install Fedora 642 Preparing for Installation 642 Installing Fedora 643 Using the Knoppix CD 646 System Requirements for the Knoppix CD 647 Loading the Knoppix CD 647 Saving Your Files on Removable Media 648 Useful Knoppix Tips 651 APPENDIX D UNIX/LINUX VARIANTS 653 PopularVersions of UNIX/Linux 654 UNIX/Linux Command Differences 656 UNIX/Linux Hardware Platforms 657 Choosing a UNIX/LinuxVariant 658 APPENDIX E UNIX/LINUX SECURITY: NETWORK AND INTERNET CONNECTIVITY 661 Security Hardening 662 Implementing Physical System Security 662 Defining and Publishing the Security Policy 662 Ensuring Password Security 663 Managing Unnecessary Services 664 Viewing Log Files on a Regular Basis 665 Keeping Up with Security Fixes and Patches 666 Monitoring Your System Automatically 667 Securing Your Folders and Files 668 Using Kerberos Authentication 669 Glossary 671 Index 683 xii Guide to UNIX Using Linux, Third Edition Preface G uide to UNIX Using Linux, Fourth Edition is updated to include new UNIX/Linux dis- tributions, networking utilities, new UNIX/Linux capabilities, and coverage of both the GNOME and KDE desktops.The large array of commands, utilities, file systems, and other information you learn here applies to any Linux system and most UNIX systems.Within the book four modern Linux operating systems are spotlighted as examples: Fedora, Red Hat Enterprise Linux, SUSE, and Knoppix. Today UNIX and Linux operating systems are popularly used on all types of computers including desktops, portables, and servers. UNIX was the first popular operating system used with the extensive computer network that has become the Internet, and remains a staple of computing. Linux is a UNIX-like operating system first released in 1991 and has become immensely popular for all types of computing applications. Chances are that the next time you access an Internet server it will be running UNIX or Linux.Also, because of strong cus- tomer demand, many computer manufacturers offer pre-installed Linux versions on desktop and server computers. A huge range of software is available for UNIX and Linux systems, including many free or low-cost applications. Through the X Window System and desktop software such as GNOME and KDE, UNIX and Linux provide a graphical user interface that is as versatile and easy to use as on any operating system. At the same time, UNIX and Linux have retained powerful capabilities that can be accessed through time-tested command line inter- faces. In short, UNIX and Linux give you the best of two worlds, comprehensive command features and unbeatable graphical interface options. The concepts you learn in this book help prepare you to use UNIX and Linux on all types of computer systems, including PCs, workstations, servers, and mainframe computers. Through this book you learn to use command-line features, run utilities, create your own applications, and use the GNOME and KDE desktops—giving you a comprehensive foun- dation in UNIX and Linux. Taking a hands-on, practical approach, this book guides you through UNIX and Linux sys- tem and programming concepts.You practice what you learn through self-guided Hands-On Projects, Review Questions, and Discovery Exercises.Your learning is facilitated by a proven combination of tools that powerfully reinforce both concepts and real-world experience. This book includes: Fedora Core 6 (on the DVD bundled with this book), which is a full-featured Linux operating system along with installation instructions Knoppix 5.1.1, which is a Linux operating system with the KDE desktop that you can run from the CD bundled with this book (there is nothing to install) Step-by-step hands-on projects to learn UNIX/Linux commands and utilities, shell programming, data management, text editing, Perl scripts, CGI scripts, Web programming, and C and C++ programming Comprehensive review and end-of-chapter materials, including point-by-point summaries, command summaries, review questions, and discovery exercises—all of which reinforce your learning and enable you to practice and master skills Presentation of the X Window graphical user interface, with a focus on the popu- lar GNOME and KDE desktops and open source applications Review of UNIX/Linux security for all types of situations Extensive screen captures and graphics to visually reinforce the text and hands-on exercises Intended Audience This book is designed to serve anyone who wants to learn UNIX/Linux and how to use the command, desktop, and programming features built into UNIX/Linux. It provides a solid beginning for general UNIX/Linux users, programmers, and system administrators. General users will appreciate learning how to use UNIX/Linux utilities, how to employ command-line commands, and how to use the X Window-based GNOME and KDE interfaces. Programmers and system administrators will be interested in learning how to use all types of powerful programming capabilities in UNIX/Linux.When you finish this book, you will have a valuable foundation in UNIX/Linux skills on which to build for general, personal, or professional use. Chapter Descriptions The chapter coverage is balanced, with each chapter building on the skills and knowledge acquired in the preceding chapters. Here is a summary of what you will learn in each chapter: Chapter 1: The Essence of UNIX and Linux gives you a basic introduction to UNIX and Linux, including how to access a UNIX/Linux system, how to use basic UNIX/Linux commands, and how to choose a shell in which to work.You also learn about the roles of general users and system administrators and how to protect your account through password configuration. xiv Guide to UNIX Using Linux, Third Edition Chapter 2: Exploring the UNIX/Linux File Systems and File Security introduces you to the standard tree structure of files and directories, how to navigate the file system, and how partitions are deployed.You also gain hands-on experience with basic UNIX/Linux utilities to create files and directories, manage them, and make them secure. Chapter 3: Mastering Editors enables you to learn the most commonly used UNIX/Linux editors, vi and Emacs. After you learn how to use these editors, you employ them in later chapters to process data, create scripts, and write programs. Chapter 4: UNIX/Linux File Processing gives you basic techniques for handling data stored in files and for manipulating files.You use file creation and manipulation utilities, including the following: input, output, and error redirection utilities; utili- ties for creating, finding, moving, and deleting files; utilities for cutting, pasting, and sorting file contents; and the join and awk utilities for file processing. Chapter 5: Advanced File Processing builds on the knowledge you learned in Chapter 4, while introducing a more advanced range of file processing utilities that include selection commands, manipulation and transformation commands, and file processing commands. Chapter 6: Introduction to Shell Script Programming gives you an introduction to using shell scripts, which are powerful files containing commands that can be executed as a group.You begin creating shell scripts that use different forms of programming logic. Next, you progress to create a menu, a simple database, and a report—all steps to building your own application.You also learn how to debug scripts. Chapter 7:Advanced Shell Programming builds on the skills you learned in Chapter 6 and enables you to add more functionality to the scripts you have created. You learn advanced techniques for managing data files, testing scripts, formatting screens, and creating shell functions. Chapter 8: Exploring the UNIX/Linux Utilities summarizes many of the utilities you have already learned and introduces you to new utilities for processing files, managing disk usage, monitoring the system status, working with text files, backing up a system, using mail, and using a network.You also create your own manual doc- umentation page for a script-based application you created in Chapters 6 and 7. Chapter 9:Perl and CGI Programming gives you a taste of how to program in Perl,CGI, and HTML to manipulate data, access disk files, and create an interactive Web page. Chapter 10: Developing UNIX/Linux Applications in C and C++ is an introduc- tion to writing C and C++ programs in UNIX/Linux.You build on knowledge of data and logic structures that you have learned earlier in the book and put it to work creating C and C++ programs. Preface xv Chapter 11:The X Window System enables you to learn about the UNIX/Linux X Window graphical interface. In this chapter, you discover how to use and customize the X Window GNOME and KDE desktops. Appendix A: How to Access a UNIX/Linux Operating System shows you how to remotely access a UNIX/Linux system using a terminal, a Microsoft Windows oper- ating system, or a computer running UNIX/Linux, including a computer running Mac OS X. Appendix B: Syntax Guide to UNIX/Linux Commands provides a quick reference and review of the utilities and commands you have learned in this book, including the commands for the vi and Emacs editors. Appendix C: How to Install Fedora and How to Use the Knoppix CD shows you, step-by-step, how to successfully install the Fedora Linux operating system from scratch using the DVD provided with this book.You also learn how to boot from and use the Knoppix CD included with this book. Appendix D: UNIX/Linux Variants provides an overview of some of the most pop- ular UNIX and Linux variants, including the different free and commercial versions of UNIX and Linux. Appendix E: UNIX/Linux Security: Network and Internet Connectivity focuses on security measures you can take to protect your UNIX or Linux operating system. Features To ensure a successful learning experience, this book includes the following learning features: Chapter Objectives. Each chapter in this book begins with a detailed list of the concepts to be mastered within that chapter.This list provides you with a quick ref- erence to the contents of that chapter, as well as a useful study aid. Screen Captures, Illustrations, and Tables. Numerous reproductions of screens and illustrations of concepts aid you in the visualization of theories, concepts, and how to use commands and desktop features. In addition, many tables provide details and comparisons of both practical and theoretical information and can be used for a quick review of topics. Syntax Boxes. Commands are summarized in Syntax boxes that provide the for- mat of a command and a dissection of the command’s purpose plus useful options for that command. End of Chapter Material. The end of each chapter includes the following fea- tures to reinforce the material covered in the chapter: - Chapter Summary. A bulleted list gives a point-by-point summary of the chap- ter, which can be used as a valuable study aid. xvi Guide to UNIX Using Linux, Third Edition - Command Summary. A summary table is provided that lists the commands, their purpose, and any command options covered in the chapter. If a chapter includes a large number of tables for commands, then the Command Summary provides a reference to the appropriate tables for review. - Key Terms. Key terms are placed in bold within each chapter and at the end of the chapter, a summary of each key term is provided. - Review Questions. A list of review questions tests your knowledge of the most important concepts covered in the chapter. - Hands-On Projects. One of the best ways to reinforce learning about UNIX/Linux is to practice the commands, utilities, and programming features. Each chapter in this book contains many Hands-On Projects that give you expe- rience implementing what you have learned. - Discovery Exercises. Each chapter concludes with Discovery Exercises, which provide you with additional hands-on practice using the skills and concepts you have learned in the chapter. Text and Graphic Conventions Wherever appropriate, additional information and exercises have been added to this book to help you better understand what is being discussed in the chapter. Icons throughout the text alert you to additional materials.The icons used in this book are as follows: The Note icon is used to present additional helpful material related to the sub- ject being described. Each Hands-On Project in this book is preceded by the Hands-On icon. Tips are used to present extra information about how to use a command or how to address a particular need. The Cautions are provided to help you anticipate potential problems or mistakes so that you can prevent them from happening. Preface xvii INSTRUCTOR’S MATERIALS The following supplemental materials are available when this book is used in a classroom setting. All of the supplements available with this book are provided to the instructor on a single CD, and are also available online at www.course.com. Electronic Instructor’s Manual. The Instructor’s Manual that accompanies this text- book includes: Additional instructional material to assist in class preparation, including suggestions for classroom activities, discussion topics, quizzes, and additional exercises. Solutions to all end-of-chapter materials, including the Review Questions and Discovery Exercises. ExamView®. This textbook is accompanied by ExamView, a powerful testing software pack- age that allows instructors to create and administer printed, computer (LAN-based), and Internet exams. ExamView includes hundreds of questions that correspond to the topics cov- ered in this text, enabling students to generate detailed study guides that include page references for further review. The computer-based and Internet testing components allow students to take exams at their computers and save the instructor time by grading each exam automatically. PowerPoint presentations. This book comes with Microsoft PowerPoint slides for each chapter.These are included as a teaching aid for classroom presentation, to make available to students on the network for chapter review, or to be printed for classroom distribution. Instructors, please feel at liberty to add your own slides for additional topics you introduce to the class. Figure files. All of the figures and tables in the book are reproduced on the Instructor’s Resource CD, in bitmap format. Similar to the PowerPoint presentations, these are included as a teaching aid for classroom presentation, to make available to students for review, or to be printed for classroom distribution. Script and program files. Files of the scripts and programs used in this book are pro- vided on the Instructor’s Resource CD. System Requirements The following system requirements are recommended to install Fedora Core 6 which comes with this book: A high-end Intel/AMD-class computer that operates at 500 MHz or faster 128 MB of RAM or more (more is preferred for faster response) At least 5 GB of disk space (to install X Window interfaces and applications) xviii Guide to UNIX Using Linux, Third Edition CD or CD/DVD drive Mouse or pointing device The requirements to use the Knoppix CD which comes with this book are: An Intel/AMD-class computer A bootable CD, DVD, or CD/DVD drive 96 MB of RAM to run the operating system and the X Window interface Mouse or pointing device To access a UNIX/Linux host on a local area network to which your computer is con- nected, you need the following software and information: Telnet or SSH installed Either an IP address or the host and domain name of the remote UNIX/Linux system To access a UNIX/Linux host via the Internet, you need the following software and information: Connection to an Internet service provider (ISP) Telnet or SSH installed Either an IP address or the host and domain name of the remote UNIX/Linux system Preface xix Read This Before You Begin There are several ways to set up a lab for the hands-on projects in this text. One is to pro- vide students with their own PCs equipped with a Linux operating system, such as Fedora.This enables students to have the full experience of working with UNIX/Linux, including access to the X Window interface and the GNOME or KDE desktops. Another way to perform the hands-on activities in this book is to provide students with access to a computer running Linux, such as Fedora, Red Hat Enterprise Linux, or SUSE that is configured as a server and connected to a network. Students can access the server remotely from a networked lab equipped with computers running a Microsoft Windows operating system, UNIX/Linux, or Mac OS X, and using the Telnet or SSH capabilities built into these systems. Students can also use computers with any of these operating sys- tems and access the server over an Internet connection from a lab or from home. Yet another way to perform the hands-on activities is for students and readers to install on their own computers the Fedora Core 6 operating system that accompanies this book on a DVD. The book also comes with the Knoppix CD that requires no installation, because it runs from a CD/DVD drive. Students can conveniently use the Knoppix CD on their own computers or on computers in a lab, without installing anything—so the computer is not altered in any way. A few projects cannot be completed via the Knoppix CD, which are those in Chapter 3 involving the Emacs editor and the GNOME desktop projects in Chapter 11. The Knoppix CD does, however, enable students and readers to complete the projects in Chapter 11 for the KDE desktop. ACKNOWLEDGMENTS It has been a great experience to update this book and to work with the people at Delmar/Course Technology who take publications to the highest level. I am grateful to Nick Lombardi, the Acquisitions Editor, for his interest in and support of this book. Deb Kaufmann, with whom I have worked on many books, has been outstanding as the Development Editor. Deb lights up a project with encouragement, wisdom, good will, and unfailing masterful editing. I’m also very grateful to the Product Managers Molly Belmont and Alyssa Pratt for their support and for ably guiding the teams that have pro- duced this book. Philippa Lehar is the Content Product Manager who has skillfully worked to ensure the success of each step through the production process. Further, I am grateful to Sandra Mitchell, the Product Manager for GEX Publishing Services. xx Guide to UNIX Using Linux, Third Edition On a technical level, special thanks go to John Bosco of Greenpen Quality Assurance, the Technical Editor for this book. John has been amazing in his close reading and thorough testing (two complete passes) of all text, projects, review questions, and discovery exercises— a process that takes hours of work. I am also very indebted to the four peer reviewers Desmond Chun (Chabot College), Robert Guess (Tidewater Community College), Bradley Rounding (Clayton State University), and Diana Stinson (Southwest Virginia Community College) who have conscientiously examined and evaluated this book provid- ing vital insights for improvements and additions. Further, the Copyeditor Dan Marinis has done fine work to tune the language for clearer presentation. Finally, and very importantly, my thanks go to you the reader for using this book and for your interest in UNIX and Linux. D E D I C AT I O N I dedicate this book to my family who are a constant source of joy and support. — Michael Palmer CHAPTER 1 THE ESSENCE OF UNIX AND LINUX After reading this chapter and completing the exercises, you will be able to: ♦ Explain operating systems, including PC and server operating systems ♦ Describe the UNIX and Linux operating systems ♦ Explain the purpose of UNIX/Linux shells ♦ Understand how to select user names and passwords ♦ Connect to UNIX/Linux using Telnet or SSH ♦ Use basic UNIX/Linux commands and command-line editing features ♦ Explain the role of a system administrator ♦ Change your password for security ♦ Use multiple commands to view the contents of files ♦ Redirect output to a file U NIX and the UNIX look-alike system Linux both have something for everyone. For the everyday user, these are friendly systems that offer a huge array of commercial and free software, including a free office suite. For the programmer, UNIX and Linux are ideal for collaborative development of software because they offer powerful tools and utilities. For the system admin- istrator, UNIX and Linux contain time-tested and leading-edge tools for networking and multiuser management. In this book, you learn UNIX through the eyes of Linux. Linux is a modern operating system that has generated significant interest among all kinds of computer users—from general users to computer professionals. Also, it is a popular server system on the Web and in businesses. If you use Google to find something on the Internet, you are using a Linux Web server. This chapter introduces you to operating systems in general and then explains the UNIX and Linux operating systems in particular. You also get an intro- duction to UNIX/Linux commands and command-line editing. As a variant of UNIX, Linux runs on PCs with Intel-type processors, but uses the same file 1 2 Chapter 1 The Essence of UNIX and Linux systems and commands as other UNIX versions. Linux can be run from an individual PC workstation or as a server operating system that is accessed through a network. When you access it through a network, you might use an old-fashioned UNIX terminal, a modern UNIX or Linux workstation, or aWindows-based workstation. Several versions of Linux are available, but this book uses Fedora, Red Hat Enterprise Linux, SUSE Linux, and Knoppix as examples (Knoppix examples are mentioned in the Hands-on Projects). These are among the most popular versions of Linux. Red Hat Enterprise Linux is a commercial version of Linux, and Fedora is a Red Hat-sponsored development project offering a free Linux version. SUSE Linux is sponsored by Novell in the commercial SUSE Linux Enterprise version and in the free openSUSE version. Knoppix is a free version of Linux that can be run from a CD/DVD and is well suited for educational use, but is also used in home and production environments. The commands and programming techniques you learn in this book can be applied to other UNIX and Linux versions. You can learn more about Fedora at fedora.redhat.com. To find out more about Red Hat Enterprise Linux, go to www.redhat.com, and you can learn more about openSUSE Linux at en.opensuse.org/Welcome_to_openSUSE.org. For information about SUSE Linux Enterprise, visit www.novell.com. UNDERSTANDING OPERATING SYSTEMS An operating system (OS) is the most important program that runs on a computer. Operating systems enable you to store information, process raw data, use application software, and access all hardware attached to a computer, such as a printer or keyboard. In short, the operating system is the most fundamental computer program. It controls all the computer’s resources and provides the base upon which application programs can be used or written. Figure 1-1 shows the relationship between an operating system and other parts of a computer system. Different computer systems can have different operating systems. For example, the most common operating systems for desktop personal computers are Microsoft Windows, Mac OS, and Linux.Popular network andWeb server computer operating systems are MicrosoftWindows Server, UNIX/Linux, Novell NetWare, Novell Open Enterprise Server (which combines Netware and SUSE Linux Enterprise), and Mac OS X Server. Very large servers that are mainframe-class computers might use UNIX/Linux or the IBM z/OS operating system. PC Operating Systems A personal computer system, or PC, is usually a stand-alone machine, such as a desktop or laptop computer. A PC operating system conducts all the input, output, processing, and storage operations on a single computer. Figure 1-2 identifies some popular PC operating systems. Understanding Operating Systems 3 Programmers Application programs Users 1 Operating system CPU Monitor Keyboard Mouse Printer Disk drive Hardware Figure 1-1 Operating system model Microsoft Windows Linux Mac OS Figure 1-2 Common PC operating systems Server Operating Systems and Networks Server operating systems are at the heart of a computer network. A computer network combines the convenience and familiarity of the personal computer with the ability to share files and other computer resources. With a network, you can share resources and exchange information with someone in the next room or on the other side of the world. Networked computers are connected by cables and through wireless communications.The Internet is one of the best examples of a network. A server operating system controls the operations of a server computer, sometimes called a host computer, which accepts requests from user programs running on other machines, called clients. A server provides multiuser access to network resources, including shared files, hard disks, and printers. Figure 1-3 shows the relationship of a server and its clients on a network. Servers can be PC-type computers, clusters of PC-type computers working as one or several units, or mainframes. A mainframe is a large computer that has 4 Chapter 1 The Essence of UNIX and Linux historically offered extensive processing, mass storage, and client access for industrial- strength computing. Mainframes are still in use today, but many have been replaced by PC-type computers that are designed as servers with powerful processing and disk storage capabilities—and cost considerably less than mainframes. Server Client Client Client Client Figure 1-3 Relationship of a server and clients on a network A server can be on a private or public network. For example, a server that stores legal files and accounting information in a law office is on a private network. AWeb server, such as the one at www.redhat.com for Red Hat’s Web site, is an example of a server on a public network. In a centralized approach, the users’ data and applications reside on the server. This type of network is called a server-based network. The system administrator secures all the information on the network by securing the server. The system administrator easily maintains the users’ applications and performs backup operations directly on the server. If the server fails, however, clients cannot do their work until the server is returned to service. Peer-to-peer networks, which are often used on small networks, are more distributed than server-based networks. In a peer-to-peer configuration, each system on the network is both a server and a client. There is no central server to manage user accounts; instead, each peer offers its own shared resources and controls access to those resources, such as through a workgroup of designated members or through accounts created on that peer workstation. Data and applications reside on the individual systems in the network. Software upgrades and backup operations must be performed locally at each computer. Security, which is implemented on each computer, is not uniform. Each user of the network is, to some degree, responsible for administering his or her own system. Despite the disadvantages a peer-to-peer network presents to the system administrator, the individual users do not depend on a central server. If one computer in the network fails, the other systems continue to operate. Introducing the UNIX and Linux Operating Systems 5 INTRODUCING THE UNIX AND LINUX OPERATING SYSTEMS 1 UNIX and Linux are multiuser, multitasking operating systems with built-in networking functions. UNIX/Linux can be used on systems functioning as: Dedicated servers in a server-based network Client workstations connected to a server-based network Client/server workstations connected to a peer-to-peer network Stand-alone workstations not connected to a network UNIX/Linux are multiuser systems, which let many people simultaneously access and share the resources of a server computer. Users must log in by typing their user name and a password before they are allowed to use a multiuser system. This validation procedure protects each user’s privacy and safeguards the system against unauthorized use. UNIX and Linux are multitasking systems that allow one user to execute more than one program at a time. For example, you can update records in the foreground while your document prints in the background. UNIX/Linux are also portable operating systems. Portability means these systems can be used in a variety of computing environments. In fact, they run on a wider variety of computers than any other operating system. They connect to the Internet, executing popular programs such as File Transfer Protocol (FTP), an Internet protocol used for sending files, and Telnet, an Internet terminal emulation program. A terminal emulation program is one that enables a PC to respond like a terminal (sometimes called a dumb terminal), which is a device that has a monitor and keyboard, but no CPU. In addition to Telnet, most UNIX/Linux systems now employ Secure Shell (SSH), which is a form of authentication (a process of verifying that a user is authorized to access a computer) developed for UNIX/Linux systems to provide security for communications over a network, including FTP applications. You learn about SSH later in this chapter. Many organizations choose UNIX and Linux because these operating systems: Enable employees to work on a range of computers (portability) Are stable, reliable, and versatile Have thousands of applications written for them, both commercial and free Offer many security options Are well suited for networked environments (UNIX was one of the first server operating systems to be used on a network in the late 1960s.) A Brief History of UNIX A group of programmers at AT&T Bell Labs originally developed UNIX in the late 1960s and early 1970s. Bell Labs distributed UNIX in its source code form, so anyone who used 6 Chapter 1 The Essence of UNIX and Linux UNIX could customize it as needed. Attracted by its portability and low cost, universities began to modify the UNIX code to make it work on different machines. Eventually, two standard versions of UNIX evolved:AT&T Bell Labs produced System V (SysV), and the University of California at Berkeley developed Berkeley Software Distribution (BSD). Using features of both versions, Linux might be considered a more integrated version of UNIX than its predecessors. Currently, the Portable Operating System Interface for UNIX (POSIX) project, a joint effort of experts from industry, academia, and government, is working to standardize UNIX. At this writing, Bell Labs is now part of Alcatel Lucent. For a review of the Bell Labs inventions that have had a profound impact on the world, including the UNIX operating system and the transistor, go to www.alcatel-lucent.com/wps/ portal/BellLabs/Top10Innovations. You can also learn more about Bell Labs and its discoveries at en.wikipedia.org/wiki/Bell_Labs. For a more complete look at the history of UNIX, visit www.unix.org/what_is_ unix/history_timeline.html. You can also read an historic paper about UNIX by Dennis Ritchie at cm.bell-labs.com/cm/cs/who/dmr/hist.html. Dennis Ritchie has played key roles in the development of UNIX and the C programming language. UNIX Concepts UNIX pioneered concepts that have been applied to other operating systems. For example, Microsoft DOS (Microsoft’s early PC operating system) and Microsoft Windows adopted original UNIX design concepts, such as the idea of a shell, which is an interface between the user and the operating system, and the hierarchical structure of directories and subdirectories. The concept of layered components that make up an operating system also originated with UNIX. Layers of software surround the computer system’s inner core to protect its vital hardware and software components and to manage the core system and its users. Figure 1-4 shows how the layers of a UNIX system form a pyramid structure. At the bottom of the pyramid is the hardware. At the top are the users. The layers between them provide insulation, ensuring system security and user privacy. The kernel is the base operating system, and it interacts directly with the hardware, software services, application programs, and user-created scripts (which are files containing commands to execute). It is accessible only through Kernel mode, which is reserved for the system administrator. This prevents unauthorized commands from invading basic operating system code and hardware, resulting in actions that might hang or disrupt smooth operating system functions. User mode provides access to higher layers where all application software resides. This layered approach, and all other UNIX features, were designed by programmers for use in complex software development. Because the programmers wrote UNIX in the C Introducing the UNIX and Linux Operating Systems 7 1 Users Access through User mode Shells Access through Kernel mode UNIX operating system (kernel) Hardware Figure 1-4 Layers of a UNIX system programming language, this operating system can be installed on any computer that has a C compiler. This portability, flexibility, and power make UNIX a logical choice for a network operating system. In addition, with the growth in popularity of Linux, more and more organizations are moving from UNIX and Windows to Linux. Linux and UNIX Linux is a UNIX-like operating system because it is not written from the traditional UNIX code. Instead, it is original code (the kernel) created to look and act like UNIX, but with enhancements that include the POSIX standards. Linus Torvalds, who released it to the public free of charge in 1991, originally created Linux. A number of organizations and companies now offer free and commercial distributions or versions of Linux. The following list is a sampling of Linux distributions: Debian GNU/Linux (free, see www.debian.org) Fedora (free, see fedoraproject.org) Knoppix (free, see www.knoppix.org) Mandriva (commercial and free versions, see www.mandriva.com) Red Hat Enterprise Linux (commercial, see www.redhat.com) openSUSE Linux (free, see en.opensuse.org/Welcome_to_openSUSE.org) SUSE Linux Enterprise (commercial, see www.novell.com) 8 Chapter 1 The Essence of UNIX and Linux Turbo Linux (commercial and free versions, see www.turbolinux.com) Ubuntu (free, see www.ubuntu.com) Linux offers all the complexity of UNIX and can be obtained at no cost; or, for a relatively small amount of money,you can purchase commercial versions that have specialized tools and features. With all the networking features of commercial UNIX versions, Linux is robust enough to handle large tasks. You can install Linux on your PC, where it can coexist with other operating systems, and test your UNIX skills. All these features make Linux an excellent way to learn UNIX, even when you have access to other computers running UNIX. INTRODUCING UNIX/LINUX SHELLS The shell is a UNIX/Linux program that interprets the commands you enter from the keyboard. UNIX/Linux provide several shells, including the Bourne shell, the Korn shell, and the C shell. Stephen Bourne at AT&T Bell Labs developed the Bourne shell as the first UNIX command processor. Another Bell employee, David Korn, developed the Korn shell. Compatible with the Bourne shell,the Korn shell includes many extensions,such as a history feature that lets you use a keyboard shortcut to retrieve commands you previously entered. The C shell is designed for C programmers’ use. Linux uses the freeware Bash shell as its default command interpreter. Its name is an acronym for “Bourne Again Shell,” and it includes the best features of the Korn and Bourne shells. No matter which shell you use, your initial communications with UNIX/Linux always take place through a shell interpreter. Figure 1-5 shows the role of the shell in UNIX/Linux. If you use a graphical user interface (GUI) desktop (similar to Microsoft Windows with graphics and icons), which you learn about later in this chapter and in Chapter 11, then your communications occur through the GUI desktop. To use commands, you open a special window, called a terminal window, and your communications with the operating system occur through a shell interpreter within the terminal window. Most versions of UNIX and Linux that support using a GUI desktop offer a terminal window. This is a powerful feature because it is literally your window to using commands. All of the commands that you learn in this book can be used in a terminal window or directly from the command line on a system that does not use a GUI desktop. Choosing Your Shell Before working with a UNIX/Linux system, you need to determine which shell to use as your command interpreter. Shells do much more than interpret commands: Each has extensive built-in commands that, in effect, turn the shells into first-class programming languages. (You pursue this subject in depth in Chapter 6, “Introduction to Shell Script Programming,” and Chapter 7,“Advanced Shell Programming.”) A default shell is associated with your account when it is created, but you have the option to switch to a different shell Introducing UNIX/Linux Shells 9 Shell 1 UNIX/Linux operating system users input output Figure 1-5 Shell’s relationship to the user, operating system, and computer after you log in. Bash is the default shell in Linux, and it is the shell many users prefer. The following is a list of shells: Bourne Korn (ksh) C shell (csh) Bash ash (a freeware shell derived from the Bourne and C shells) tcsh (a freeware shell derived from the C shell) zsh (a freeware shell derived from the Korn shell) Switching from Shell to Shell After you choose your shell, the system administrator stores your choice in your account record, and it becomes your assigned shell. UNIX/Linux use this shell any time you log in. However, you can switch from one shell to another by typing the shell’s name (such as tcsh, 10 Chapter 1 The Essence of UNIX and Linux bash, or ash) on your command line. You work in that shell until you log in again or type another shell name on the command line. Users often use one shell for writing shell scripts (programs) and another for interacting with a program. (In Hands-on Project 1-8 later in this chapter, you learn how to switch shells, and in Chapter 7, you learn how to set your own default shell.) CHOOSING USER NAMES AND PASSWORDS Before you can work with UNIX/Linux, you must log in by providing a unique user name and password. Decide on a name you want to use to identify yourself to the UNIX/Linux system, such as “aquinn.”This is the same name others on the UNIX/Linux system use to send you electronic mail. Some UNIX versions recognize only the first eight characters of a user name, but most versions of Linux, such as Fedora, Red Hat Enterprise Linux, and SUSE, recognize up to 32 characters. You must also choose a password, which must contain six or more characters when using newer versions of UNIX/Linux, such as Fedora, Red Hat Enterprise Linux, and SUSE. The password should be easy for you to remember but difficult for others to guess, such as a concatenation of two or more words that have meaning to you—a combination of hobbies or favorite places, for example—written in a mix of uppercase and lowercase letters, numbers, and other characters. The password can contain letters, numbers, and punctuation symbols, but not control characters, such as Ctrl+x. (Control characters are codes that are a combination of the Control key and a letter, such as x, and that offer services to perform a specific action on a computer.) The default minimum password length depends on your version of UNIX/Linux. Some earlier versions of Linux have a minimum length of five characters, but Fedora, Red Hat Enterprise Linux, and SUSE require a minimum length of six characters, which is the practice used in this book. You can log in to any UNIX or Linux system as long as you have a user account and password on the workstation or host (server) computer. A UNIX/Linux system adminis- trator creates your account by adding your user name (also called a login name or user ID) and your password. You can change your password at any time by using the passwd command. You’ll learn how to use the passwd command later in this chapter. To use this book and the Hands-on Projects, you must have an account on a UNIX or Linux system along with some means to connect to that system. Some of the common ways to connect or to access a UNIX/Linux system are: Through a Telnet or SSH connection to a remote computer, such as from another UNIX/Linux or aWindows-based operating system (Not all versions of Windows implement SSH, but you can obtain SSH from a third-party source, such as SSH Communications Security at www.ssh.com.) Connecting to UNIX/Linux Using Telnet or SSH 11 Through client software on a UNIX/Linux client/server network As a peer on a peer-to-peer, local area network in which each computer has the 1 UNIX/Linux operating system installed On a stand-alone PC that has the UNIX/Linux operating system installed Through a dumb terminal connected to a communications port on a UNIX/ Linux host Appendix A, “How to Access a UNIX/Linux Operating System,” describes several access methods, including how to set up and use Telnet or SSH. Also, see Appendix C, “How to Install Fedora and How to Use the Knoppix CD” for instructions on how to install the Fedora version of Linux on your computer and how to run Knoppix from the CD included with this book. The steps you take to connect to a UNIX/Linux system vary according to the kind of connection you use. Connecting via a dumb terminal or accessing the OS through a stand-alone system are two of the easiest methods. In both cases, you need to log in to your account. Connecting by using client software for a client/server network might take special instructions or training from a network administrator. If you connect on a peer-to-peer network, you can use Telnet or SSH. Connecting through Telnet or SSH are common methods and are described in the next section. You can use Telnet or SSH to access a UNIX/Linux peer or server computer over a local area network and through the Internet. Appendix A also discusses how to connect over a network using different methods. CONNECTING TO UNIX/LINUX USING TELNET OR SSH Telnet is a terminal emulation program. It runs on your computer and connects your PC to a server, or host, on the network. The PC from which you connect can be running UNIX, Linux, a Windows-based operating system, or Mac OS. You can then log in to a UNIX/ Linux host and begin working. Most UNIX/Linux versions include Telnet, as do most versions of Microsoft Windows and later versions of Mac OS. Each computer on the Internet has an Internet Protocol (IP) address. An IP address is a set of four numbers (in the commonly used IP version 4) separated by periods, such as 172.16.1.61. Most systems on the Internet also have a domain name, which is a name that identifies a grouping of computer resources on a network. Internet-based domain names consist of three parts: a top-level domain (such as a country or organization type), a subdomain name (such as a business or college name), and a host name (such as the name of a host computer). An example using the three-part identification is research.campus.edu, in which “research” is the host name, “campus” is the subdomain name, and “edu” is the 12 Chapter 1 The Essence of UNIX and Linux top-level domain. Both the IP address and the domain name identify a system on the network. Programs such as Telnet use IP addresses or domain names to access remote systems. The general steps used to access a UNIX/Linux host via Telnet are: 1. Determine the remote host’s IP address or domain name. 2. Connect to your network or the Internet. 3. Start your Telnet program, and connect to the UNIX/Linux system. For example, to start Telnet in Windows XP orVista, open a Command Prompt window, type telnet, and press Enter. To connect to Telnet in Fedora, Red Hat Enterprise Linux, or SUSE, open a terminal window, type telnet, and press Enter. 4. Follow the instructions in your Telnet program to connect to a remote host. Usually, you must provide the host name or IP address to connect to a UNIX/Linux system. For example, after the command prompt in a Windows 2000/XP/Server 2003/Vista Command Prompt window or at the UNIX/ Linux command line to access the system lunar.campus.edu, you can type the following command: telnet lunar.campus.edu Press Enter after you type the command. 5. Provide a user name and password to log in to the remote UNIX/Linux computer. Secure Shell (SSH) was developed for UNIX/Linux systems to provide authentication security for TCP/IP applications, such as FTP and Telnet. Historically, the authentication for these applications has largely consisted of providing an unencrypted account and password, making both extremely vulnerable. SSH applies modern security techniques to ensure the authentication of a communications session. SSH can encrypt communications as they go across a network or the Internet. In Fedora, Red Hat Enterprise Linux, SUSE, and other versions of UNIX/Linux, the ssh command can be used instead of telnet to establish a secure connection to a remote computer also running UNIX/Linux and that is compatible with openSSH. openSSH is a version of SSH that includes protocols and software intended for free distribution and which can be used on many UNIX/Linux systems. To use ssh, you open a terminal window (or access the command line) and enter ssh -l on the command line along with the user account name and the name of the host computer. Two other options are to enter ssh with user@hostname or ssh with the IP address. Hands-on Project 1-1 shows you how to useTelnet inWindows 2000/XP/Vista, and Hands-on Project 1-2 shows you how to access a terminal window in Fedora, Red Hat Enterprise Linux, or SUSE and use ssh to access a remote computer. Connecting to UNIX/Linux Using Telnet or SSH 13 To use Telnet or SSH, you need to enable them on your system. See the note with Hands-on Project 1-1 to learn how to enable Telnet or SSH in different 1 UNIX/Linux systems. Logging In to UNIX/Linux After you boot or connect to a UNIX/Linux system, you must log in by specifying your user name and password. You should see either a command line or a login dialog box if you are using a graphical user interface (GUI). For security, the password does not appear on the screen as you type it. When you connect through the network or a dumb terminal, you log in and execute commands using a command-line screen. If you are on a stand-alone PC, the system might be configured to use only the command-line (text) mode, or it might be configured using a GUI. In UNIX/Linux, the foundation of a GUI is called the X Window interface. The X Window interface can have a different look and feel depending on what desktop environ- ment is used with it. The Fedora examples and figures in this book use the popular (and free) GNU Network Object Model Environment (GNOME) desktop. GNU stands for “Gnu’s Not Unix,” which was an endeavor started in 1983 to develop a free, open-standards, UNIX-like operating system (and additional operating system utilities). In the beginning, they were typically written in the C language. To learn more about the GNOME Project, visit the Web site at www.gnome.org. Also, you learn more about the X Window interface and GNOME desktop in Chapter 11, “The X Window System.” You cannot log in without an authorized user account. If your password fails, or if you wait too long before entering your user name and password, contact your system administrator for help. After you log in, you are ready to begin using the system. If you access UNIX/Linux through a network or a dumb terminal—or if your stand-alone system is configured for the command-line text mode—you can immediately enter commands at the command prompt. However, if you are using a stand-alone computer and an X Window desktop such as GNOME, you must open a terminal window (see Figure 1-6) to access the command prompt. Hands-on Project 1-2 demonstrates how to access a terminal window in Fedora, Red Hat Enterprise Linux, or SUSE (to execute the ssh command). 14 Chapter 1 The Essence of UNIX and Linux Figure 1-6 Terminal window in Fedora USING COMMANDS To interact with UNIX/Linux, you enter a command, which is text you type after the command prompt. When you finish typing the command, press Enter. UNIX/Linux are case sensitive; that is, they distinguish between uppercase and lowercase letters, so John differs from john. You type most UNIX/Linux commands in lowercase. Commands are divided into two categories: user-level commands that you type to perform tasks, such as retrieve information or communicate with other users, and system- administration commands, which the system administrator uses to manage the system. You must know a command’s syntax to enter it properly. Syntax refers to a command’s format and wording, as well as the options and arguments you can use to extend and modify its functions. Most commands are single words, such as the command clear. If you enter a command using correct syntax, UNIX/Linux execute the command. Otherwise, you receive a message that UNIX/Linux cannot interpret your command. Appendix B, “Syntax Guide to UNIX/Linux Commands,” alphabetically lists all the commands in this book and tells you how to enter each command and use its options. Using Commands 15 The place on the screen where you type the command is called the command line (refer to Figure 1-6). Commands use the following syntax: 1 Syntax command_name [-option] [argument] Dissection The command_name specifies what operation to perform. In the syntax illustrations in this book, command names appear in boldface. (In regular text, command names appear in italic.) Command options are ways to request that UNIX/Linux carry out a command in a specific style or variation. Options follow command names, separated by a space. They usually begin with a hyphen (-). Options are also case sensitive. For example, -R differs from -r. You do not need to type an option after every command; however, some commands do not work unless you specify an option. The syntax illustrations in this book list options in square brackets ([ ]) when the command does not require them. Command arguments follow command options, separated by white space (blank space). Command arguments are usually file and directory names. In the syntax illustrations in this book, arguments appear in italic. Square brackets surround arguments if the command does not require them. In the following sections, you start your journey learning UNIX/Linux with an introduc- tion to the following basic commands: date cal who clear man whatis You also learn command-line editing techniques, how to enter multiple commands, and how to recall commands you’ve used previously. And, you learn how to log out of an active session. The date Command The UNIX/Linux date command displays the system date, which the system administrator maintains (see Figure 1-7). Because the date and time on a multiuser system are critical for applications, only the system administrator can change the date. For example, the Accounting Department might need to associate a date with a specific file used for reporting tax information, or the Publications Department might have to date stamp a document to ensure a specific copyright date. 16 Chapter 1 The Essence of UNIX and Linux Figure 1-7 Using the date command The date command has an option,-u,which displays the time in Greenwich MeanTime (GMT). GMT is also known as Greenwich Meridian Time and Coordinated Universal Time (UTC). UTC is considered the international time standard. To learn more about UTC, visit NASA’s Web page at www.ghcc.msfc.nasa.gov/utc.html. Hands-on Project 1-3 enables you to use the date command. Syntax date [-option] Dissection Displays the system date and time Commonly used options include: -u view Greenwich Mean Time -s to reset the date or time The cal Command Use the cal command to show the system calendar. This command can be useful for scheduling events or determining a specific date of a project you completed in the past or Using Commands 17 intend to complete in the future. The cal command can also be used to determine the Julian date, by using cal -j at the command line. The Julian date is the number of the date from the 1 beginning of the year, and is a value between 1 and 366 (including leap year). Programmers sometimes use the Julian date for specific programming functions, such as determining the number of days an employee has worked in an organization for the current year. Figure 1-8 shows the results of the command cal -j 2009, showing the Julian date for monthly calendars in 2009. Hands-on Project 1-4 enables you to use the cal command. Figure 1-8 Using the cal command to determine the Julian date Syntax cal [-option] Dissection Generates a calendar for the current year or for a year specified by the user Commonly used options include: -j for Julian date -s to show Sunday as the first day in the week -m to show Monday as the first day in the week -y to show all of the months for the current year 18 Chapter 1 The Essence of UNIX and Linux The who Command To determine information about who is logged in, use the who command. In a multiuser system, knowing who is logged in to the system is important for the administrator, so the administrator can periodically verify authorized users and levels of use. Knowing who is logged in is also valuable for ordinary users, who can use that information to judge how busy the system is at a given time or who might want to contact another user. Syntax who [-option] Dissection Provides a listing of those logged in to the operating system Commonly used options include: am i (type who in front, as in who am i ) for information about your own session whoami (type whoami as all one word) to see what account you are using -H to show column headings -u to show idle time for each user (the older -i is being retired from the who options) -q for a quick list and total of users logged in -b used by system administrators and others to verify when the system was last booted Try Hands-on Project 1-5 to learn how to use the who command. The clear Command As you continue to enter commands, your screen might become cluttered. Unless you need to refer to commands you previously entered and to their output, you can use the clear command to clear your screen. It has no options or arguments. You use the clear command in Hands-on Project 1-6. Syntax clear Clears the terminal screen, display, or terminal window The man Program For reference, UNIX/Linux include an online manual that contains all commands, including their options and arguments. The man program in UNIX/Linux displays this online manual, called the man pages, for command-line assistance. Although the man pages for some commands contain more information than others, most man pages list the following items: Name—The name of the command and a short statement describing its purpose Using Commands 19 Synopsis—A syntax diagram showing the usage of the command Description—A more detailed description of the command than the name item 1 gives as well as a list of command options and their descriptions Author—The name or names of the author or authors who developed the command or program (if available) Reporting Bugs—The information about how to report bugs or problems History—The information that is sometimes included to show where the com- mand originated Other Versions—The information that is sometimes included to indicate there are other versions of the command available See Also—The other commands or man pages that provide related information The man program usually accepts only one argument—the name of the command about which you want more information. The online manual shows the valid command formats that your system accepts. To close the online manual, type q. Syntax man [-option] argument Dissection Shows information from the online documentation Example options include: -d to print information for debugging -f displays a short description of a command (produces the same information as using the whatis command described in the next section) -K to find a certain string by searching through all of the man information The argument is to supply the name of the command or program you want to learn more about, such as man who As an example, consider the man pages for the cal command, as shown in Figures 1-9 and 1-10. In this example, the top line shows the name of the command, which is cal, and a brief description,which is“displays a calendar.”Next,the Synopsis section provides information about the way in which the command is used, showing that it can be used with options, such as any of -smjyl3, as well as specifying the month or year as arguments. The Description section provides more information about the purpose of the cal command and explains the default usage, such as that the current month is displayed if there are no arguments used. The Description section also shows the options, such as -s to display the calendar starting with Sunday. In Figure 1-10, more information about the use of the cal command appears at the end of the Description section. The History section shows that this command appeared inVersion 6 AT&T UNIX. Finally, the OtherVersions section contains information about other versions of cal that you can obtain and use,and at the end a date shows when this man page was written or updated. 20 Chapter 1 The Essence of UNIX and Linux Figure 1-9 man page for the cal command Figure 1-10 Additional information from the man documentation for the cal command Using Commands 21 Many systems also offer info pages in addition to the man p

Use Quizgecko on...
Browser
Browser