The Linux Command Line - A Complete Introduction, 3e (William Shotts)(Z-Library)
Linux
No Description
170
Views
0
Downloads
0.00
Total Donations
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
(This page has no text content)
Page
2
(This page has no text content)
Page
3
PRAISE FOR THE LINUX COMMAND LINE “The most approachable tome on the subject.” —FEDERICO LUCIFREDI, LINUX MAGAZINE “This excellent Linux command line book is more than cubicle decoration; it’s a secret superpower.” —KEN HESS, RED HAT “I can honestly say I have found the beginner’s guide to Linux.” —JAYSON BROUGHTON, LINUX JOURNAL “This is the best introduction to the command line I have read.” —BEGINLINUX.COM “For those looking to master the Linux command line and get an essential understanding of the core Linux command line tools, this book is a highly effective and useful guide.” —BEN ROTHKE, RSA CONFERENCE “Anyone who reads this book and makes use of the examples provided will not be able to avoid becoming a Unix command line pro by the time they’ve hit the end of the book. It provides an excellent introduction to the command line that takes students from knowing nearly nothing to using impressively sophisticated commands.” —SANDRA HENRY-STOCKER, ITWORLD “Thorough and approachable. A great resource for those new to Linux and for seasoned Linux veterans wanting to dive deeper.” —PHILIP POLSTRA, PHD, AUTHOR OF LINUX FORENSICS “It trains you to think like the system thinks—not just run commands until something works.” —LINUXSECURITY.COM
Page
4
THE LINUX COMMAND LINE 3rd Edition A Complete Introduction by William Shotts no starch press® San Francisco
Page
5
THE LINUX COMMAND LINE, 3RD EDITION. Copyright © 2026 by William Shotts. All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. First printing 29 28 27 26 25 1 2 3 4 5 ISBN-13: 978-1-7185-0452-3 (print) ISBN-13: 978-1-7185-0453-0 (ebook) Published by No Starch Press®, Inc. 245 8th Street, San Francisco, CA 94103 phone: +1.415.863.9900 www.nostarch.com; info@nostarch.com Publisher: William Pollock Managing Editor: Jill Franklin Production Manager: Sabrina Plomitallo-González Production Editor: Jennifer Kepler Developmental Editor: Jill Franklin Cover Illustrator: Rob Fiore Interior Design: Octopod Studios Technical Reviewer: Mitch Frazier Copyeditor: Kim Wimpsett Indexer: BIM Creatives, LLC The Library of Congress has catalogued the first edition as follows: Shotts, William E. The Linux command line: a complete introduction / William E. Shotts, Jr. p. cm. Includes index. ISBN-13: 978-1-59327-389-7 (pbk.) ISBN-10: 1-59327-389-4 (pbk.) 1. Linux. 2. Scripting Languages (Computer science) 3. Operating systems (Computers) I. Title. QA76.76.O63S5556 2011 005.4'32—dc23 2011029198 For customer service inquiries, please contact info@nostarch.com. For information on distribution, bulk sales, corporate sales, or translations: sales@nostarch.com. For permission to translate this work: rights@nostarch.com. To report counterfeit copies or piracy: counterfeit@nostarch.com. The authorized representative in the EU for product safety and compliance is EU Compliance Partner, Pärnu mnt. 139b-14, 11317 Tallinn, Estonia, hello@eucompliancepartner.com, +3375690241. No Starch Press and the No Starch Press iron logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
Page
6
For Karen
Page
7
About the Author William Shotts is the former vice president of technical services at Media Cybernetics LLC. Now retired, he started his computing career in 1978 when he acquired his first computer. Since then, he has been a teacher, a photographer, a programmer, and a technical manager of diverse teams of technical support specialists, software quality assurance testers, system administrators, and technical writers. He earned a bachelor of industrial design degree from Syracuse University. He has been a Linux user and advocate since 1996 and is the creator of LinuxCommand.org.
Page
8
About the Technical Reviewer Mitch Frazier is a programmer who works for Emerson Electric doing mostly embedded systems programming in C. He also occasionally writes code in Golang, Python, Tcl, JavaScript, and bash. He previously worked for Linux Journal, as both a technical editor and a system administrator.
Page
9
BRIEF CONTENTS Acknowledgments Introduction PART I: LEARNING THE SHELL Chapter 1: What Is the Shell? Chapter 2: Navigation Chapter 3: Exploring the System Chapter 4: Manipulating Files and Directories Chapter 5: Working with Commands Chapter 6: Redirection Chapter 7: Seeing the World as the Shell Sees It Chapter 8: Advanced Keyboard Tricks Chapter 9: Permissions Chapter 10: Processes PART II: CONFIGURATION AND THE ENVIRONMENT Chapter 11: The Environment Chapter 12: A Gentle Introduction to vi(m) Chapter 13: Customizing the Prompt PART III: COMMON TASKS AND ESSENTIAL TOOLS Chapter 14: Package Management Chapter 15: Storage Media Chapter 16: Networking Chapter 17: Searching for Files Chapter 18: Archiving and Backup Chapter 19: Regular Expressions Chapter 20: Text Processing Chapter 21: Formatting Output Chapter 22: Printing Chapter 23: Compiling Programs
Page
10
PART IV: WRITING SHELL SCRIPTS Chapter 24: Writing Your First Script Chapter 25: Starting a Project Chapter 26: Top-Down Design Chapter 27: Flow Control: Branching with if Chapter 28: Reading Keyboard Input Chapter 29: Flow Control: Looping with while/until Chapter 30: Troubleshooting Chapter 31: Flow Control: Branching with case Chapter 32: Positional Parameters Chapter 33: Flow Control: Looping with for Chapter 34: Strings and Numbers Chapter 35: Arrays Chapter 36: Exotica Index
Page
11
CONTENTS IN DETAIL ACKNOWLEDGMENTS INTRODUCTION Why Use the Command Line? What This Book Is About Who Should Read This Book What’s in This Book How to Read This Book Prerequisites What’s New in the Third Print Edition Your Feedback Is Needed! PART I: LEARNING THE SHELL 1 WHAT IS THE SHELL? Terminal Emulators Making Your First Keystrokes Command History Cursor Movement Try Some Simple Commands Ending a Terminal Session Summing Up 2 NAVIGATION Understanding the Filesystem Tree The Current Working Directory Listing the Contents of a Directory Changing the Current Working Directory Absolute Pathnames Relative Pathnames
Page
12
Some Helpful Shortcuts Summing Up 3 EXPLORING THE SYSTEM More Fun with ls Options and Arguments A Longer Look at Long Format Determining a File’s Type with file Viewing File Contents with less Taking a Guided Tour Symbolic Links Hard Links Summing Up 4 MANIPULATING FILES AND DIRECTORIES Wildcards Dot Files mkdir—Create Directories cp—Copy Files and Directories Useful Options and Examples mv—Move and Rename Files Useful Options and Examples rm—Remove Files and Directories Useful Options and Examples ln—Create Links Hard Links Symbolic Links Let’s Build a Playground Creating Directories Copying Files Moving and Renaming Files Creating Hard Links Creating Symbolic Links Removing Files and Directories Summing Up
Page
13
5 WORKING WITH COMMANDS What Exactly Are Commands? Identifying Commands type—Display a Command’s Type which—Display an Executable’s Location Getting a Command’s Documentation help—Get Help for Shell Builtins --help—Display Usage Information man—Display a Program’s Manual Page apropos—Display Appropriate Commands whatis—Display One-Line Manual Page Descriptions info—Display a Program’s Info Entry README and Other Program Documentation Files Creating Our Own Commands with alias Summing Up 6 REDIRECTION Standard Input, Output, and Error Redirecting Standard Output Group Commands Redirecting Standard Error Redirecting Standard Output and Standard Error to One File Disposing of Unwanted Output Redirecting Standard Input cat—Concatenate Files Pipelines Filters uniq—Report or Omit Repeated Lines wc—Print Line, Word, and Byte Counts grep—Print Lines Matching a Pattern head/tail—Print First/Last Part of Files tee—Read from Stdin and Output to Stdout and Files Summing Up 7 SEEING THE WORLD AS THE SHELL SEES IT
Page
14
Expansion Pathname Expansion Tilde Expansion Arithmetic Expansion Brace Expansion Parameter Expansion Command Substitution Quoting Double Quotes Single Quotes Escaping Characters Backslash Escape Sequences Summing Up 8 ADVANCED KEYBOARD TRICKS Command Line Editing Cursor Movement Modifying Text Cutting and Pasting (Killing and Yanking) Text Command Completion Using History Searching History History Expansion Summing Up 9 PERMISSIONS Users, Group Members, and Everybody Else Reading, Writing, and Executing chmod—Change File Mode Setting File Mode with the GUI umask—Set Default Permissions Some Special Permissions Changing Identities su—Run a Shell with Substitute User and Group IDs sudo—Execute a Command as Another User chown—Change File Owner and Group
Page
15
chgrp—Change Group Ownership Exercising Our Privileges Changing Your Password Summing Up 10 PROCESSES How a Process Works Viewing Processes Viewing Processes Dynamically with top Controlling Processes Interrupting a Process Putting a Process in the Background Returning a Process to the Foreground Stopping (Pausing) a Process Changing Process Priority Signals Sending Signals to Processes with kill Making a Process Hang-Up Proof Sending Signals to Multiple Processes with killall Shutting Down the System More Process-Related Commands Summing Up PART II: CONFIGURATION AND THE ENVIRONMENT 11 THE ENVIRONMENT What Is Stored in the Environment? Examining the Environment Some Interesting Variables How Is the Environment Established? What’s in a Startup File? Exploring How Child Processes Inherit Their Environments Launching a Program with a Temporary Environment Modifying the Environment Which Files Should We Modify?
Page
16
Text Editors Using a Text Editor Activating Our Changes Summing Up 12 A GENTLE INTRODUCTION TO VI(M) Why We Should Learn vi A Little Background Starting and Stopping vi Editing Modes Entering Insert Mode Saving Our Work Moving the Cursor Around Basic Editing Appending Text Opening a Line Deleting Text Cutting, Copying, and Pasting Text Joining Lines Search-and-Replace Searching Within a Line Searching the Entire File Global Search-and-Replace Editing Multiple Files Switching Between Files Opening Additional Files for Editing Copying Content from One File into Another Inserting an Entire File into Another Saving Our Work bash Does vi Too Summing Up 13 CUSTOMIZING THE PROMPT Anatomy of a Prompt Trying Some Alternative Prompt Designs Adding Color
Page
17
Moving the Cursor Saving the Prompt Summing Up PART III: COMMON TASKS AND ESSENTIAL TOOLS 14 PACKAGE MANAGEMENT Packaging Systems How a Package System Works Package Files Repositories Dependencies High- and Low-Level Package Tools Common Package Management Tasks Finding a Package in a Repository Installing a Package from a Repository Installing a Package from a Package File Removing a Package Updating Packages from a Repository Upgrading a Package from a Package File Listing Installed Packages Determining Whether a Package Is Installed Displaying Information About an Installed Package Finding Which Package Installed a File Summing Up 15 STORAGE MEDIA Mounting and Unmounting Storage Devices Viewing a List of Mounted Filesystems Determining Device Names Creating New Filesystems Manipulating Partitions with parted Creating a New Filesystem with mkfs Testing and Repairing Filesystems Moving Data Directly to and from Devices
Page
18
Creating CD-ROM Images Creating an Image Copy of a CD-ROM Creating an Image from a Collection of Files Writing CD-ROM Images Mounting an ISO Image Directly Blanking a Rewritable CD-ROM Writing an Image Verifying Data Summing Up 16 NETWORKING Examining and Monitoring a Network ping traceroute ip Transporting Files Over a Network ftp lftp—A Better ftp curl—Transfer a URL wget—Non-Interactive Network Downloader Secure Communication with Remote Hosts ssh scp and sftp Summing Up 17 SEARCHING FOR FILES locate—Find Files the Easy Way find—Find Files the Hard Way Tests Operators Predefined Actions User-Defined Actions Improving Efficiency xargs A Return to the Playground Options
Page
19
Summing Up 18 ARCHIVING AND BACKUP Compressing Files gzip bzip2 Archiving Files tar zip Synchronizing Files and Directories Using rsync Over a Network Summing Up 19 REGULAR EXPRESSIONS What Are Regular Expressions? grep Metacharacters and Literals The Any Character Anchors Bracket Expressions and Character Classes Negation Traditional Character Ranges POSIX Character Classes POSIX Basic vs. Extended Regular Expressions Alternation Quantifiers ?—Match an Element Zero or One Time *—Match an Element Zero or More Times +—Match an Element One or More Times { }—Match an Element a Specific Number of Times Putting Regular Expressions to Work Validating a Phone List with grep Finding Ugly Filenames with find Searching for Files with locate Searching for Text with less and vim Summing Up
Page
20
20 TEXT PROCESSING Applications of Text Documents Web Pages Email Printer Output Program Source Code Revisiting Some Old Friends cat sort uniq Slicing and Dicing cut paste join tac rev Comparing Text comm diff patch Editing on the Fly tr sed aspell Summing Up Extra Credit 21 FORMATTING OUTPUT Simple Formatting Tools nl—Number Lines fold—Wrap Each Line to a Specified Length fmt—A Simple Text Formatter pr—Format Text for Printing printf—Format and Print Data Document Formatting Systems
The above is a preview of the first 20 pages. Register to read the complete e-book.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
AI guide
# The Linux Command Line - A Complete Introduction, 3e
## 【One-Line Pitch】
A comprehensive, hands-on guide to mastering the Linux command line and shell scripting, perfect for beginners and intermediate users who want to move beyond GUI file managers and gain real power over their systems. If you've ever felt limited by graphical tools or wanted to automate repetitive tasks, this book is your gateway to the "Erector Set" philosophy of Linux.
---
## 【Book Arc】
- **Opening (~0%–10%)**: Introduces the shell environment, command history, cursor movement, and the fundamental file manipulation commands (cp, mv, mkdir, rm, ln). Establishes why the command line beats GUI tools for complex tasks, using examples like conditional file copying with `cp -u`.
- **Early (~10%–23%)**: Covers redirection (`>`, `>>`), command grouping, and the philosophy of Linux as a modular system. Includes the famous "Game Boy vs. Erector Set" analogy, explaining how Linux empowers users to build their own solutions rather than being limited to pre-packaged ones.
- **Early (~23%–32%)**: Delves into quoting and expansion (single vs. double quotes), file permissions, umask, and process management. Introduces job control with background processes (`&`), the `jobs` command, and the distinction between foreground and background execution.
- **Middle (~32%–48%)**: Shifts to text editors—nano for beginners and vi/vim for power users—covering essential editing commands, cursor movement, and the modal editing paradigm. Also explores customizing the shell prompt with PS1 variables, including complex color and positioning escape sequences.
- **Late (~48%–100%)**: Moves into shell scripting fundamentals: writing first scripts, top-down design, flow control (if/while/until/case/for), positional parameters, arrays, and troubleshooting. The final chapters cover archiving (gzip, tar, zip, rsync) and regular expressions (grep, character classes, quantifiers).
---
## 【Key Takeaways】
- **The command line offers power GUI tools can't match** (Early): Complex operations like copying only newer files (`cp -u *.html destination`) are trivial on the command line but nearly impossible with file managers. This is the core justification for investing time in learning the shell.
- **Redirection and pipes are the shell's superpower** (Early): Using `>` and `>>` to create/append files, and grouping commands with `;`, enables sophisticated workflows. The book emphasizes that almost all command-line programs use standard input/output, making them composable building blocks.
- **Quoting controls expansion** (Early): Single quotes suppress all expansions, double quotes allow some (like `$USER` and `$(echo foo)`), and unquoted text allows everything including globbing and brace expansion. Understanding this distinction prevents countless scripting bugs.
- **Job control manages foreground/background processes** (Early): Appending `&` launches programs in the background, and the `jobs` command tracks them. This is essential for managing multiple tasks from a single terminal without opening new windows.
- **vi/vim rewards investment with speed** (Middle): The modal editing model (normal vs. insert mode) and keyboard-only navigation (h/j/k/l) allow typists to keep fingers on the home row. Commands like `5j` (move down 5 lines) and `A` (append at line end) demonstrate the efficiency of composable commands.
- **The prompt is programmable** (Middle): PS1 variables can embed colors, cursor positioning, and dynamic information like time and user. The book breaks down complex escape sequences, showing how to create a status bar with a clock—a practical example of shell customization.
- **Shell scripting follows structured design** (Late): The book advocates top-down design and covers all essential flow control constructs (if, while, until, case, for) plus positional parameters and arrays. This transforms users from command executors to tool builders.
- **Regular expressions are a separate language** (Late): The book dedicates significant space to grep, metacharacters, character classes, and quantifiers, with practical applications like validating phone lists and finding "ugly" filenames—skills that pay off in log analysis and data cleaning.
---
## 【Reading Tips】
- **Skim the early chapters if you're already comfortable with basic commands** (~0%–10%): The file manipulation and navigation content is foundational but may be review. Focus on the "why" sections, especially the GUI vs. command-line comparisons.
- **Deep-read the quoting and expansion chapter** (~23%): This is where many beginners get confused. The side-by-side comparisons of unquoted, double-quoted, and single-quoted echo commands are worth studying carefully.
- **Practice vi/vim actively** (Middle): Don't just read—open a file and try every command. The book's examples (appending text, moving by lines) are designed for immediate hands-on practice. Consider doing the exercises twice: once following along, once from memory.
- **Treat the shell scripting section as a mini-course** (Late): The progression from first script through flow control to arrays is deliberately structured. Code along with every example, and try modifying the scripts to test your understanding.
- **Use the troubleshooting chapter as a reference** (Late): When your scripts fail, return to this section rather than guessing. The book's approach to debugging is systematic and worth internalizing.
---
## 【Coverage Limits】
The excerpts focus primarily on Parts I–IV (fundamentals through shell scripting), with the archiving and regular expressions chapters appearing in the table of contents but not deeply excerpted. Advanced topics like networking, system administration, and GUI programming are not covered in this sample.
---
##
Passage locations
Excerpt 1
bberish at the prompt like so: [me@linuxbox ~]$ kaekfjaeifj Because this command makes no sense, the shell tells us so and gives us another chance: bash: kae...
View in text
Excerpt 2
uments to long options are mandatory for short options too. -m, --mode=MODE set file mode (as in chmod), not a=rwx – umask -p, --parents no error i...
View in text
Excerpt 3
er information, consult each command’s man page. Summing Up In this chapter, we saw how Unix-like systems such as Linux manage user permissions to allow the ...
View in text
Excerpt 4
uick brown fox jumps over the lazy dog. It was cool. Line 2 The quick brown fox jumps over the lazy dog. It was cool. -rwxr-xr-x 1 root root 31316 2024...
View in text
Recommended for You
{{#thumbnailUrl}}
{{/thumbnailUrl}}
{{^thumbnailUrl}}
{{/thumbnailUrl}}
Loading recommended books...
Failed to load, please try again later
Tip the Site
Scan the WeChat Pay or Alipay code to tip. No login required.
WeChat Pay
Alipay