Transcription of The Linux Command Line
1 The Linux Command line Fifth Internet Edition William Shotts A Book Copyright 2008-2019, William E. Shotts, Jr. This work is licensed under the Creative Commons Attribution-Noncommercial-No De- rivative Works United States License. To view a copy of this license, visit the link above or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042. A version of this book is also available in printed form, published by No Starch Press. Copies may be purchased wherever fine books are sold. No Starch Press also offers elec- tronic formats for popular e-readers. They can be reached at: Linux is the registered trademark of Linus Torvalds. All other trademarks belong to their respective owners. This book is part of the project, a site for Linux education and advo- cacy devoted to helping users of legacy operating systems migrate into the future. You may contact the project at Release History Version Date Description January 28, 2019 Fifth Internet Edition (Corrected TOC).
2 January 17, 2019 Fifth Internet Edition. October 19, 2017 Fourth Internet Edition. July 28, 2016 Third Internet Edition. July 6, 2013 Second Internet Edition. December 14, 2009 First Internet Edition. Table of Contents Why Use the Command line ?..xvi What This Book Is Who Should Read This What's in This How To Read This Why I Don't Call It GNU/ Linux ..xix What's New in the Fifth Internet First Internet Second Internet Third Internet Fourth Internet Fifth Internet Your Feedback Is Needed!..xxi Further Part 1 Learning the 1 What Is the Shell?..2. Terminal Making Your First Command Cursor A Few Words About Mice and Try Some Simple Ending a Terminal The Console Behind the Summing Further 2 Understanding the File System The Current Working Listing the Contents of a i Changing the Current Working Absolute Relative Some Helpful Important Facts About Summing 3 Exploring the Having More Fun with Options and A Longer Look at Long Determining a File's Type with Viewing File Contents with What Is Text ?
3 17. Less Is Taking a Guided Symbolic Hard Summing Further 4 Manipulating Files and Character Wildcards Work in the GUI mkdir Create cp Copy Files and Useful Options and mv Move and Rename Useful Options and rm Remove Files and Useful Options and Be Careful with rm!..33. ln Create Hard Symbolic Let's Build a Creating Copying Moving and Renaming Creating Hard Creating Symbolic Removing Files and Creating Symlinks With The Summing Further 5 Working with What Exactly Are Commands?..42. Identifying ii type Display a Command 's which Display an Executable's Getting a Command 's help Get Help for Shell --help Display Usage man Display a Program's Manual apropos Display Appropriate whatis Display One- line Manual Page The Most Brutal Man Page Of Them info Display a Program's Info README and Other Program Documentation Creating Our Own Commands with Summing Further 6 Standard Input, Output, and Redirecting Standard Redirecting Standard Redirecting Standard Output and Standard Error to One Disposing of Unwanted /dev/null In Unix Redirecting Standard cat Concatenate The Difference Between > and |.
4 61. uniq - Report or Omit Repeated wc Print line , Word, and Byte grep Print Lines Matching a head / tail Print First / Last Part of tee Read from Stdin and Output to Stdout and Summing Linux Is About 7 Seeing the World as the Shell Sees Pathname Pathname Expansion of Hidden Tilde Arithmetic Brace Parameter Command Double Single Escaping Backslash Escape Summing iii Further 8 Advanced Keyboard Command line Cursor Modifying Cutting and Pasting (Killing and Yanking) The Meta Programmable Using Searching History Summing Further 9 Owners, Group Members, and Everybody Reading, Writing, and chmod Change File What the Heck is Octal?..95. Setting File Mode with the umask Set Default Some Special Changing su Run a Shell with Substitute User and Group sudo Execute a Command as Another Ubuntu and chown Change File Owner and chgrp Change Group Exercising Our Changing Your Summing Further 10 How a Process Viewing Viewing Processes Dynamically with Controlling Interrupting a Putting a Process in the Returning a Process to the Stopping (Pausing) a Sending Signals to Processes with Sending Signals to Multiple Processes with Shutting Down the More Process-Related iv Summing Part 2 Configuration and the 11 The What is Stored in the Environment?
5 128. Examining The Some Interesting How Is The Environment Established?..131. What's in a Startup File?..132. Modifying the Which Files Should We Modify?..135. Text Using a Text Why Comments Are Activating Our Summing Further 12 A Gentle Introduction to Why We Should Learn A Little Starting and Stopping Compatibility Editing Entering Insert Saving Our Moving the Cursor Basic Appending Opening a Deleting Cutting, Copying, and Pasting Joining Searching Within a Searching the Entire Global Editing Multiple Switching Between Opening Additional Files for Copying Content from One File into Inserting an Entire File into Saving Our Summing Further 13 Customizing the Anatomy of a v Trying Some Alternative Prompt Adding Terminal Moving the Saving the Summing Further Part 3 Common Tasks and Essential 14 Package Packaging How a Package System Package High and Low-level Package Common Package Management Finding a Package in a Installing a Package from a Installing a Package from a Package Removing a Updating Packages from a Upgrading a Package from a Package Listing Installed Determining Whether a Package is Displaying Information About an Installed Finding Which Package Installed a Summing The Linux Software Installation Further 15 Storage Mounting and Unmounting Storage Viewing a List of Mounted File Why Unmounting Is Determining Device Creating New File Manipulating Partitions with Creating a
6 New File System with Testing and Repairing File What the fsck?..196. Moving Data Directly to and from Creating CD-ROM Creating an Image Copy of a Creating an Image From a Collection of A Program by Any Other Writing CD-ROM Mounting an ISO Image vi Blanking a Rewritable Writing an Summing Further Extra 16 Examining and Monitoring a Transporting Files Over a lftp A Better Secure Communication with Remote Tunneling with scp and An SSH Client for Windows?..215. Summing Further 17 Searching for locate Find Files the Easy Where Does the locate Database Come From?..219. find Find Files the Hard Predefined User-Defined Improving Dealing with Funny A Return to the Summing Further 18 Archiving and Compressing Don't Be Compressive Archiving Synchronizing Files and Using rsync Over a vii Summing Further 19 Regular What are Regular Expressions?..251. Metacharacters and The Any A Crossword Puzzle Bracket Expressions and Character Traditional Character POSIX Character Reverting to Traditional Collation POSIX Basic vs.
7 Extended Regular ? - Match an Element Zero or One * - Match an Element Zero or More + - Match an Element One or More { } - Match an Element a Specific Number of Putting Regular Expressions to Validating a Phone List With Finding Ugly Filenames with Searching for Files with Searching for Text with less and Summing Further 20 Text Applications of Web Printer Program Source Revisiting Some Old MS-DOS Text vs. Unix Slicing and Expanding Comparing viii Editing on the ROT13: The Not-So-Secret Decoder People Who Like sed Also Summing Further Extra 21 Formatting Simple Formatting nl Number fold Wrap Each line to a Specified fmt A Simple Text pr Format Text for printf Format and Print Document Formatting Summing Further 22 A Brief History of Printing in the Dim Character-Based Graphical Printing with Preparing Files for pr Convert Text Files for Sending a Print Job to a lpr Print Files (Berkeley Style)..342. lp Print Files (System V Style)..343. Another Option: Monitoring and Controlling Print lpstat Display Print System lpq Display Printer Queue lprm / cancel Cancel Print Summing Further 23 Compiling What is Compiling?
8 350. Are All Programs Compiled?..351. Compiling a C Obtaining the Source Examining the Source Building the ix Installing the Summing Further Part 4 Writing Shell 24 Writing Your First What are Shell Scripts?..364. How to Write a Shell Script File Executable Script File Good Locations for More Formatting Long Option Indentation and Configuring vim For Script Summing Further 25 Starting a First Stage: Minimal Second Stage: Adding a Little Variables and Assigning Values to Variables and Here Summing Further 26 Top-Down Shell Local Keep Scripts Shell Functions In Your .bashrc Summing Further 27 Flow Control: Branching with Exit File String Integer A More Modern Version of (( )) - Designed for Combining Portability is the Hobgoblin of Little x Control Operators: Another Way to Summing Further 28 Reading Keyboard read Read Values from Standard You Can't Pipe Validating Summing Extra Further 29 Flow Control: Looping with while / Breaking Out of a Reading Files with Summing Further 30 Syntactic Missing Missing or Unexpected Unanticipated Logical Defensive Watch Out for Portable Verifying Design is a Function of Test Finding the Problem Examining Values During Summing Further 31 Flow Control: Branching with Performing Multiple Summing xi Further 32 Positional Accessing the Command Determining the Number of shift Getting Access to Many Simple Using Positional Parameters with Shell Handling Positional Parameters en A More Complete Summing Further 33 Flow Control: Looping with for: Traditional Shell Why i?
9 469. for: C Language Summing Further 34 Strings and Parameter Basic Expansions to Manage Empty Expansions That Return Variable String Case Arithmetic Evaluation and Number Unary Simple Bit bc An Arbitrary Precision Calculator Using An Example Summing Extra Further 35 What Are Arrays?..495. Creating an Assigning Values to an Accessing Array Array Outputting the Entire Contents of an Determining the Number of Array xii Finding the Subscripts Used by an Adding Elements to the End of an Sorting an Deleting an Associative Summing Further 36 Group Commands and Process Temporary Asynchronous Named Setting Up a Named Using Named Summing Further xiii xiv For Karen xv Introduction I want to tell you a story. No, not the story of how, in 1991, Linus Torvalds wrote the first version of the Linux ker- nel. You can read that story in lots of Linux books. Nor am I going to tell you the story of how, some years earlier, Richard Stallman began the GNU Project to create a free Unix- like operating system.
10 That's an important story too, but most other Linux books have that one, as well. No, I want to tell you the story of how you take back control of your computer. When I began working with computers as a college student in the late 1970s, there was a revolution going on. The invention of the microprocessor had made it possible for ordi- nary people like you and me to actually own a computer. It's hard for many people today to imagine what the world was like when only big business and big government ran all the computers. Let's just say, you couldn't get much done. Today, the world is very different. Computers are everywhere, from tiny wristwatches to giant data centers to everything in between. In addition to ubiquitous computers, we also have a ubiquitous network connecting them together. This has created a wondrous new age of personal empowerment and creative freedom, but over the last couple of decades something else has been happening. A few giant corporations have been imposing their control over most of the world's computers and deciding what you can and cannot do with them.