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 essentialthats 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), 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.
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 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 presenting 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.
Whats 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. Weve replaced these commands with new ones that youll find immediately practical on a modern Linux system.
Runnable examples
You can now download a set of files from the books website and run the books 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.
Whats Linux?
Linux is a popular, open source operating system that competes with Microsoft Windows and Mac OS X. Like these other operating systems, Linux has a graphical user interface with windows, icons, and mouse control. However, the real power of 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 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 get along fine without typing commands. On Linux, 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, and Mint among others. 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
, short for word count) 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 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:
wc -lw myfile
Same as -l -w
though some programs are quirky and do not recognize combined 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 represent 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: