Acknowledgments |
|
xxiii | |
|
|
xxiii | |
|
|
xxiv | |
Introduction |
|
xxv | |
|
Why Use the Command Line2 |
|
|
xxvi | |
|
|
xxvi | |
|
Who Should Read This Book |
|
|
xxvii | |
|
|
xxvii | |
|
|
xxviii | |
|
|
xxviii | |
|
What's New in the Second Edition |
|
|
xxix | |
|
|
xxx | |
Part I: Learning The Shell |
|
|
|
3 | (4) |
|
|
3 | (1) |
|
Making Your First Keystrokes |
|
|
4 | (1) |
|
|
4 | (1) |
|
|
4 | (1) |
|
|
5 | (1) |
|
Ending a Terminal Session |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
7 | (6) |
|
Understanding the File System Tree |
|
|
7 | (1) |
|
The Current Working Directory |
|
|
8 | (1) |
|
Listing the Contents of a Directory |
|
|
9 | (1) |
|
Changing the Current Working Directory |
|
|
9 | (3) |
|
|
9 | (1) |
|
|
9 | (2) |
|
|
11 | (1) |
|
|
12 | (1) |
|
|
13 | (10) |
|
|
13 | (3) |
|
|
14 | (1) |
|
A Longer Look at Long Format |
|
|
15 | (1) |
|
Determining a File's Type with file |
|
|
16 | (1) |
|
Viewing File Contents with less |
|
|
17 | (1) |
|
|
18 | (3) |
|
|
21 | (1) |
|
|
22 | (1) |
|
|
22 | (1) |
|
4 Manipulating Files And Directories |
|
|
23 | (16) |
|
|
24 | (2) |
|
|
26 | (1) |
|
cp-Copy Files and Directories |
|
|
26 | (1) |
|
Useful Options and Examples |
|
|
26 | (1) |
|
|
27 | (1) |
|
Useful Options and Examples |
|
|
28 | (1) |
|
rm-Remove Files and Directories |
|
|
28 | (2) |
|
Useful Options and Examples |
|
|
29 | (1) |
|
|
30 | (1) |
|
|
30 | (1) |
|
|
31 | (1) |
|
|
31 | (6) |
|
|
31 | (1) |
|
|
31 | (1) |
|
Moving and Renaming Files |
|
|
32 | (1) |
|
|
33 | (1) |
|
|
34 | (1) |
|
Removing Files and Directories |
|
|
35 | (2) |
|
|
37 | (2) |
|
|
39 | (10) |
|
What Exactly Are Commands? |
|
|
40 | (1) |
|
|
40 | (1) |
|
type-Display a Command's Type |
|
|
40 | (1) |
|
which-Display an Executable's Location |
|
|
40 | (1) |
|
Getting a Command's Documentation |
|
|
41 | (5) |
|
help-Get Help for Shell Builtins |
|
|
41 | (1) |
|
-help-Display Usage Information |
|
|
42 | (1) |
|
man-Display a Program's Manual Page |
|
|
42 | (2) |
|
apropos-Display Appropriate Commands |
|
|
44 | (1) |
|
whatis-Display One-line Manual Page Descriptions |
|
|
44 | (1) |
|
info-Display a Program's Info Entry |
|
|
45 | (1) |
|
README and Other Program Documentation Files |
|
|
46 | (1) |
|
Creating Our Own Commands with alias |
|
|
46 | (2) |
|
|
48 | (1) |
|
|
49 | (12) |
|
Standard Input, Output, and Error |
|
|
50 | (1) |
|
Redirecting Standard Output |
|
|
50 | (2) |
|
Redirecting Standard Error |
|
|
52 | (1) |
|
Redirecting Standard Output and Standard Error to One File |
|
|
52 | (1) |
|
Disposing of Unwanted Output |
|
|
53 | (1) |
|
Redirecting Standard Input |
|
|
53 | (2) |
|
|
53 | (2) |
|
|
55 | (4) |
|
|
55 | (1) |
|
uniq: Report or Omit Repeated Lines |
|
|
56 | (1) |
|
wc: Print Line, Word, and Byte Counts |
|
|
57 | (1) |
|
grey: Print Lines Matching a Pattern |
|
|
57 | (1) |
|
head/tail: Print First/Last Part of Files |
|
|
58 | (1) |
|
tee: Read from Stdin and Output to Stdout and Files |
|
|
59 | (1) |
|
|
59 | (2) |
|
7 Seeing The World As The Shell Sees It |
|
|
61 | (12) |
|
|
61 | (6) |
|
|
62 | (1) |
|
|
63 | (1) |
|
|
64 | (1) |
|
|
65 | (1) |
|
|
66 | (1) |
|
|
67 | (1) |
|
|
67 | (4) |
|
|
68 | (1) |
|
|
69 | (1) |
|
|
70 | (1) |
|
Backslash Escape Sequences |
|
|
70 | (1) |
|
|
71 | (2) |
|
8 Advanced Keyboard Tricks |
|
|
73 | (8) |
|
|
74 | (2) |
|
|
74 | (1) |
|
|
74 | (1) |
|
Cutting and Pasting (Killing and Yanking) Text |
|
|
75 | (1) |
|
|
76 | (1) |
|
|
77 | (3) |
|
|
77 | (2) |
|
|
79 | (1) |
|
|
80 | (1) |
|
|
81 | (18) |
|
Owners, Group Members, and Everybody Else |
|
|
82 | (1) |
|
Reading, Writing, and Executing |
|
|
83 | (8) |
|
|
85 | (3) |
|
Setting File Mode with the GUI |
|
|
88 | (1) |
|
umask: Set Default Permissions |
|
|
89 | (1) |
|
|
90 | (1) |
|
|
91 | (4) |
|
su: Run a Shell with Substitute User and Group IDs |
|
|
92 | (1) |
|
sudo: Execute a Command As Another User |
|
|
93 | (1) |
|
chown: Change File Owner and Group |
|
|
94 | (1) |
|
chgrp: Change Group Ownership |
|
|
95 | (1) |
|
Exercising Our Privileges |
|
|
95 | (2) |
|
|
97 | (1) |
|
|
98 | (1) |
|
|
99 | (16) |
|
|
100 | (1) |
|
|
100 | (4) |
|
Viewing Processes Dynamically with top |
|
|
102 | (2) |
|
|
104 | (3) |
|
|
105 | (1) |
|
Putting a Process in the Background |
|
|
105 | (1) |
|
Returning a Process to the Foreground |
|
|
106 | (1) |
|
Stopping (Pausing) a Process |
|
|
106 | (1) |
|
|
107 | (3) |
|
Sending Signals to Processes with kill |
|
|
107 | (2) |
|
Sending Signals to Multiple Processes with killall |
|
|
109 | (1) |
|
|
110 | (1) |
|
More Process-Related Commands |
|
|
111 | (1) |
|
|
111 | (4) |
Part II: Configuration And The Environment |
|
|
|
115 | (12) |
|
What Is Stored in the Environment? |
|
|
116 | (2) |
|
Examining the Environment |
|
|
116 | (1) |
|
Some Interesting Variables |
|
|
117 | (1) |
|
How Is the Environment Established? |
|
|
118 | (3) |
|
What's in a Startup File? |
|
|
119 | (2) |
|
Modifying the Environment |
|
|
121 | (4) |
|
Which Files Should We Modify? |
|
|
121 | (1) |
|
|
121 | (1) |
|
|
122 | (3) |
|
|
125 | (1) |
|
|
125 | (2) |
|
12 A Gentle Introduction To VI |
|
|
127 | (18) |
|
|
128 | (1) |
|
|
128 | (1) |
|
|
128 | (2) |
|
|
130 | (1) |
|
|
131 | (1) |
|
|
131 | (1) |
|
|
131 | (1) |
|
|
132 | (4) |
|
|
132 | (1) |
|
|
133 | (1) |
|
|
134 | (1) |
|
Cuffing, Copying, and Pasting Text |
|
|
135 | (1) |
|
|
136 | (1) |
|
|
136 | (3) |
|
|
137 | (1) |
|
Searching the Entire File |
|
|
137 | (1) |
|
Global Search-and-Replace |
|
|
137 | (2) |
|
|
139 | (3) |
|
|
139 | (1) |
|
Opening Additional Files for Editing |
|
|
140 | (1) |
|
Copying Content from One File into Another |
|
|
141 | (1) |
|
Inserting an Entire File into Another |
|
|
141 | (1) |
|
|
142 | (1) |
|
|
143 | (2) |
|
13 Customizing The Prompt |
|
|
145 | (10) |
|
|
145 | (2) |
|
Trying Some Alternative Prompt Designs |
|
|
147 | (1) |
|
|
148 | (2) |
|
|
150 | (1) |
|
|
151 | (1) |
|
|
151 | (4) |
Part III: Common Tasks And Essential Tools |
|
|
|
155 | (10) |
|
|
156 | (1) |
|
How a Package System Works |
|
|
156 | (2) |
|
|
156 | (1) |
|
|
157 | (1) |
|
|
157 | (1) |
|
High- and Low-Level Package Tools |
|
|
158 | (1) |
|
Common Package Management Tasks |
|
|
158 | (4) |
|
Finding a Package in a Repository |
|
|
158 | (1) |
|
Installing a Package from a Repository |
|
|
159 | (1) |
|
Installing a Package from a Package File |
|
|
159 | (1) |
|
|
160 | (1) |
|
Updating Packages from a Repository |
|
|
160 | (1) |
|
Upgrading a Package from a Package File |
|
|
160 | (1) |
|
Listing Installed Packages |
|
|
161 | (1) |
|
Determining Whether a Package Is Installed |
|
|
161 | (1) |
|
Displaying Information About an Installed Package |
|
|
161 | (1) |
|
Finding Which Package Installed a File |
|
|
162 | (1) |
|
|
162 | (3) |
|
|
165 | (16) |
|
Mounting and Unmounting Storage Devices |
|
|
166 | (7) |
|
Viewing a List of Mounted File Systems |
|
|
167 | (3) |
|
|
170 | (3) |
|
Creating New File Systems |
|
|
173 | (3) |
|
Manipulating Partitions with fdisk |
|
|
173 | (2) |
|
Creating a New File System with mkfs |
|
|
175 | (1) |
|
Testing and Repairing File Systems |
|
|
176 | (1) |
|
Moving Data Directly to and from Devices |
|
|
177 | (1) |
|
|
177 | (1) |
|
Creating an Image Copy of a CD-ROM |
|
|
177 | (1) |
|
Creating an Image from a Collection of Files |
|
|
178 | (1) |
|
|
178 | (1) |
|
Mounting an ISO Image Directly |
|
|
179 | (1) |
|
Blanking a Rewritable CD-ROM |
|
|
179 | (1) |
|
|
179 | (1) |
|
|
179 | (1) |
|
|
180 | (1) |
|
|
181 | (14) |
|
Examining and Monitoring a Network |
|
|
182 | (3) |
|
|
182 | (1) |
|
|
183 | (1) |
|
|
184 | (1) |
|
|
184 | (1) |
|
Transporting Files over a Network |
|
|
185 | (3) |
|
|
186 | (1) |
|
|
187 | (1) |
|
|
188 | (1) |
|
Secure Communication with Remote Hosts |
|
|
188 | (5) |
|
|
188 | (4) |
|
|
192 | (1) |
|
|
193 | (2) |
|
|
195 | (14) |
|
locate-Find Files the Easy Way |
|
|
196 | (1) |
|
find-Find Files the Hard Way |
|
|
197 | (11) |
|
|
198 | (2) |
|
|
200 | (2) |
|
|
202 | (2) |
|
|
204 | (1) |
|
|
204 | (1) |
|
|
205 | (1) |
|
A Return to the Playground |
|
|
206 | (2) |
|
|
208 | (1) |
|
|
208 | (1) |
|
|
209 | (16) |
|
|
210 | (3) |
|
|
210 | (2) |
|
|
212 | (1) |
|
|
213 | (6) |
|
|
213 | (4) |
|
|
217 | (2) |
|
Synchronizing Files and Directories |
|
|
219 | (4) |
|
Using rsync over a Network |
|
|
222 | (1) |
|
|
223 | (2) |
|
|
225 | (20) |
|
What Are Regular Expressions? |
|
|
226 | (1) |
|
|
226 | (1) |
|
Metacharacters and Literals |
|
|
227 | (1) |
|
|
228 | (1) |
|
|
228 | (2) |
|
Bracket Expressions and Character Classes |
|
|
230 | (1) |
|
|
230 | (1) |
|
Traditional Character Ranges |
|
|
230 | (1) |
|
|
231 | (3) |
|
POSIX Basic vs. Extended Regular Expressions |
|
|
234 | (1) |
|
|
235 | (1) |
|
|
236 | (3) |
|
?-Match an Element Zero or One Time |
|
|
236 | (1) |
|
-Match an Element Zero or More Times |
|
|
237 | (1) |
|
+-Match an Element One or More Times |
|
|
238 | (1) |
|
{ }-Match an Element a Specific Number of Times |
|
|
238 | (1) |
|
Putting Regular Expressions to Work |
|
|
239 | (3) |
|
Validating a Phone List with grep |
|
|
239 | (1) |
|
Finding Ugly Filenames with find |
|
|
240 | (1) |
|
Searching for Files with locate |
|
|
241 | (1) |
|
Searching for Text with less and vim |
|
|
241 | (1) |
|
|
242 | (3) |
|
|
245 | (34) |
|
|
246 | (1) |
|
|
246 | (1) |
|
|
246 | (1) |
|
|
246 | (1) |
|
|
246 | (1) |
|
|
247 | (1) |
|
Revisiting Some Old Friends |
|
|
247 | (9) |
|
|
247 | (1) |
|
|
248 | (6) |
|
|
254 | (2) |
|
|
256 | (6) |
|
cut-Remove Sections from Each Line of Files |
|
|
256 | (2) |
|
paste-Merge Lines of Files |
|
|
258 | (2) |
|
join-Join Lines of Two Files on a Common Field |
|
|
260 | (2) |
|
|
262 | (4) |
|
comm-Compare Two Sorted Files Line by Line |
|
|
262 | (1) |
|
diff-Compare Files Line by Line |
|
|
263 | (2) |
|
patch-Apply a diff to an Original |
|
|
265 | (1) |
|
|
266 | (12) |
|
tr-Transliterate or Delete Characters |
|
|
266 | (2) |
|
sed-Stream Editor for Filtering and Transforming Text |
|
|
268 | (7) |
|
aspell-Interactive Spellchecker |
|
|
275 | (3) |
|
|
278 | (1) |
|
|
278 | (1) |
|
|
279 | (18) |
|
|
280 | (10) |
|
|
280 | (2) |
|
fold-Wrap Each Line to a Specified Length |
|
|
282 | (1) |
|
fmt-A Simple Text Formatter |
|
|
283 | (3) |
|
pr-Format Text for Printing |
|
|
286 | (1) |
|
printf-Format and Print Data |
|
|
287 | (3) |
|
Document Formatting Systems |
|
|
290 | (5) |
|
|
290 | (5) |
|
|
295 | (2) |
|
|
297 | (12) |
|
A Brief History of Printing |
|
|
298 | (2) |
|
Printing in the Dim Times |
|
|
298 | (1) |
|
|
298 | (1) |
|
|
299 | (1) |
|
|
300 | (1) |
|
Preparing Files for Printing |
|
|
300 | (1) |
|
pr-Convert Text Files for Printing |
|
|
300 | (1) |
|
Sending a Print Job to a Printer |
|
|
301 | (4) |
|
lpr-Print Files (Berkeley Style) |
|
|
302 | (1) |
|
lp-Print Files (System V Style) |
|
|
302 | (1) |
|
|
303 | (2) |
|
Monitoring and Controlling Print Jobs |
|
|
305 | (2) |
|
lpstat-Display Print System Status |
|
|
306 | (1) |
|
lpq-Display Printer Queue Status |
|
|
306 | (1) |
|
lprm/cancel-Cancel Print Jobs |
|
|
307 | (1) |
|
|
307 | (2) |
|
|
309 | (14) |
|
|
310 | (1) |
|
Are All Programs Compiled? |
|
|
311 | (1) |
|
|
311 | (8) |
|
Obtaining the Source Code |
|
|
312 | (2) |
|
Examining the Source Tree |
|
|
314 | (1) |
|
|
315 | (3) |
|
|
318 | (1) |
|
|
319 | (4) |
Part IV: Writing Shell Scripts |
|
|
24 Writing Your First Script |
|
|
323 | (6) |
|
|
323 | (1) |
|
How to Write a Shell Script |
|
|
324 | (3) |
|
|
324 | (1) |
|
|
325 | (1) |
|
|
325 | (1) |
|
Good Locations for Scripts |
|
|
326 | (1) |
|
|
327 | (1) |
|
|
327 | (1) |
|
Indentation and Line Continuation |
|
|
327 | (1) |
|
|
328 | (1) |
|
|
329 | (10) |
|
First Stage: Minimal Document |
|
|
330 | (1) |
|
Second Stage: Adding a Little Data |
|
|
331 | (1) |
|
|
332 | (4) |
|
Assigning Values to Variables and Constants |
|
|
334 | (2) |
|
|
336 | (2) |
|
|
338 | (1) |
|
|
339 | (10) |
|
|
340 | (3) |
|
|
343 | (1) |
|
|
344 | (3) |
|
|
347 | (2) |
|
27 Flow Control: Branching With If |
|
|
349 | (14) |
|
|
350 | (1) |
|
|
350 | (2) |
|
|
352 | (5) |
|
|
352 | (2) |
|
|
354 | (2) |
|
|
356 | (1) |
|
A More Modern Version of test |
|
|
357 | (1) |
|
(( ))-Designed for Integers |
|
|
358 | (1) |
|
|
359 | (2) |
|
Control Operators: Another Way to Branch |
|
|
361 | (1) |
|
|
362 | (1) |
|
28 Reading Keyboard Input |
|
|
363 | (12) |
|
read-Read Values from Standard Input |
|
|
364 | (6) |
|
|
366 | (2) |
|
|
368 | (2) |
|
|
370 | (2) |
|
|
372 | (1) |
|
|
373 | (1) |
|
|
373 | (2) |
|
29 Flow Control: Looping With While/Until |
|
|
375 | (8) |
|
|
376 | (2) |
|
|
376 | (2) |
|
|
378 | (2) |
|
|
379 | (1) |
|
|
380 | (1) |
|
|
381 | (2) |
|
|
383 | (12) |
|
|
383 | (4) |
|
|
384 | (1) |
|
Missing or Unexpected Tokens |
|
|
385 | (1) |
|
|
386 | (1) |
|
|
387 | (3) |
|
|
387 | (1) |
|
|
388 | (1) |
|
|
389 | (1) |
|
|
390 | (1) |
|
|
391 | (1) |
|
|
391 | (3) |
|
|
391 | (1) |
|
|
392 | (2) |
|
Examining Values During Execution |
|
|
394 | (1) |
|
|
394 | (1) |
|
31 Flow Control: Branching With Case |
|
|
395 | (6) |
|
|
396 | (4) |
|
|
397 | (2) |
|
Performing Multiple Actions |
|
|
399 | (1) |
|
|
400 | (1) |
|
|
401 | (12) |
|
Accessing the Command Line |
|
|
401 | (4) |
|
Determining the Number of Arguments |
|
|
402 | (1) |
|
shift-Getting Access to Many Arguments |
|
|
403 | (1) |
|
|
404 | (1) |
|
Using Positional Parameters with Shell Functions |
|
|
405 | (1) |
|
Handling Positional Parameters en Masse |
|
|
405 | (2) |
|
A More Complete Application |
|
|
407 | (3) |
|
|
410 | (3) |
|
33 Flow Control: Looping With For |
|
|
413 | (6) |
|
for: Traditional Shell Form |
|
|
413 | (3) |
|
|
416 | (1) |
|
|
417 | (2) |
|
|
419 | (18) |
|
|
419 | (8) |
|
|
420 | (1) |
|
Expansions to Manage Empty Variables |
|
|
420 | (2) |
|
Expansions That Return Variable Names |
|
|
422 | (1) |
|
|
422 | (3) |
|
|
425 | (2) |
|
Arithmetic Evaluation and Expansion |
|
|
427 | (7) |
|
|
427 | (1) |
|
|
428 | (1) |
|
|
428 | (1) |
|
|
429 | (2) |
|
|
431 | (1) |
|
|
432 | (2) |
|
bc-An Arbitrary Precision Calculator Language |
|
|
434 | (2) |
|
|
434 | (1) |
|
|
435 | (1) |
|
|
436 | (1) |
|
|
436 | (1) |
|
|
437 | (10) |
|
|
437 | (1) |
|
|
438 | (1) |
|
Assigning Values to an Array |
|
|
438 | (1) |
|
|
439 | (2) |
|
|
441 | (3) |
|
Outputting the Entire Contents of an Array |
|
|
441 | (1) |
|
Determining the Number of Array Elements |
|
|
441 | (1) |
|
Finding the Subscripts Used by an Array |
|
|
442 | (1) |
|
Adding Elements to the End of an Array |
|
|
442 | (1) |
|
|
443 | (1) |
|
|
443 | (1) |
|
|
444 | (1) |
|
|
444 | (3) |
|
|
447 | (12) |
|
Group Commands and Subshells |
|
|
447 | (6) |
|
|
451 | (2) |
|
|
453 | (3) |
|
Asynchronous Execution with wait |
|
|
456 | (1) |
|
|
457 | (1) |
|
|
458 | (1) |
|
|
458 | (1) |
|
|
458 | (1) |
Index |
|
459 | |