Chapter 1. Linux Pocket Guide
Welcome to Linux! If youre 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.
Whats in This Book?
This book is a short guide, not a comprehensive reference . We cover important, useful aspects of Linux so you can work productively. We do not, however, present every single command and every last option (our apologies if your favorite was omitted), nor delve into detail about operating system internals. Short, sweet, and essential, thats our motto.
We focus on commands, those pesky little words you type on a command line to tell a Linux system what to do. Heres an example command that counts lines of text in a file, myfile:
wc -l myfile
Well cover the most important Linux commands for the average user, such as ls
(list files), grep
(search for text in a file), amarok
(play audio 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.
Weve organized the material by function to provide a concise learning path. For example, to help you view the contents of a file, we introduce all file-viewing commands together: cat
for short text files, less
for longer ones, od
for binary files, acroread
for PDF files, and so on. Then we explain each command in turn, briefly presenting its common uses and options.
We assume you have an account on a Linux system and know how to log in with your username and password. If not, speak with your system administrator, or if the system is your own, use the account created when you installed Linux.
Whats Linux?
Linux is a popular, open source operating system that competes with Microsoft Windows and the Apple Macintosh. There are two ways to work with a Linux system:
A graphical user interface with windows, icons, and mouse control.
A command-line interface, called the shell, for typing and running commands like the preceding wc
.
Windows and Mac OS computers can be operated by command line as well (Windows with its cmd
and PowerShell command tools, and OS X with its Terminal application), but most of their users can survive without typing commands. On Linux, however, the shell is critical. If you use Linux without the shell, you are missing out.
Whats a Distro?
Linux is extremely configurable and includes thousands of programs. 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 programs and files. Each variety is called a distro (short for distribution). Popular distros include Ubuntu Linux, Red Hat Enterprise Linux, Slackware, Mint, and more. This book covers core material that should apply to every distro.
Whats a Command?
A Linux command typically consists of a program name followed by options and arguments, typed within a shell, like this:
$ wc -l myfile
The program name (wc
, the word count program) refers to a program 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 rather than words. The argument myfile
specifies the file that wc
should read and process. The leading dollar sign ($
) is a prompt from the shell, indicating that it is waiting for your command.
Commands can have multiple options and arguments. Options may be given individually:
$ wc -l -w myfile
Two individual optionsor combined behind a single dash:
$ wc -lw myfile
Same as -l -wthough some programs are quirky and do not recognize combined options. Multiple arguments are also OK:
$ wc -l myfile1 myfile2
Count lines in two filesOptions are not standardized. The same option letter (say, -l
) may have different meanings to different programs: in wc -l
it means lines of text, but in ls -l
it means longer output. In the other direction, two programs might use different options to mean the same thing, such as -q
for run quietly versus -s
for run silently.
Likewise, arguments are not standardized, unfortunately. They usually represent filenames for input or output, but they can be other things too, like directory names or regular expressions.
Commands can be more complex and interesting than a single program with options:
Commands can run more than one program 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 interfacethe shellhas a programming language built in. So instead of a command saying run this program, it might say, if today is Tuesday, run this program; otherwise, run another command six times for each file whose name ends in .txt.
Reading This Book
Well describe many Linux commands in this book. Each description begins with a standard heading about the command; shows one for the ls
(list files) command. This heading demonstrates the general usage in a simple format:
ls [
options
] [
files
]
which means youd type ls followed, if you choose, by options and then filenames. You wouldnt type the square brackets [ and ]: they just indicate their contents are optional; and words in italics mean you have to fill in your own specific 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.
The special heading also includes six properties of the command printed in black (supported) or gray (unsupported):