Linux Pocket Guide Essential Commands (Daniel J. Barrett) (Z-Library)
Author: Unknown Author
技术
No Description
📄 File Format:
PDF
💾 File Size:
5.3 MB
199
Views
69
Downloads
0.00
Total Donations
📄 Text Preview (First 20 pages)
ℹ️
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
Linux Pocket Guide Essential Commands Daniel J. Barrett 20th Anniversary Release Fourth Edition
📄 Page
2
Linux Pocket Guide If you use Linux in your day-to-day work, then Linux Pocket Guide is the perfect on-the-job reference. This thoroughly updated 20th anniversary edition explains more than 200 Linux commands, including new commands for file handling, package management, version control, file format conversions, and more. In this concise guide, author Daniel Barrett provides the most useful Linux commands grouped by functionality. Whether you’re a novice or an experienced user, this practical book is an ideal reference for the most important Linux commands. You’ll learn: • Essential concepts—commands, shells, users, and the filesystem • File commands—creating, organizing, manipulating, and processing files of all kinds • Sysadmin basics—superusers, processes, user management, and software installation • Filesystem maintenance—disks, RAID, logical volumes, backups, and more • Networking commands—working with hosts, network connections, email, and the web • Getting stuff done—everything from math to version control to graphics and audio LINUX 9 7 8 1 0 9 8 1 5 7 9 6 8 5 2 9 9 9 US $29.99 CAN $37.99 ISBN: 978-1-098-15796-8 linkedin.com/company/oreilly-media youtube.com/oreillymedia
📄 Page
3
Praise for Linux Pocket Guide Linux Pocket Guide is a must-have book on every Linux user’s desk, even in this digital age. It’s like a collection of my favorite bookmarked manual pages that I keep revisiting for reference, but simpler to understand and easier to follow. —Abhishek Prakash, cofounder of It’s FOSS One of the beloved features of Linux environments is the assortment of small utilities that combine in wonderful ways to solve problems. This book distills that experience into an accessible reference. Even experienced readers will rediscover forgotten facets and incredible options on their favorite tools. —Jess Males, DevOps engineer, TriumphPay This is such a handy reference! It somehow manages to be both thorough and concise. —Jerod Santo, changelog.com
📄 Page
4
Daniel J. Barrett Linux Pocket Guide 4TH EDITION
📄 Page
5
978-1-098-15796-8 [LSI] Linux Pocket Guide by Daniel J. Barrett Copyright © 2024 Daniel J. Barrett. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebasto‐ pol, CA 95472. O’Reilly books may be purchased for educational, business, or sales pro‐ motional use. Online editions are also available for most titles (https:// oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com. Acquisitions Editor: John Devins Development Editor: Virginia Wilson Production Editor: Ashley Stussy Copyeditor: Stephanie English Proofreader: Dwight Ramsey Indexer: Daniel J. Barrett and BIM Creatives, LLC Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Kate Dullea March 2024: Fourth Edition Revision History for the Fourth Edition 2024-03-01: First Release See https://oreil.ly/lpg4eERR for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Linux Pocket Guide, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the author and do not represent the publisher’s views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
📄 Page
6
Table of Contents First Things First ix Chapter 1: Essential Concepts 19 What’s Linux? 19 The Structure of Commands 24 Users and Superusers 26 The Filesystem 27 Selected Features of Bash 36 Getting Help 59 Chapter 2: File Commands 61 Basic File Operations 61 Directory Operations 68 Viewing Files 71 Creating and Editing Files 78 Properties of Files 83 Locating Files 97 Manipulating Text in Files 107 Compressing, Packaging, and Encrypting 126 v
📄 Page
7
Comparing Files 135 Converting Files to Other Formats 140 PDF and PostScript File Handling 151 Printing 156 Spellchecking 158 Chapter 3: System Administration Basics 161 Becoming the Superuser 161 Viewing Processes 163 Controlling Processes 169 Scheduling Jobs 175 Logins, Logouts, and Shutdowns 181 Users and Their Environment 184 User Account Management 188 Group Management 192 Installing Software Packages 195 Installing Software from Source Code 209 Chapter 4: Filesystem Maintenance 213 Using Disks and Filesystems 213 Creating and Modifying Filesystems 219 RAID Arrays for Redundancy 224 Logical Volumes for Flexible Storage 229 ZFS: A Modern, Do-It-All Filesystem 235 Backups and Remote Storage 241 Chapter 5: Networking Commands 249 Host Information 249 Host Location 252 Network Connections 256 Email in Daily Use 262 vi | Table of Contents
📄 Page
8
Email Servers 266 Web Browsing 270 Chapter 6: Getting Stuff Done 275 Screen Output 275 Copy and Paste 281 Math and Calculations 283 Dates and Times 289 Version Control 292 Containers 297 Displaying and Processing Images 301 Audio and Video 303 Programming with Shell Scripts 311 Final Words 328 Index 329 Table of Contents | vii
📄 Page
9
(This page has no text content)
📄 Page
10
First Things First Welcome to Linux! If you’re a new user, this book can serve as a quick introduction, as well as a guide to common and practical commands. If you have Linux experience, feel free to skip the introductory material. What’s in This Book? This book is a short guide, not a comprehensive reference. I cover important, useful aspects of Linux so you can work pro‐ ductively. I do not, however, present every single command and every last option (my apologies if your favorite was omit‐ ted), nor delve into detail about operating system internals. Short, sweet, and essential—that’s our motto. I focus on commands, those pesky little words you type on a command line to tell a Linux system what to do. Here’s an example command that counts lines of text in a file, myfile: wc -l myfile This book covers important Linux commands for most users, such as ls (list files), grep (search for text), mplayer (play audio and video files), and df (measure free disk space). I touch only briefly on graphical environments like GNOME and KDE Plasma, each of which could fill a Pocket Guide by itself. ix
📄 Page
11
I’ve organized the material by function to provide a concise learning path. For example, to help you view the contents of a file, I introduce many file-viewing commands together: cat for short text files, less for longer ones, od for binary files, and so on. Then I explain each command in turn, briefly presenting its common uses and options. I assume you have access to a Linux system and can log in. If not, it’s easy to try out Linux on most computers. Just download and install a “live” Linux distribution onto a USB thumb drive and boot it. Examples are Ubuntu, Fedora, and KNOPPIX. What’s New in the Fourth Edition? New commands I’ve added 50 new commands to this edition, such as git and svn for version control, split and column for text manipulation, pandoc and ffmpeg for file conversion, snap and flatpak for package management, mdadm, lvcreate, and zfs for fancy storage management, gpg for encryp‐ tion, and many others. Clearer organization I’ve reorganized the book into chapters on concepts, files, basic system administration, networking, and other topics. Goodbye, ancient commands Some commands from previous editions of this book are mostly obsolete today, such as write and finger, or depre‐ cated, such as ftp. I’ve replaced them with more relevant commands for modern Linux systems. Conventions Used in This Book Each command I present in this book begins with a standard heading. Figure P-1 shows the heading for ls, a command that lists the names and attributes of files. The heading demon‐ strates the command’s general usage in a simple format: x | First Things First
📄 Page
12
ls [options] [files] which means you’d type “ls” followed, if you choose, by options and then filenames. Don’t type the square brackets “[” and “]” —they just indicate their contents are optional. Words in italics mean you have to fill in your own values, like names of actual files. If you see a vertical bar between options or arguments, perhaps grouped by parentheses: (file | directory) this indicates choice: you may supply either a filename or directory name as an argument. Figure P-1. Standard command heading The standard heading shown in Figure P-1 also includes six properties of the command, printed in black (supported) or gray (unsupported): stdin The command reads by default from standard input (i.e., your keyboard). See “Input, Output, and Redirection” on page 43. stdout The command writes by default to standard output (i.e., your display). See “Input, Output, and Redirection” on page 43. - file A single-dash argument (-), when provided as an input filename, tells the command to read from standard input rather than a disk file. Likewise, if the dash is supplied as an output filename, the command writes to standard output. For example, the following wc command line reads First Things First | xi
📄 Page
13
the files myfile and myfile2, then standard input, then myfile3: wc myfile myfile2 - myfile3 -- opt A double-dash option (--) means “end of options”: any strings appearing later on the command line are not treated as options. A double dash is sometimes necessary to work with a filename that begins with a dash, which otherwise would be (mistakenly) treated as an option. For example, if you have a file named -dashfile, the command wc -dashfile fails because the string -dashfile is treated as an (invalid) option. Run wc -- -dashfile to indicate -dashfile is a filename. If a command does not support “--”, you can still work around the problem by prepending the current directory path “./” to the filename so the dash is no longer the first character: wc ./-dashfile --help The option --help makes the command print a help mes‐ sage explaining proper usage, then exit. --version The option --version makes the command print its ver‐ sion information and exit. Commands, Prompts, and Output The Linux command line, or shell, prints a special symbol, called a prompt, when it’s waiting for a command. In this book, the prompt is a right-facing arrow: → Prompts come in all shapes and sizes, depending on how your shell is configured. Your prompt might be a dollar sign ($), a combination of your computer name, username, and various symbols (myhost:~smith$), or something else. Every xii | First Things First
📄 Page
14
prompt means the same thing: the shell is ready for your next command. When I show a command line in this book, some parts are meant to be typed by the user, and other parts are not (like the prompt and the command’s output). I use boldface to identify the parts to type. Sometimes I add italic comments to explain what’s going on: → wc -l myfile The command to type at the prompt 18 myfile The output it produces Your Friend, the echo Command In many of my examples, I print information to the screen with the echo command, which I formally describe in “Screen Output” on page 275. echo is one of the simplest commands—it merely prints its arguments on standard output, once those arguments have been processed by the shell: → echo My dog has fleas My dog has fleas → echo My name is $USER The shell variable USER My name is smith Long Command Lines Sometimes, a command is longer than the width of a page, so I split it onto multiple lines. A final backslash character means “continued on the next line”: → echo This is a long command that does not fit on \ one line This is a long command that does not fit on one line If you enter one of my multiline commands in a running shell, feel free to break it up with backslashes as I did, or just type the whole command on one line without backslashes. First Things First | xiii
📄 Page
15
1 Or, if you are experienced with git and GitHub, download the files and skip the rest of my instructions. If you clone the repository and want to restore the files to their original state, don’t run the reset-lpg script; run git reset --hard instead. Keystrokes I use certain symbols for keystrokes. The caret (^) means “hold down the Control key,” usually labeled Ctrl. For example, ^D (Ctrl D) means “hold down the Ctrl key and type D.” I also write ESC to mean “press and release the Escape key.” Keys like Enter and the space bar should be self-explanatory. Downloading the Practice Files I’ve created a collection of files to help you practice with Linux. Download and install them on any Linux machine, and you can run most of the example commands in this book verbatim. To download them for the first time, run the following com‐ mands.1 (Note that -O contains a capital O, not a zero.) → cd → curl -O https://linuxpocketguide.com/LPG4.tar.gz → tar -xf LPG4.tar.gz The preceding commands create a directory named linuxpock‐ etguide in your home directory. Visit this directory: → cd ~/linuxpocketguide and run commands as you read the book. The output should match the book’s except for local details like dates and usernames. To re-download and install the practice files (say, if you’ve modified them), simply run the provided reset-lpg script: → cd ~/linuxpocketguide → bash reset-lpg xiv | First Things First
📄 Page
16
If you’ve placed the practice files in a different directory, supply it to reset-lpg. The following command creates or refreshes the directory /tmp/practice/linuxpocketguide: → bash reset-lpg /tmp/practice Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, state‐ ments, and keywords. Constant width bold Shows commands or other text that should be typed liter‐ ally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values determined by context. TIP This element signifies a tip or suggestion. NOTE This element signifies a general note. First Things First | xv
📄 Page
17
WARNING This element indicates a warning or caution. O’Reilly Online Learning For more than 40 years, O’Reilly Media has provided technology and business training, knowledge, and insight to help companies succeed. Our unique network of experts and innovators share their knowledge and expertise through books, articles, and our online learning platform. O’Reilly’s online learning platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+ other pub‐ lishers. For more information, visit https://oreilly.com. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-889-8969 (in the United States or Canada) 707-827-7019 (international or local) 707-829-0104 (fax) support@oreilly.com https://www.oreilly.com/about/contact.html We have a web page for this book, where we list errata, exam‐ ples, and any additional information. You can access this page at https://oreil.ly/linux-pocket-guide-4e. xvi | First Things First
📄 Page
18
For news and information about our books and courses, visit https://oreilly.com. Find us on LinkedIn: https://linkedin.com/company/oreilly- media. Watch us on YouTube: https://youtube.com/oreillymedia. Acknowledgments I am so grateful to the many readers who purchased the first three editions of this book over the past 20(!) years, making the fourth edition possible. My heartfelt thanks also go to my editor Virginia Wilson, acquisitions editor John Devins, the O’Reilly production team, my awesome technical reviewers (Abhishek Prakash, Dan Ritter, Doron Beit-Halahmi, Ethan Schwartz, and Jess Males), Maggie Johnson at Google, and Kerry and Lesley Minnear at Alucard Music. And all my love to my wonderful family, Lisa, Sophia, Kay, and Luna. First Things First | xvii
📄 Page
19
(This page has no text content)
📄 Page
20
CHAPTER 1 Essential Concepts What’s Linux? Linux is a free, open source operating system (OS) that’s an alternative to Microsoft Windows and Apple macOS. Linux powers most of the servers on the internet. It operates behind the scenes on every Android mobile phone and Chromebook, and on millions of network-connected devices like routers, firewalls, and robotic cow-milking systems (seriously). It also runs fine on desktop and laptop computers. Linux has four major parts, shown in Figure 1-1: The kernel Low-level software. It controls the hardware and basic functions like process scheduling and networking. Few users interact with the kernel directly. Supplied programs Thousands of programs for file handling, text edit‐ ing, software development, web browsing, audio, video, encryption, mathematics…you name it. These programs talk to the kernel. Programs that run on the command line are called commands. 19
The above is a preview of the first 20 pages. Register to read the complete e-book.