Immediate download Linux pocket guide 1st Edition Daniel J Barrett ebooks 2024
Immediate download Linux pocket guide 1st Edition Daniel J Barrett ebooks 2024
Immediate download Linux pocket guide 1st Edition Daniel J Barrett ebooks 2024
https://ebookultra.com
https://ebookultra.com/download/linux-pocket-
guide-1st-edition-daniel-j-barrett/
https://ebookultra.com/download/linux-pocket-guide-3rd-edition-daniel-
j-barrett/
ebookultra.com
https://ebookultra.com/download/linux-pocket-guide-4th-edition-daniel-
barrett/
ebookultra.com
https://ebookultra.com/download/macintosh-terminal-pocket-guide-take-
command-of-your-mac-1st-edition-daniel-j-barrett/
ebookultra.com
https://ebookultra.com/download/linux-guide-to-linux-
certification-2nd-edition-eckert-schitka/
ebookultra.com
Understanding the Linux Kernel 3rd Edition Daniel P. Bovet
https://ebookultra.com/download/understanding-the-linux-kernel-3rd-
edition-daniel-p-bovet/
ebookultra.com
https://ebookultra.com/download/sql-pocket-guide-pocket-guides-third-
edition-jonathan-gennick/
ebookultra.com
https://ebookultra.com/download/pocket-guide-to-reptiles-and-
amphibians-of-east-africa-pocket-guide-stephen-spawls/
ebookultra.com
https://ebookultra.com/download/ultimate-guide-to-architectural-
ceiling-treatments-neal-barrett/
ebookultra.com
https://ebookultra.com/download/the-american-bird-conservancy-guide-
to-bird-conservation-daniel-j-lebbin/
ebookultra.com
Linux pocket guide 1st Edition Daniel J Barrett Digital
Instant Download
Author(s): Daniel J Barrett
ISBN(s): 9780596528768, 0596528760
Edition: 1
File Details: PDF, 1.15 MB
Year: 2004
Language: english
Linux
Pocket Guide
Daniel J. Barrett
Printing History:
February 2004: First Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are
registered trademarks of O’Reilly Media, Inc. The Pocket Guide series
designations, Linux Pocket Guide, the image of a roper, and related trade
dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish
their products are claimed as trademarks. Where those designations appear
in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the
designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the
publisher and author assume no responsibility for errors or omissions, or for
damages resulting from the use of the information contained herein.
0-596-00628-4
[C] [4/06]
Contents
v
Killing a Command in Progress 32
Terminating a Shell 33
Tailoring Shell Behavior 33
Installing Software 33
Basic File Operations 37
Directory Operations 41
File Viewing 43
File Creation and Editing 51
File Properties 56
File Location 65
File Text Manipulation 71
File Compression and Packaging 82
File Comparison 86
Disks and Filesystems 91
Backups and Remote Storage 95
File Printing 101
Spelling Operations 102
Viewing Processes 104
Controlling Processes 108
Users and Their Environment 110
Working with User Accounts 115
vi | Contents
Becoming the Superuser 118
Working with Groups 119
Basic Host Information 121
Host Location 124
Network Connections 128
Email 132
Web Browsing 136
Usenet News 140
Instant Messaging 142
Screen Output 144
Math and Calculations 149
Dates and Times 152
Scheduling Jobs 155
Graphics and Screensavers 160
Audio and Video 163
Programming with Shell Scripts 166
Whitespace and Linebreaks 166
Variables 166
Input and Output 167
Booleans and Return Codes 167
Conditionals 170
Loops 172
Break and Continue 174
Contents | vii
Creating and Running Shell Scripts 176
Command-Line Arguments 177
Exiting with a Return Code 178
Beyond Shell Scripting 178
Final Words 179
Acknowledgments 179
viii | Contents
Linux Pocket Guide
1
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.
What’s Linux?
Linux is a popular, open-source computer software environ-
ment that competes with Microsoft Windows and the Apple
Macintosh. It has four major parts:
The kernel
The low-level operating system, handling files, disks, net-
working, and other necessities we take for granted.
Supplied programs
Thousands of programs for file manipulation, text edit-
ing, mathematics, typesetting, audio, video, computer
programming, web site creation, encryption, CD burn-
ing... you name it.
The shell
A user interface for typing commands, executing them,
and displaying the results. There are various shells in
existence: the Bourne shell, Korn shell, C shell, and oth-
ers. This book focuses on bash, the Bourne Again Shell,
which is often the default for user accounts. However, all
these shells have similar basic functions.
X
A graphical system that provides windows, menus, icons,
mouse support, and other familiar GUI elements. More
complex graphical environments are built on X; the most
popular are KDE and GNOME. Throughout this book, we
discuss programs that open their own X windows to run.
What’s a Command?
A Linux command typically consists of a program name fol-
lowed by options and arguments, typed within a shell. The
program name refers to a program somewhere on disk
(which the shell will locate and run). Options, which usually
begin with a dash, affect the behavior of the program, and
arguments usually represent inputs and outputs. For exam-
ple, this command to count the lines in a file:
$ wc -l myfile
* Red Hat now focuses on its Enterprise Linux products for higher-end appli-
cations. Most of this book applies to Enterprise and other Linux distros.
* For example, you can capture standard output in a file and still have stan-
dard error messages appear on screen.
Standard heading
Each command description begins with a heading like this
one for the ls (list files) command.
The heading includes the command name (ls) and usage, the
directory in which it is located (/bin), the RPM package that
installed the command (coreutils), and six properties of the
command printed in black (supported) or gray (unsupported):
stdin
The command reads from standard input, i.e., your keyboard,
by default.
stdout
The command writes to standard output, i.e., your screen, by
default.
- file
If you supply a dash (-) argument in place of an input file-
name, the command reads from standard input; and likewise,
if the dash is supplied as an output filename, the command
writes to standard output. For example, the following wc
(word count) command line reads the files file1 and file2, then
standard input, then file3:
$ wc file1 file2 - file3
-- opt
If you supply the command-line option “--” it means “end of
options”: anything appearing later on the command line is
not an option. This is sometimes necessary to operate on a file
whose name begins with a dash, which otherwise would be
(mistakenly) treated as an option. For example, if you have a
file named -foo, the command wc -foo will fail because -foo
will be treated as an (invalid) option. wc -- -foo works. If a
command does not support “--”, you can prepend the current
Standard symbols
Throughout the book, we use certain symbols to indicate
keystrokes. Like many other Linux documents, we use the ^
symbol to mean “press and hold the control (Ctrl) key,” so
for example, ^D (pronounced “control D”) means “press and
hold the control key and type D.” We also write ESC to
mean “press the Escape key.” Keys like Enter and Spacebar
should be self-explanatory.
Getting Help
If you need more information than this book provides, there
are several things you can do.
Getting Help | 7
Run the man command
The man command displays an online manual page, or
manpage, for a given program. For example, to get docu-
mentation on listing files with ls, run:
$ man ls
To search for manpages by keyword for a particular
topic, use the -k option followed by the keyword:
$ man -k database
* Unless you’re logging in remotely over the network, in which case you’ll
see a command line, prompting you to type a command.
Interface Take this action... ...to run this shell window program
GNOME Menu : System Tools : Terminal gnome-terminal
or on the desktop:
Right Mouse Button : Open Terminal
KDE Menu : System Tools : Terminal konsole
or on the desktop:
Right Mouse Button : Open Terminal
twm On the desktop: xterm
Right Mouse Button : XTerm
Useful options
-r Reboot the system.
-h Halt the system.
-k Kidding: don’t really perform a shutdown, just broadcast warning messages
to all users as if the system were going down.
-c Cancel a shutdown in progress (omit the time argument).
-f On reboot, skip the usual filesystem check performed by the fsck program
(described in “Disks and Filesystems” on page 91).
-F On reboot, require the usual filesystem check.
The Filesystem
To make use of any Linux system, you need to be comfort-
able with Linux files and their layout. Every Linux file is con-
tained in a collection called a directory. Directories are like
folders on Windows and Macintosh systems. Directories
form a hierarchy, or tree: one directory may contain other
directories, called subdirectories, which may themselves con-
tain other files and subdirectories, and so on, into infinity.
The topmost directory is called the root directory and is
denoted by a slash (/).*
We refer to files and directories using a “names and slashes”
syntax called a path. For instance, this path:
/one/two/three/four
* In Linux, all files and directories descend from the root. This is unlike
Windows or DOS, in which different devices are accessed by drive letters.
The Filesystem | 13
/one/two/three/myfile. Likewise, a relative path a/b/c would
imply the true path /one/two/three/a/b/c.
Two special directories are denoted . (a single period) and ..
(two periods in a row). The former means your current direc-
tory, and the latter means your parent directory, one level
above. So if your current directory is /one/two/three, then .
refers to this directory and .. refers to /one/two.
You “move” your shell from one directory to another using
the cd command:
$ cd /one/two/three
Home Directories
Users’ personal files are often found in /home (for ordinary
users) or /root (for superusers). Your home directory is typically
/home/your-username: /home/smith, /home/jones, etc. There are
several ways to locate or refer to your home directory.
cd
With no arguments, the cd command returns you (i.e., sets
the shell’s working directory) to your home directory.
~
When used in place of a directory, a lone tilde is expanded
by the shell to the name of your home directory.
$ echo ~
/home/smith
When followed by a username (as in ~smith), the shell
expands this string to be the user’s home directory:
$ cd ~smith
$ pwd The “print working directory” command
/home/smith
System Directories
A typical Linux system has tens of thousands of system direc-
tories. These directories contain operating system files, appli-
cations, documentation, and just about everything except
private user files (which typically live in /home).
Unless you’re a system administrator, you’ll rarely visit most
system directories—but with a little knowledge you can
understand or guess their purposes. Their names often con-
tain three parts, which we’ll call the scope, category, and
application. (These are not standard terms, but they’ll help
you understand things.) For example, the directory /usr/local/
share/emacs, which contains local data for the Emacs text
editor, has scope /usr/local (locally installed system files), cat-
egory share (program-specific data and documentation), and
application emacs (a text editor), shown in Figure 2. We’ll
explain these three parts, slightly out of order.
/usr/local/share/emacs
Scope Category Application
The Filesystem | 15
Directory path part 1: category
A category tells you the types of files found in a directory. For
example, if the category is bin, you can be reasonably assured
that the directory contains programs. Common categories are
listed below.
Categories for programs
bin Programs (usually binary files)
sbin Programs (usually binary files) intended to be run by the superuser, root
lib Libraries of code used by programs
libexec Programs invoked by other programs, not usually by users; think
“library of executable programs”
Categories for documentation
doc Documentation
info Documentation files for Emacs’s built-in help system
man Documentation files (manual pages) displayed by the man program; the
files are often compressed, or sprinkled with typesetting commands for
man to interpret
share Program-specific files, such as examples and installation instructions
Categories for configuration
etc Configuration files for the system (and other miscellaneous stuff)
init.d Configuration files for booting Linux; also rc1.d, rc2.d, ...
rc.d
Categories for programming
include Header files for programming
src Source code for programs
Categories for web files
cgi-bin Scripts/programs that run on web pages
html Web pages
public_html Web pages, typically in users’ home directories
www Web pages
Categories for display
fonts Fonts (surprise!)
X11 X window system files
The Filesystem | 17
There isn’t a clear distinction between / and /usr in practice,
but there is a sense that / is “lower-level” and closer to the
operating system. So /bin contains fundamental programs
like ls and cat, /usr/bin contains a wide variety of applica-
tions supplied with your Linux distribution, and /usr/local/
bin contains programs your system administrator chose to
install. These are not hard-and-fast rules but typical cases.
File Protections
A Linux system may have many users with login accounts.
To maintain privacy and security, each user can access only
some files on the system, not all. This access control is
embodied in two questions:
Who has permission? Every file and directory has an owner
who has permission to do anything with it. Typically the
user who created a file is its owner, but relationships can
get more complex.
Additionally, a predefined group of users may have per-
mission to access a file. Groups are defined by the sys-
tem administrator and are covered in “Working with
Groups” on page 119.
Finally, a file or directory can be opened to all users with
login accounts on the system. You’ll also see this set of
users called the world or simply other.
What kind of permission is granted? File owners, groups,
and the world may each have permission to read, write
(modify), and execute (run) particular files. Permissions
also extend to directories, which users may read (access
files within the directory), write (create and delete files
within the directory), and execute (enter the directory).
To see the ownership and permissions of a file, run:
$ ls -l filename
The Filesystem | 19
To see the ownership and permissions of a directory, run:
$ ls -ld directory_name
The Shell
In order to run commands on a Linux system, you’ll need
somewhere to type them. That “somewhere” is called the
shell, which is Linux’s command-line user interface: you type
a command and press Enter, and the shell runs whatever pro-
gram (or programs) you’ve requested. To run a shell, see
“Fedora: A First View” on page 9.
For example, to see who’s logged in, you could execute this
command in a shell:
$ who
barrett :0 Sep 23 20:44
byrnes pts/0 Sep 15 13:51
silver pts/1 Sep 22 21:15
silver pts/2 Sep 22 21:18
telling you how many users are logged in.* The vertical bar,
called a pipe, makes the connection between who and wc.
A shell is actually a program itself, and Linux has several. We
focus on Bash (the “Bourne-Again Shell”), located in /bin/
bash, which is the Fedora Linux default.
* Actually, how many interactive shells those users are running. If a user has
several shells running, like the user silver in our example, they’ll have that
many lines of output in who.
The Shell | 21
are wildcards for matching filenames, redirection of com-
mand output and input to and from files, pipes for making
the output of one command become the input of another,
aliases to run common commands quickly, variables for stor-
ing values for use by the shell, and more. We’re just scratch-
ing the surface to introduce you to a set of useful tools. Run
info bash for full documentation.
Wildcards
Wildcards provide a shorthand for specifying sets of files
with similar names. For example, a* means all files whose
names begin with lowercase “a”. Wildcards are “expanded”
by the shell into the actual set of filenames they match. So if
you type:
$ ls a*
the shell first expands a* into the filenames that begin with
“a” in your current directory, as if you had typed:
ls aardvark adamantium apple
ls never knows you used a wildcard: it sees only the final list
of filenames after the shell expansion.
Wildcard Meaning
* Any set of characters except a leading period
? Any single character
[set] Any single character in the given set, most commonly a sequence of
characters, like [aeiouAEIOU] for all vowels, or a range with a dash,
like [A-Z] for all capital letters
[^set] Any single character not in the given set (as above)
[!set]
Tilde expansion
The shell treats tildes (~) as special characters if they appear
alone or at the beginning of a word.
~ Your home directory
~smith User smith’s home directory
Shell variables
You can define variables and their values by assigning them:
$ MYVAR=3
Variable Meaning
DISPLAY The name of your X window display
HOME The name of your home directory
The Shell | 23
Variable Meaning
LOGNAME Your login name
MAIL Path to your incoming mailbox
OLDPWD Your shell's previous directory
PATH Your shell search path: directories separated by colons
PWD Your shell's current directory
SHELL The path to your shell, e.g., /bin/bash
TERM The type of your terminal, e.g., xterm or vt100
USER Your login name
or the shorthand:
$ export MYVAR=3
Your variable is now called an environment variable, since it’s
available to other programs in your shell’s “environment.”
To make a specific value available to a specific program just
once, prepend variable=value to the command line:
$ echo $HOME
/home/smith
$ HOME=/home/sally echo "My home is $HOME"
My home is /home/sally
$ echo $HOME
/home/smith The original value is unaffected
Search path
A very important variable is PATH, which instructs the shell
where to find programs. When you type any command:
$ who
Aliases
The built-in command alias defines a convenient shorthand
for a longer command, to save typing. For example:
$ alias ll='ls -l'
The Shell | 25
“Programming with Shell Scripts” on page 166, run info bash,
and read up on “shell functions.”
Input/output redirection
The shell can redirect standard input, standard output, and
standard error to and from files. In other words, any com-
mand that reads from standard input can have its input come
from a file instead with the shell’s < operator:
$ mycommand < infile
Pipes
Using the shell, you can redirect the standard output of one
command to be the standard input of another, using the
shell’s pipe (|) operator. For example:
$ who | sort
Combining commands
To invoke several commands in sequence on a single com-
mand line, separate them with semicolons:
$ command1 ; command2 ; command3
Quoting
Normally, the shell treats whitespace simply as separating
the words on the command line. If you want a word to con-
tain whitespace (e.g., a filename with a space in it), surround
it with single or double quotes to make the shell treat it as a
unit. Single quotes treat their contents literally, while double
quotes let shell constructs be evaluated, such as variables:
$ echo 'The variable HOME has value $HOME'
The variable HOME has value $HOME
$ echo "The variable HOME has value $HOME"
The variable HOME has value /home/smith
Escaping
If a character has special meaning to the shell but you want it
used literally (e.g., * as a literal asterisk rather than a wild-
card), precede the character with the backward slash “\”
character. This is called escaping the special character:
$ echo a* As a wildcard, matching “a” filenames
aardvark agnostic apple
$ echo a\* As a literal asterisk
a*
The Shell | 27
$ echo "I live in $HOME" Dollar sign means a variable value
I live in /home/smith
$ echo "I live in \$HOME" A literal dollar sign
I live in $HOME
Command-line editing
bash lets you edit the command line you’re working on, using
keystrokes inspired by the text editors emacs and vi (see “File
Creation and Editing” on page 51). To enable command-line
editing with emacs keys, run this command (and place it in
your ~/.bash_profile to make it permanent):
$ set -o emacs
For vi keys:
$ set -o vi
vi keystroke
emacs keystroke (first type ESC) Meaning
^P or up arrow k Previous command line
^N or down arrow j Next command line
^F or right arrow l Forward one character
^B or left arrow h Backward one character
^A 0 Beginning of line
^E $ End of line
^D x Delete next character
^U ^U Erase entire line
Command Meaning
history Print your history
history N Print the most recent N commands in your history
history -c Clear (delete) your history
!! Previous command
!N Command number N in your history
!-N The command you typed N commands ago
!$ The last parameter from the previous command; great for checking
that files are present before removing them:
$ ls a*
$ rm !$
!* All parameters from the previous command
Filename completion
Press the TAB key while you are in the middle of typing a
filename, and the shell will automatically complete (finish
typing) the filename for you. If several filenames match what
you’ve typed so far, the shell will beep, indicating the match
is ambiguous. Immediately press TAB again and the shell will
present the alternatives. Try this:
$ cd /usr/bin
$ ls un<TAB><TAB>
Job Control
jobs List your jobs
& Run a job in the background
^Z Suspend the current (foreground) job
suspend Suspend a shell
fg Unsuspend a job: bring it into the foreground
bg Make a suspended job run in the background
The Shell | 29
All Linux shells have job control: the ability to run programs
in the background (multitasking behind the scenes) and fore-
ground (running as the active process at your shell prompt).
A job is simply the shell’s unit of work. When you run a
command interactively, your current shell tracks it as a job.
When the command completes, the associated job disap-
pears. Jobs are at a higher level than Linux processes; the
Linux operating system knows nothing about them. They are
merely constructs of the shell. Some important vocabulary
about job control is:
foreground job
Running in a shell, occupying the shell prompt so you
cannot run another command
background job
Running in a shell, but not occupying the shell prompt,
so you can run another command in the same shell
suspend
To stop a foreground job temporarily
resume
To cause a suspended job to start running again
jobs
The built-in command jobs lists the jobs running in your current
shell.
$ jobs
[1]- Running emacs myfile &
[2]+ Stopped su
The integer on the left is the job number, and the plus sign identi-
fies the default job affected by the fg (foreground) and bg
(background) commands.
&
Placed at the end of a command-line, the ampersand causes the
given command to run as a background job.
$ emacs myfile &
[2] 28090
^Z
Typing ^Z in a shell, while a job is running in the foreground, will
suspend that job. It simply stops running, but its state is
remembered.
$ mybigprogram
^Z
[1]+ Stopped mybigprogram
$
Now you’re ready to type bg to put the command into the back-
ground, or fg to resume it in the foreground.
suspend
The built-in command suspend will suspend the current shell if
possible, as if you’d typed ^Z to the shell itself. For instance, if
you’ve run the su command and want to return to your original
shell:
$ whoami
smith
$ su -l
Password: *******
# whoami
root
# suspend
[1]+ Stopped su
$ whoami
smith
bg [%jobnumber]
The built-in command bg sends a suspended job to run in the
background. With no arguments, bg operates on the most recently
suspended job. To specify a particular job (shown by the jobs
command), supply the job number preceded by a percent sign:
$ bg %2
The Shell | 31
Some types of interactive jobs cannot remain in the background—
for instance, if they are waiting for input. If you try, the shell will
suspend the job and display:
[2]+ Stopped command line here
You can now resume the job (with fg) and continue.
fg [%jobnumber]
The built-in command fg brings a suspended or backgrounded
job into the foreground. With no arguments, it selects a job,
usually the most recently suspended or backgrounded one. To
specify a particular job (as shown by the jobs command), supply
the job number preceded by a percent sign:
$ fg %2
Terminating a Shell
To terminate a shell, either run the exit command or type
^D.*
$ exit
Installing Software
You will probably want to add further software to your Linux
system from time to time. The most common forms of pack-
aged software for Fedora and many other Linux distros are:
Installing Software | 33
*.rpm files
Red Hat Package Manager (RPM) files. These are
installed and managed with the programs rpm (manually)
and up2date (automatically).
*.tar.gz files, *.tar.Z files, and *.tar.bz2 files
Compressed tar files. They are packaged with tar and
compressed with gzip (.gz), compress (.Z), or bzip2 (.bz2).
Most new software must be installed by the superuser, so
you’ll need to run the su command (or equivalent) before
installation. For example:
$ su -l
Password: ********
# rpm -ivh mypackage.rpm
...etc...
to list all updated RPM packages (if any) available for your
system. To download the given packages, run:
# up2date -d packages
Installing Software | 35
rpm -ql package_name
List the files included in the given, installed package. Try
rpm -ql emacs.
rpm -qi package_name
Get general information about the package.
rpm -qlp package.rpm
List the contents of an RPM file, not necessarily installed
yet. Use -qip for general information about the RPM file.
rpm -qa
List all installed RPM packages. Useful for piping
through grep to locate a package name:
rpm -qa | grep -i emacs
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.