3rd Edition Linux Pocket Guide ESSENTIAL COMMANDS Daniel J. Barrett 3RD EDITION Linux Pocket Guide Daniel J. Barrett Linux Pocket Guide by Daniel J. Barrett Copyright © 2016 Daniel 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 promo‐ tional use. Online editions are also available for most titles (http://safaribook‐ sonline.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or [email protected]. Editor: Nan Barber Production Editor: Nicholas Adams Copyeditor: Jasmine Kwityn Proofreader: Susan Moritz Indexer: Daniel Barrett Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Rebecca Demarest June 2016: Third Edition Revision History for the Third Edition 2016-05-27: First Release 2016-07-22: Second Release See http://oreilly.com/catalog/errata.csp?isbn=9781491927571 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. 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 intellec‐ tual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. 978-1-491-92757-1 [M] Table of Contents Linux Pocket Guide 1 What’s in This Book? 1 Practicing with This Book 10 Getting Help 11 Linux: A First View 13 The Filesystem 17 Shell Features 26 Basic File Operations 47 Directory Operations 52 File Viewing 55 File Creation and Editing 63 File Properties 69 File Location 81 File Text Manipulation 92 File Compression and Packaging 108 File Comparison 114 PDF and PostScript File Handling 120 Printing 124 Spellchecking 126 iii Disks and Filesystems 128 Backups and Remote Storage 134 Viewing Processes 138 Controlling Processes 143 Scheduling Jobs 148 Logins, Logouts, and Shutdowns 154 Users and Their Environment 156 User Account Management 161 Becoming the Superuser 166 Group Management 167 Host Information 170 Host Location 174 Network Connections 179 Email 184 Web Browsing 188 Instant Messaging 193 Screen Output 198 Copy and Paste 204 Math and Calculations 206 Dates and Times 211 Graphics 215 Audio and Video 218 Installing Software 223 Programming with Shell Scripts 232 Final Words 248 Index 251 iv | Table of Contents Linux Pocket Guide 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. We cover important, useful aspects of Linux so you can work pro‐ ductively. We do not, however, present every single command and every last option (our apologies if your favorite was omit‐ ted), nor delve into detail about operating system internals. Short, sweet, and essential—that’s our motto. We 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 We’ll cover the most important Linux commands for the aver‐ age user, such as ls (list files), grep (search for text), mplayer (play audio and video files), and df (measure free disk space). We touch only briefly on graphical windowing environments like GNOME and KDE, each of which could fill a Pocket Guide by itself. 1 We’ve organized the material by function to provide a concise learning path. For example, to help you view the contents of a file, we introduce many file-viewing commands together: cat for short text files, less for longer ones, od for binary files, and so on. Then we explain each command in turn, briefly present‐ ing its common uses and options. We assume you have access to a Linux system and know how to log in with your username and password. If not, get your hands on a Linux “live” DVD, such as Ubuntu, Fedora, or Knoppix, which you can boot on most computers to play around with Linux. What’s New in the Third Edition? New commands Technology changes quickly, and some commands that made sense to cover in the first two editions are barely used today. We’ve replaced these commands with new ones that you’ll find immediately practical on a modern Linux system. Runnable examples You can now download a set of files from the book’s web‐ site and run the book’s example commands as you read them. Goodbye, GUI applications We no longer cover applications that have graphical user interfaces, such as photo editors and web browsers, in order to focus purely on commands. You can find these applications yourself pretty easily these days just by searching the Web. What’s Linux? Linux is a popular, open source operating system that competes with Microsoft Windows and Mac OS X. Like these other oper‐ ating systems, Linux has a graphical user interface with win‐ dows, icons, and mouse control. However, the real power of 2 | Linux Pocket Guide Linux comes from its command-line interface, called the shell, for typing and running commands like the preceding wc. Windows and Mac OS X computers can be operated by com‐ mand line as well (Windows with its cmd and PowerShell com‐ mand tools, and OS X with its Terminal application), but most of their users can get along fine without typing commands. On Linux, the shell is critical. If you use Linux without the shell, you are missing out. What’s a Distro? Linux is extremely configurable and includes thousands of pro‐ grams. As a result, different varieties of Linux have arisen to serve different needs and tastes. They all share certain core components but may look different and include different pro‐ grams and files. Each variety is called a distro (short for “distri‐ bution”). Popular distros include Ubuntu Linux, Red Hat Enterprise Linux, Slackware, and Mint among others. This book covers core material that should apply to every distro. What’s a Command? A Linux command typically consists of a program name fol‐ lowed by options and arguments, typed within a shell, like this: wc -l myfile The program name (wc, short for “word count”) refers to a pro‐ gram somewhere on disk that the shell will locate and run. Options, which usually begin with a dash, affect the behavior of the program. In the preceding command, the -l option tells wc to count lines and not words. The argument myfile specifies the file that wc should read and process. Commands can have multiple options and arguments. Options may be given individually: wc -l -w myfile Two individual options or combined after a single dash: What’s in This Book? | 3 wc -lw myfile Same as -l -w though some programs are quirky and do not recognize com‐ bined options. Multiple arguments are also OK: wc -l myfile myfile2 Count lines in two files Options are not standardized. They may be a single dash and one character (say, -l), two dashes and a word (--lines), or several other formats. The same option may have different meanings to different programs: in the command wc -l, the option -l means “lines of text,” but in ls -l it means “longer output.” Two programs also might use different options to mean the same thing, such as -q for “run quietly” versus -s for “run silently.” Some options are followed by a value, such as -s 10, and space between them might not be required (-s10). Likewise, arguments are not standardized. They usually repre‐ sent filenames for input or output, but they can be other things too, like directory names or regular expressions. Commands can be more interesting than just a single program with options: • Commands can run several programs at a time, either in sequence (one program after another) or in a “pipeline” with the output of one command becoming the input of the next. Linux experts use pipelines all the time. • The Linux command-line user interface—the shell—has a programming language built in. So instead of a com‐ mand saying “run this program,” it might say, “run this program, write its output to a file of my choosing, and if any errors occur, send me an email with the results.” Shell prompts Before you can type a command, you must wait for the shell to display a special symbol, called a prompt. A prompt means, “I am waiting for your next command.” Prompts come in all 4 | Linux Pocket Guide shapes and sizes, depending on how your shell is configured. Your prompt might be a dollar sign: $ or a complex string of text containing your computer name, username, and possibly other information and symbols: myhost:~smith$ or various other styles. All these prompts mean the same thing: the shell is ready for your commands. In this book, we’ll use the unique symbol → to indicate a shell prompt, so you won’t mistakenly type it as part of a command.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages268 Page
-
File Size-