This book will take your Linux command-line skills to the next level, so you can work faster, smarter, and more efficiently.
In the 30-plus years that I’ve been teaching Linux, I’ve met many users who learned its basic commands by trial and error or by skimming an intro book. These folks had more important work to do, like developing software or maintaining a network, and they learned just enough command-line skills to feel productive. As the years passed, they picked up some cool command-line tricks but never developed a solid understanding of how and why things worked. Their Linux skills, as a result, were relatively slow and inefficient and they had no idea. For example, I’ve watched experienced programmers lose hours of productivity by exiting their text editor in between compiles, when savvy use of job control (Chapter TK) would make them more productive almost instantly.
This book aims to change things by teaching core skills and the core concepts behind them. Think of it as “a second book on Linux” that takes you beyond the basics. You’ll learn to create and run complex commands that solve practical problems, efficiently process and retrieve information, automate manual tasks, tailor your Linux environment, and organize your files for rapid access. Most of all, you’ll learn general best practices so no matter which Linux tools you use, you can become more effective in daily use and more competitive on the job market.
In short, this is the book I wish I had when I learned Linux.
Every Linux command is an act of creation. You’re presented with nothing but a prompt, which is an offer to run any command you may know:
$
What happens next is up to you and your creative mind. There are no friendly icons or buttons to click here. No menus full of convenient operations to choose from. It’s just you and a prompt.
Each time you type a command and press Enter, you’re solving a business problem, whether it’s “Show me my files” or “Track my FedEx package” or “Convert these 20,000 PNG files to JPEG format.” Your solutions may be simple, like this directory listing command:
$ ls
or complex, like this brash one-liner:1
$ paste <(echo {1..10}.jpg | sed 's/ / /g') <(echo {0..9}.jpg | sed 's/ / /g') | sed 's/^/mv /' | bash
If you’re staring at the preceding command and thinking, “What the heck is that?” or “I would never need such a complicated command,” then this book is for you.
Have you ever met a Linux wizard who could produce and run long,
intricate commands, like the earlier paste
command, as fast as they
could type? These folks have a kind of wisdom about commands and how
they combine. This book will share that wisdom and make you faster and
more effective at three essential skills:
Recalling or inventing commands to solve the problem at hand
Running those commands efficiently
Navigating the Linux filesystem with ease, so you can launch commands from anywhere
By the end, you’ll understand what happens behind the scenes when you
run a command, so you can better predict the results (and not develop
superstitions). You’ll see a dozen different methods for launching
commands and learn when to use each one for best advantage, including
ordinary execution, lists, pipelines, subshells, command substitution,
process substitution, bash -c
, xargs
, and more. You’ll also tailor
your Linux account for speed and productivity.
Along with general best practices, you’ll learn individual tips and tricks to make you more productive, such as:
Building complex commands out of simpler ones, step by step, to solve real-world problems, like managing passwords or generating 10,000 test files
Automating tasks with single-use scripts that you throw away afterward, and understanding why this is a good thing
Saving time by organizing your home directory intelligently so you don’t have to hunt for files
Treating any text file like a database that can be queried and transformed by Linux commands
Controlling point-and-click features of Linux from the command line, such as copying and pasting with the clipboard, and retrieving and processing web data, without lifting your hands from the keyboard
This book assumes you have some Linux experience; it’s not an introduction. It’s designed for users with beginning or intermediate skills at the command line, such as students, system administrators, software developers, site reliability engineers, test engineers, and general Linux enthusiasts. Advanced Linux users may find some useful material as well, especially if they learned by trial and error over the years and want to strengthen their conceptual understanding.
To benefit most from this book, you should already be comfortable with the following topics. If not, see Appendix A (forthcoming) for a quick refresher.
Logging into a Linux system
Creating and editing text files with a text editor such as vim, emacs, nano, or pico
Basic file-handling commands like cp
(copy), mv
(move or rename),
rm
(remove or delete), and chmod
(change file permissions)
Basic file-viewing commands like cat
(view an entire file)
and less
(view one page at a time)
Basic directory commands like cd
(change directory), ls
(list files
in a directory), mkdir
(create directory), rmdir
(remove directory),
and pwd
(display your current directory name)
The basics of shell scripts: storing Linux commands in a file,
making the file executable (with chmod 755
or chmod +x
), and running
the file
Viewing Linux’s built-in documentation, known as manpages, with the
man
command (example: man cat
displays documentation on the cat
command)
Becoming the superuser with the sudo
command for full access to
your Linux system (example: sudo nano /etc/hosts
edits the system file
/etc/hosts which is protected from ordinary users)
If you also know common command-line features like pattern-matching for
filenames (with the *
and ?
symbols), input/output redirection (<
and
>
), and pipes (|
), you’re ahead of the game.
This book is not a comprehensive reference for the command line — there are hundreds of commands and features that I don’t mention. This book is about expertise. It teaches a carefully-selected set of command-line wisdom in a practical order to build your skills. For a more reference-style guide, try my previous book, Linux Pocket Guide.
I assume your Linux shell is bash
, which is the default shell for
most Linux distributions. Whenever I write “the shell,” I always mean
bash
. Most of the ideas I present apply to other shells too.
The following typographical conventions are used in this book:
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, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
This element signifies a tip or suggestion.
This element signifies a general note.
This element indicates a warning or caution.
Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/oreillymedia/mastering_linux_command_line.
If you have a technical question or a problem using the code examples, please send email to [email protected].
This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.
We appreciate, but generally do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Book Title by Some Author (O’Reilly). Copyright 2012 Some Copyright Holder, 978-0-596-xxxx-x.”
If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at [email protected].
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 publishers. For more information, visit http://oreilly.com.
Please address comments and questions concerning this book to the publisher:
We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://www.oreilly.com/catalog/9781098113391.
Email [email protected] to comment or ask technical questions about this book.
For news and information about our books and courses, visit http://oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
TK
1 We’ll uncover this mystery command’s purpose in Chapter 8. The final backslash on each line is a line-continuation character, which permits long commands to be split across several lines.
52.91.54.203