Praise For The First Edition Of A Practical Guide To

3y ago
14 Views
2 Downloads
5.17 MB
1.1K Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Julia Hutchens
Transcription

Praise for the First Edition of A Practical Guide toLinux Commands, Editors, and Shell Programming “This book is a very useful tool for anyone who wants to ‘look underthe hood’ so to speak, and really start putting the power of Linux towork. What I find particularly frustrating about man pages is that theynever include examples. Sobell, on the other hand, outlines very clearlywhat the command does and then gives several common, easy-tounderstand examples that make it a breeze to start shell programmingon one’s own. As with Sobell’s other works, this is simple, straight-forward, and easy to read. It’s a great book and will stay on the shelf ateasy arm’s reach for a long time.”—Ray BartlettTravel Writer“Overall I found this book to be quite excellent, and it has earned a spoton the very front of my bookshelf. It covers the real ‘guts’ of Linux—the command line and its utilities—and does so very well. Its strongestpoints are the outstanding use of examples, and the Command Reference section. Highly recommended for Linux users of all skill levels.Well done to Mark Sobell and Prentice Hall for this outstanding book!”—Dan CloughElectronics Engineer andSlackware Linux user“Totally unlike most Linux books, this book avoids discussing everything via GUI and jumps right into making the power of the commandline your friend.”—Bjorn TiplingSoftware Engineerask.com“This book is the best distro-agnostic, foundational Linux reference I’veever seen, out of dozens of Linux-related books I’ve read. Finding thisbook was a real stroke of luck. If you want to really understand how toget things done at the command line, where the power and flexibility of

free UNIX-like OSes really live, this book is among the best tools you’llfind toward that end.”—Chad PerrinWriter, TechRepublicPraise for Other Books by Mark G. Sobell“I keep searching for books that collect everything you want to knowabout a subject in one place, and keep getting disappointed. Usually thebooks leave out some important topic, while others go too deep insome areas and must skim lightly over the others. A Practical Guide toRed Hat Linux is one of those rare books that actually pulls it off.Mark G. Sobell has created a single reference for Red Hat Linux thatcan’t be beat! This marvelous text (with a 4-CD set of Linux FedoraCore 2 included) is well worth the price. This is as close to an ‘everything you ever needed to know’ book that I’ve seen. It’s just that goodand rates 5 out of 5.”—Ray LodatoSlashdot contributor“Mark Sobell has written a book as approachable as it is authoritative.”—Jeffrey BianchineAdvocate, Author, Journalist“Excellent reference book, well suited for the sysadmin of a Linux cluster, or the owner of a PC contemplating installing a recent stable Linux.Don’t be put off by the daunting heft of the book. Sobell has strived tobe as inclusive as possible, in trying to anticipate your system administration needs.”—Wes BoudvilleInventor“A Practical Guide to Red Hat Linux is a brilliant book. Thank youMark Sobell.”—C. PozrikidisUniversity of Californiaat San Diego

“This book presents the best overview of the Linux operating systemthat I have found. . . . [It] should be very helpful and understandableno matter what the reader’s background: traditional UNIX user, newLinux devotee, or even Windows user. Each topic is presented in aclear, complete fashion, and very few assumptions are made aboutwhat the reader knows. . . . The book is extremely useful as a reference,as it contains a 70-page glossary of terms and is very well indexed. It isorganized in such a way that the reader can focus on simple tasks without having to wade through more advanced topics until they areready.”—Cam MarshallMarshall Information Service LLCMember of Front Range UNIXUsers Group [FRUUG]Boulder, Colorado“Conclusively, this is THE book to get if you are a new Linux user andyou just got into the RH/Fedora world. There’s no other book that discusses so many different topics and in such depth.”—Eugenia Loli-QueruEditor in ChiefOSNews.com

This page intentionally left blank

A Practical Guide to Linux Commands,Editors, and Shell ProgrammingSECOND EDITION

This page intentionally left blank

A Practical Guide to Linux Commands,Editors, and Shell ProgrammingSECOND EDITIONMark G. SobellUpper Saddle River, NJ Boston Indianapolis San FranciscoNew York Toronto Montreal London Munich Paris MadridCapetown Sydney Tokyo Singapore Mexico City

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Wherethose designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printedwith initial capital letters or in all capitals.The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of anykind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages inconnection with or arising out of the use of the information or programs contained herein.The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which mayinclude electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, andbranding interests. For more information, please contact:U.S. Corporate and Government Sales(800) 382-3419corpsales@pearsontechgroup.comFor sales outside the United States, please contact:International Salesinternational@pearson.comVisit us on the Web: informit.com/phLibrary of Congress Cataloging-in-Publication DataSobell, Mark G.A practical guide to Linux commands, editors, and shell programming /Mark G. Sobell.—2nd ed.p. cm.Includes bibliographical references and index.ISBN 978-0-13-136736-4 (pbk.)1. Linux. 2. Operating systems (Computers) I. Title.QA76.76.O63S59483 2009005.4'32—dc222009038191Copyright 2010 Mark G. SobellAll rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission mustbe obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in anyform or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions,write to:Pearson Education, Inc.Rights and Contracts Department501 Boylston Street, Suite 900Boston, MA 02116Fax: (617) 671-3447ISBN-13: 978-0-13-136736-4ISBN-10:0-13-136736-6Text printed in the United States at Edwards Brothers in Ann Arbor, Michigan.First printing, October 2009

With love for my guys,Zach, Max, and Sam

This page intentionally left blank

Brief ContentsContents xiiiPreface xxxi1Welcome to Linux and Mac OS XPART I2345The EditorsThe ShellsThe Bourne Again ShellThe TC Shell 349PART IV101121147The vim Editor 149The emacs Editor 205PART III89The Linux and Mac OS X Operating SystemsGetting Started 23The Utilities 45The Filesystem 77The Shell 117PART II671267269Programming ToolsProgramming the Bourne Again ShellThe Perl Scripting Language 485395397xi

xii Brief Contents121314The AWK Pattern Processing LanguageThe sed Editor 565The rsync Secure Copy Utility 583PART VCommand ReferenceCommand ReferencePART VI599Appendixes885A Regular Expressions 887B Help 897C Keeping the System Up-to-DateD Mac OS X Notes 925Glossary 939File Tree Index 989Utility Index 991Main Index 995909531597

ContentsPreface xxxiChapter 1: Welcome to Linux and Mac OS X1The History of UNIX and GNU–Linux 2The Heritage of Linux: UNIX 2Fade to 1983 3Next Scene, 1991 4The Code Is Free 5Have Fun! 5What Is So Good About Linux? 6Why Linux Is Popular with Hardware Companies and Developers 9Linux Is Portable 9The C Programming Language 10Overview of Linux 11Linux Has a Kernel Programming Interface 11Linux Can Support Many Users 12Linux Can Run Many Tasks 12Linux Provides a Secure Hierarchical Filesystem 12The Shell: Command Interpreter and Programming Language 13A Large Collection of Useful Utilities 15Interprocess Communication 15System Administration 16Additional Features of Linux 16GUIs: Graphical User Interfaces 16(Inter)Networking Utilities 17Software Development 17Chapter Summary 18Exercises 18xiii

xiv ContentsPART I The Linux and Mac OS XOperating Systems 21Chapter 2: Getting Started 23Conventions Used in This Book 24Logging In from a Terminal or Terminal Emulator 26Working with the Shell 28Which Shell Are You Running? 28Correcting Mistakes 29Repeating/Editing Command Lines 31su/sudo: Curbing Your Power (root Privileges) 31Where to Find Documentation 33The ––help Option 33man: Displays the System Manual 33apropos: Searches for a Keyword 35info: Displays Information About Utilities 36HOWTOs: Finding Out How Things Work 38Getting Help with the System 38More About Logging In 40Using Virtual Consoles 40What to Do If You Cannot Log In 41Logging Out 41Changing Your Password 41Chapter Summary 43Exercises 44Advanced Exercises 44Chapter 3: The Utilities45Special Characters 46Basic Utilities 47ls: Lists the Names of Files 47cat: Displays a Text File 48rm: Deletes a File 48less Is more: Display a Text File One Screen at a Timehostname: Displays the System Name 49Working with Files 49cp: Copies a File 49mv: Changes the Name of a File 50lpr: Prints a File 51grep: Searches for a String 52head: Displays the Beginning of a File 5248

Contents xvtail: Displays the End of a File 53sort: Displays a File in Order 54uniq: Removes Duplicate Lines from a Filediff: Compares Two Files 54file: Identifies the Contents of a File 5654 (Pipe): Communicates Between Processes 56Four More Utilities 57echo: Displays Text 57date: Displays the Time and Date 58script: Records a Shell Session 58todos/unix2dos: Converts Linux and Mac OS X Files to Windows FormatCompressing and Archiving Files 60bzip2: Compresses a File 60bunzip2 and bzcat: Decompress a File 61gzip: Compresses a File 62tar: Packs and Unpacks Archives 62Locating Commands 65which and whereis: Locate a Utility 65slocate/locate: Searches for a File 66Obtaining User and System Information 67who: Lists Users on the System 67finger: Lists Users on the System 68w: Lists Users on the System 69Communicating with Other Users 70write: Sends a Message 70mesg: Denies or Accepts Messages 71Email 72Chapter Summary 72Exercises 75Advanced Exercises 75Chapter 4: The Filesystem77The Hierarchical Filesystem 78Directory Files and Ordinary Files 78Filenames 79The Working Directory 82Your Home Directory 82Pathnames 83Absolute Pathnames 83Relative Pathnames 84Working with Directories 85mkdir: Creates a Directory 86cd: Changes to Another Working Directory8759

xvi Contentsrmdir: Deletes a Directory88Using Pathnames 89mv, cp: Move or Copy Files 90mv: Moves a Directory 90Important Standard Directories and Files 91Access Permissions 93ls –l: Displays Permissions 93chmod: Changes Access Permissions 94Setuid and Setgid Permissions 96Directory Access Permissions 98ACLs: Access Control Lists 99Enabling ACLs 100Working with Access Rules 100Setting Default Rules for a Directory 103Links 104Hard Links 106Symbolic Links 108rm: Removes a Link 110Chapter Summary 111Exercises 112Advanced Exercises 114Chapter 5: The Shell117The Command Line 118Syntax 118Processing the Command Line 120Executing the Command Line 123Editing the Command Line 123Standard Input and Standard Output 123The Screen as a File 124The Keyboard and Screen as Standard Input and Standard OutputRedirection 126Pipes 131Running a Command in the Background 134Filename Generation/Pathname Expansion 136The ? Special Character 137Special Character 138TheThe [ ] Special Characters 139Builtins 141Chapter Summary 142Utilities and Builtins Introduced in This Chapter 142Exercises 143Advanced Exercises 144*125

Contents xviiPART IIThe EditorsChapter 6: The vim Editor147149History 150Tutorial: Using vim to Create and Edit a File 151Starting vim 151Command and Input Modes 153Entering Text 154Getting Help 155Ending the Editing Session 158The compatible Parameter 158Introduction to vim Features 158Online Help 158Terminology 159Modes of Operation 159The Display 160Correcting Text as You Insert It 160Work Buffer 161Line Length and File Size 161Windows 161File Locks 161Abnormal Termination of an Editing Session 162Recovering Text After a Crash 163Command Mode: Moving the Cursor 164Moving the Cursor by Characters 165Moving the Cursor to a Specific Character 165Moving the Cursor by Words 166Moving the Cursor by Lines 166Moving the Cursor by Sentences and Paragraphs 167Moving the Cursor Within the Screen 167Viewing Different Parts of the Work Buffer 167Input Mode 168Inserting Text 168Appending Text 168Opening a Line for Text 168Replacing Text 169Quoting Special Characters in Input Mode 169Command Mode: Deleting and Changing Text 169Undoing Changes 169Deleting Characters 170Deleting Text 170Changing Text 171Replacing Text 172Changing Case 173

xviii ContentsSearching and Substituting 173Searching for a Character 173Searching for a String 174Substituting One String for Another 176Miscellaneous Commands 180Join 180Status 180. (Period) 180Copying, Moving, and Deleting Text 180The General-Purpose Buffer 181Named Buffers 182Numbered Buffers 182Reading and Writing Files 183Reading Files 183Writing Files 183Identifying the Current File 184Setting Parameters 184Setting Parameters from Within vim 184Setting Parameters in a Startup File 185The .vimrc Startup File 185Parameters 185Advanced Editing Techniques 189Using Markers 189Editing Other Files 190Macros and Shortcuts 190Executing Shell Commands from Within vim 191Units of Measure 193Character 193Word 193Blank-Delimited Word 194Line 194Sentence 194Paragraph 195Screen (Window) 196Repeat Factor 196Chapter Summary 196Exercises 201Advanced Exercises 202Chapter 7: The emacs Editor205History 206Evolution 206emacs Versus vim 207Command-Line emacs Versus Graphical emacs208

Contents xixTutorial: Getting Started with emacs 208Starting emacs 208Exiting 210Inserting Text 210Deleting Characters 210Moving the Cursor 211Editing at the Cursor Position 214Saving and Retrieving the Buffer 214The emacs GUI 215Basic Editing Commands 216Keys: Notation and Use 216Key Sequences and Commands 217META-x: Running a Command Without a Key BindingNumeric Arguments 218Point and the Cursor 218Scrolling Through a Buffer 218Erasing Text 219Searching for Text 219Using the Menubar from the Keyboard 221Online Help 223Advanced Editing 225Undoing Changes 225Point, Mark, and Region 226Cut and Paste: Yanking Killed Text 228Inserting Special Characters 230Global Buffer Commands 230Visiting and Saving Files 232Buffers 235Windows 236Foreground Shell Commands 238Background Shell Commands 239Major Modes: Language-Sensitive Editing 239Selecting a Major Mode 240Human-Language Modes 240C Mode 243Customizing Indention 246Comments 247Special-Purpose Modes 247Customizing emacs 249The .emacs Startup File 250Remapping Keys 251A Sample .emacs File 253More Information 254Access to emacs 254Chapter Summary 254Exercises 262Advanced Exercises 264217

xx ContentsPART IIIThe Shells 267Chapter 8: The Bourne Again Shell269Background 270Shell Basics 271Startup Files 271Commands That Are Symbols 275Redirecting Standard Error 275Writing a Simple Shell Script 278Separating and Grouping Commands 281Job Control 285Manipulating the Directory Stack 288Parameters and Variables 290User-Created Variables 292Variable Attributes 295Keyword Variables 296Special Characters304Processes 306Process Structure 306Process Identification 306Executing a Command 308History 308Variables That Control History 308Reexecuting and Editing Commands 310The Readline Library 318Aliases 324Single Versus Double Quotation Marks in AliasesExamples of Aliases 326Functions327Controlling bash: Features and OptionsCommand-Line Options 330Shell Features 330330Processing the Command Line 334History Expansion 334Alias Substitution 334Parsing and Scanning the Command LineCommand-Line Expansion 335Chapter Summary343334325

Contents xxiExercises 345Advanced Exercises347Chapter 9: The TC Shell349Shell Scripts 350Entering and Leaving the TC Shell 351Startup Files 352Features Common to the Bourne Again and TC Shells 353Command-Line Expansion (Substitution) 354Job Control 358Filename Substitution 358Manipulating the Directory Stack 359Command Substitution 359Redirecting Standard Error 359Working with the Command Line 360Word Completion 360Editing the Command Line 363Correcting Spelling 364Variables 365Variable Substitution 366String Variables 366Arrays of String Variables 367Numeric Variables 368Braces 370Special Variable Forms 371Shell Variables 371Control Structures 378if 378goto 381Interrupt Handling 381if.then.else 382foreach 383while 385break and continue 385switch 386Builtins 387Chapter Summary 391Exercises 392Advanced Exercises 394

xxii ContentsPART IVProgramming Tools 395Chapter 10: Programming the Bourne Again ShellControl Structures 398if.then 398if.then.else 402if.then.elif 405for.in 411for 412while 414until 418break and continue 420case 421select 427Here Document 429File Descriptors 431Parameters and Variables 434Array Variables 434Locality of Variables 436Special Parameters 438Positional Parameters 440Expanding Null and Unset Variables 445Builtin Commands 446type: Displays Information About a Command 447read: Accepts User Input 447exec: Executes a Command or Redirects File Descriptorstrap: Catches a Signal 453kill: Aborts a Process 456getopts: Parses Options 456A Partial List of Builtins 459Expressions 460Arithmetic Evaluation 460Logical Evaluation (Conditional Expressions) 461String Pattern Matching 462Operators 463Shell Programs 468A Recursive Shell Script 469The quiz Shell Script 472Chapter Summary 478Exercises 480Advanced Exercises 482450397

ContentsChapter 11: The Perl Scripting Languagexxiii485Introduction to Perl 486More Information 486Help 487perldoc 487Terminology 489Running a Perl Program 490Syntax 491Variables 493Scalar Variables 495Array Variables 497Hash Variables 500Control Structures 501if/unless 501if.else 503if.elsif.else 504foreach/for 505last and next 506while/until 508Working with Files 510Sort 513Subroutines 515Regular Expressions 517Syntax and the Operator 518CPAN Modules 523Examples 525Chapter Summary 529Exercises 529Advanced Exercises 530Chapter 12: The AWK Pattern Processing Language 531Syntax 532Arguments 532Options 533Notes 534Language Basics 534Patterns 534Actions 535Comments 535Variables 535Functions 536Arithmetic Operators537

xxiv ContentsAssociative Arrays 538printf 538Control Structures 539Examples 541Advanced gawk Programming 558getline: Controlling Input 558Coprocess: Two-Way I/O 560Getting Input from a Network 562Chapter Summary 563Exercises 563Advanced Exercises 564Chapter 13: The sed Editor565Syntax 566Arguments 566Options 566Editor Basics 567Addresses 567Instructions 568Control Structures 569The Hold Space 570Examples 570Chapter Summary 581Exercises 581Chapter 14: The rsync Secure Copy UtilitySyntax 584Arguments 584Options 584Notes 586More Information 586Examples 587Using a Trailing Slash ( /) on source-file 587Removing Files 588Copying Files to and from a Remote System 590Mirroring a Directory 590Making Backups 591Chapter Summary 594Exercises 594583

ContentsPART VCommand Reference597Standard Multiplicative Suffixes 602Common Options 603The sample Utility 604sample Brief description of what the utility does 605aspell Checks a file for spelling errors 607at Executes commands at a specified time 611bzip2 Compresses or decompresses files 615cal Displays a calendar 617cat Joins and displays files 618cd Changes to another working directory 620chgrp Changes the group associated with a file 622chmod Changes the access mode (permissions) of a file 626chown Changes the owner of a file and/or the group the file isassociated with 631cmp Compares two files 634comm Compares sor

Praise for the First Edition of A Practical Guide to Linux Commands, Editors, and Shell Programming This book is a very useful tool for anyone who wants to look under the hood so to speak, and really start putting the power of Linux to work. What I find particularly frustrating about man pages is that they never include examples.

Related Documents:

May 02, 2018 · D. Program Evaluation ͟The organization has provided a description of the framework for how each program will be evaluated. The framework should include all the elements below: ͟The evaluation methods are cost-effective for the organization ͟Quantitative and qualitative data is being collected (at Basics tier, data collection must have begun)

Silat is a combative art of self-defense and survival rooted from Matay archipelago. It was traced at thé early of Langkasuka Kingdom (2nd century CE) till thé reign of Melaka (Malaysia) Sultanate era (13th century). Silat has now evolved to become part of social culture and tradition with thé appearance of a fine physical and spiritual .

On an exceptional basis, Member States may request UNESCO to provide thé candidates with access to thé platform so they can complète thé form by themselves. Thèse requests must be addressed to esd rize unesco. or by 15 A ril 2021 UNESCO will provide thé nomineewith accessto thé platform via their émail address.

̶The leading indicator of employee engagement is based on the quality of the relationship between employee and supervisor Empower your managers! ̶Help them understand the impact on the organization ̶Share important changes, plan options, tasks, and deadlines ̶Provide key messages and talking points ̶Prepare them to answer employee questions

Dr. Sunita Bharatwal** Dr. Pawan Garga*** Abstract Customer satisfaction is derived from thè functionalities and values, a product or Service can provide. The current study aims to segregate thè dimensions of ordine Service quality and gather insights on its impact on web shopping. The trends of purchases have

Song of Praise Knut Nystedt Praise the Lord! Praise the Lord from the heavens. Praise the Lord! Praise the Lord in the heights. Praise him all his angels, praise him all his hosts. Praise him sun and moon, praise him all you shining stars! Praise him you highest heavens, and the waters above the heavens.

Bruksanvisning för bilstereo . Bruksanvisning for bilstereo . Instrukcja obsługi samochodowego odtwarzacza stereo . Operating Instructions for Car Stereo . 610-104 . SV . Bruksanvisning i original

Chính Văn.- Còn đức Thế tôn thì tuệ giác cực kỳ trong sạch 8: hiện hành bất nhị 9, đạt đến vô tướng 10, đứng vào chỗ đứng của các đức Thế tôn 11, thể hiện tính bình đẳng của các Ngài, đến chỗ không còn chướng ngại 12, giáo pháp không thể khuynh đảo, tâm thức không bị cản trở, cái được