Tutorial de Linux en inglés
LINUX: Rute User’s Tutorial and Exposition Paul Sheer August 14, 2001 Pages up to and including this page are not included by Prentice Hall.
“The reason we don’t sell billions and billions of Guides,” continued Harl,
after wiping his mouth, “is the expense. What we do is we sell one Guide billions
and billions of times. We exploit the multidimensional nature of the Universe to
cut down on manufacturing costs. And we don’t sell to penniless hitchhikers.
What a stupid notion that was! Find the one section of the market that, more or
less by definition, doesn’t have any money, and try to sell to it. No. We sell to
the affluent business traveler and his vacationing wife in a billion, billion different
futures. This is the most radical, dynamic and thrusting business venture in the
entire multidimensional infinity of space-time-probability ever.” . . .Ford was completely at a loss for what to do next.
“Look,” he said in a stern voice. But he wasn’t certain how far saying things
like “Look” in a stern voice was necessarily going to get him, and time was not on
his side. What the hell, he thought, you’re only young once, and threw himself out
of the window. That would at least keep the element of surprise on his side.. . . In a spirit of scientific inquiry he hurled himself out of the window again.
Douglas Adams
Mostly Harmless
Strangely, the thing that least intrigued me was how they’d managed to get it
all done. I suppose I sort of knew. If I’d learned one thing from traveling, it was
that the way to get things done was to go ahead and do them. Don’t talk about
going to Borneo. Book a ticket, get a visa, pack a bag, and it just happens.Alex Garland
The Beach
Chapter Summary 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14 Permission and Modification Times . . . . . . . . . . . . . . . . . . . . . 123
25 Introduction to IP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
24 Source and Binary Packages . . . . . . . . . . . . . . . . . . . . . . . . . 237
23 Shared Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
22 Trivial Introduction to C . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
21 System Services and lpd . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
. . . . . . . . . . . . . . . . . . . . . . . . . . . 171
20 Advanced Shell Scripting
. . . . . . . . . . . . . . 153
19 Partitions, File Systems, Formatting, Mounting
18 U NIX Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
17 Overview of the U NIX Directory Layout . . . . . . . . . . . . . . . . . . 135
16 Pre-installed Documentation . . . . . . . . . . . . . . . . . . . . . . . . . 131
15 Symbolic and Hard Links . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
INUX Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
1 2 Computing Sub-basics . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13 L
12 Using Internet Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
11 User Accounts and Ownerships . . . . . . . . . . . . . . . . . . . . . . . 101
97
81 10 Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
73 9 Processes, Environment Variables . . . . . . . . . . . . . . . . . . . . . .
61 8 Streams and sed — The Stream Editor . . . . . . . . . . . . . . . . . . .
53 7 Shell Scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
49 6 Editing Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25 5 Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4 Basic Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15
5 3 PC Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
26 TCP and UDP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Chapter Summary
39 smbd
INUX Advocacy FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551 E The GNU General Public License Version 2 . . . . . . . . . . . . . . . . 573
B LPI Certification Cross-Reference . . . . . . . . . . . . . . . . . . . . . . 531 C RHCE Certification Cross-Reference . . . . . . . . . . . . . . . . . . . . 543 D L
44 U NIX Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511 A Lecture Schedule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
43 The X Window System . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
INUX Kernel Source, Modules, and Hardware Support . . . . . . 463
42 The L
41 Point-to-Point Protocol — Dialup Networking . . . . . . . . . . . . . . 453
— Domain Name Server . . . . . . . . . . . . . . . . . . . . . . . 437
40 named
— Samba NT Server . . . . . . . . . . . . . . . . . . . . . . . . . . 425
INUX File System Standard . . . . . . . . . . . . . . . . . . . . . . 347 36 httpd — Apache Web Server . . . . . . . . . . . . . . . . . . . . . . . . 389 37 crond and atd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409 38 postgres SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
27 DNS and Name Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . 273
35 The L
34 uucp and uux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
33 Sending Faxes
, ?getty, and U NIX Run Levels . . . . . . . . . . . . . . . . . . . . 325
32 init
, initrd, and Booting . . . . . . . . . . . . . . . . . . . . . . . . . 317
31 lilo
30 exim and sendmail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
29 Services Running Under inetd . . . . . . . . . . . . . . . . . . . . . . . 291
28 Network File System, NFS . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Index 581
Contents Acknowledgments xxxi
7 2.3 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15 3.2 Master/Slave IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 PC Hardware 15 3.1 Motherboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
12 2.10 Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12 2.9 Allowable Characters for File Names . . . . . . . . . . . . . . . . . . . .
11 2.8 Creating Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10 2.7 Console Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10 2.6 Command-Line Editing Keys . . . . . . . . . . . . . . . . . . . . . . . . .
9 2.5 Listing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8 2.4 Login and Password Change . . . . . . . . . . . . . . . . . . . . . . . . .
5 2.2 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1 Introduction 1 1.1 What This Book Covers . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2 Computing Sub-basics 5 2.1 Binary, Octal, Decimal, and Hexadecimal . . . . . . . . . . . . . . . . . .
3
3 1.8 Updates and Errata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2 1.7 Not RedHat: RedHat-like . . . . . . . . . . . . . . . . . . . . . . . . . . .
2 1.6 LPI and RHCE Requirements . . . . . . . . . . . . . . . . . . . . . . . . .
NIX Documentation That I Don’t Understand . .
1.5 I Get Frustrated with U
2
1 1.4 More About This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1 1.3 What Do I Need to Get Started? . . . . . . . . . . . . . . . . . . . . . . .
1 1.2 Read This Next. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19 Contents 3.3 CMOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
20 3.4 Serial Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
40 4.12 Terminating Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . .
52 5.5 Regular Expression Subexpressions . . . . . . . . . . . . . . . . . . . . .
51 5.4 + ? \< \> ( ) | Notation . . . . . . . . . . . . . . . . . . . . . . . . . . .
51 5.3 Regular Expression \{ \} Notation . . . . . . . . . . . . . . . . . . . . .
49 5.2 The fgrep Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5 Regular Expressions 49 5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
47
46 4.19 The -- Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
45 4.18 The PATH Where Commands Are Searched For . . . . . . . . . . . . . .
44 4.17 Archives and Backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
43 4.16 Copying to MS-DOS and Windows Formatted Floppy Disks . . . . . . .
42 4.15 Searching Within Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
41 4.14 Searching for Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
41 4.13 Compressed Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
40 4.11 Multimedia Commands for Fun . . . . . . . . . . . . . . . . . . . . . . .
20 3.5 Modems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
36 4.10 The mc File Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
36 4.9 Some Basic Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . .
35 4.8 System info Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
34 4.7 System Manual Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
34 4.6 Relative vs. Absolute Pathnames . . . . . . . . . . . . . . . . . . . . . . . .
33 4.5 Directory Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . .
32 4.4 Usage Summaries and the Copy Command . . . . . . . . . . . . . . . . .
29 4.3.2 Glob expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . .
29 4.3.1 File naming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
26 4.3 Wildcards, Names, Extensions, and glob Expressions . . . . . . . . . . .
25 4.2 Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4 Basic Commands 25 4.1 The ls Command, Hidden Files, Command-Line Options . . . . . . . .
23
52 Contents
6 Editing Text Files
74 8.4 A Complex Piping Example . . . . . . . . . . . . . . . . . . . . . . . . . .
70 7.11 Double-Quote Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . .
70 7.12 Backward-Quote Substitution . . . . . . . . . . . . . . . . . . . . . . . . .
71
8 Streams and sed — The Stream Editor
73 8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
73 8.2 Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
74 8.3 Piping Using | Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . .
75 8.5 Redirecting Streams with >& . . . . . . . . . . . . . . . . . . . . . . . . .
68 7.9 More on Command-Line Arguments: $@ and $0 . . . . . . . . . . . . . .
75 8.6 Using sed to Edit Streams . . . . . . . . . . . . . . . . . . . . . . . . . . .
77 8.7 Regular Expression Subexpressions . . . . . . . . . . . . . . . . . . . . .
77 8.8 Inserting and Deleting Lines . . . . . . . . . . . . . . . . . . . . . . . . .
79
9 Processes, Environment Variables
81 9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
81 9.2 ps — List Running Processes . . . . . . . . . . . . . . . . . . . . . . . . .
82 9.3 Controlling Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
70 7.10 Single Forward Quote Notation . . . . . . . . . . . . . . . . . . . . . . . .
67 7.8 Properly Processing Command-Line Args: shift . . . . . . . . . . . . .
53
vi and vim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.1
vi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
53 6.2 Syntax Highlighting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
57 6.3 Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
57 6.3.1 Cooledit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
58
6.3.2
58 6.3.3 Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
66 7.7 Using Functions: the function Keyword . . . . . . . . . . . . . . . . .
59 6.3.4 Other editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
59
7 Shell Scripting 61 7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
61 7.2 Looping: the while and until Statements . . . . . . . . . . . . . . . . .
62 7.3 Looping: the for Statement . . . . . . . . . . . . . . . . . . . . . . . . . .
63 7.4 break ing Out of Loops and continueing . . . . . . . . . . . . . . . . .
65 7.5 Looping Over Glob Expressions . . . . . . . . . . . . . . . . . . . . . . .
66 7.6 The case Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
82 Contents 9.4 Creating Background Processes . . . . . . . . . . . . . . . . . . . . . . . .
83 9.5 kill ing a Process, Sending Signals . . . . . . . . . . . . . . . . . . . . .
84 9.6 List of Common Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . .
86 9.7 Niceness of Processes, Scheduling Priority . . . . . . . . . . . . . . . . .
87 9.8 Process CPU/Memory Consumption, top . . . . . . . . . . . . . . . . .
88 9.9 Environments of Processes . . . . . . . . . . . . . . . . . . . . . . . . . .
90
10 Mail 97 10.1 Sending and Reading Mail . . . . . . . . . . . . . . . . . . . . . . . . . .
99 10.2 The SMTP Protocol — Sending Mail Raw to Port 25 . . . . . . . . . . . .
99
11 User Accounts and Ownerships 101
11.1 File Ownerships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
11.2 The Password File /etc/passwd . . . . . . . . . . . . . . . . . . . . . . 102
11.3 Shadow Password File: /etc/shadow . . . . . . . . . . . . . . . . . . . 103
11.4 The groups Command and /etc/group . . . . . . . . . . . . . . . . . 104
11.5 Manually Creating a User Account . . . . . . . . . . . . . . . . . . . . . . 105
11.6 Automatically: useradd and groupadd . . . . . . . . . . . . . . . . . . 106
11.7 User Logins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
11.7.1 The login command . . . . . . . . . . . . . . . . . . . . . . . . . 106
11.7.2 The set user, su command . . . . . . . . . . . . . . . . . . . . . . . 107
11.7.3 The who, w, and users commands to see who is logged in . . . . 108
11.7.4 The id command and effective UID . . . . . . . . . . . . . . . . . 109
11.7.5 User limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
12 Using Internet Services 111
12.1 ssh, not telnet or rlogin . . . . . . . . . . . . . . . . . . . . . . . . . 111 12.2 rcp and scp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 12.3 rsh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
12.4 FTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 12.5 finger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
12.6 Sending Files by Email . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 12.6.1 uuencode and uudecode . . . . . . . . . . . . . . . . . . . . . . 114
12.6.2 MIME encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Contents
INUX
13 L Resources 117
13.1 FTP Sites and the sunsite Mirror . . . . . . . . . . . . . . . . . . . . . . 117
13.2 HTTP — Web Sites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
13.3 SourceForge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
13.4 Mailing Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
13.4.1 Majordomo and Listserv . . . . . . . . . . . . . . . . . . . . . . . 119 13.4.2 *-request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
13.5 Newsgroups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
13.6 RFCs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
14 Permission and Modification Times 123
14.1 The chmod Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
14.2 The umask Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
14.3 Modification Times: stat . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
15 Symbolic and Hard Links 127
15.1 Soft Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
15.2 Hard Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
16 Pre-installed Documentation 131
17 Overview of the U NIX Directory Layout 135
17.1 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
17.2 U NIX Directory Superstructure . . . . . . . . . . . . . . . . . . . . . . . . 136
17.3 L
INUX on a Single Floppy Disk . . . . . . . . . . . . . . . . . . . . . . . . 138
18 U NIX Devices 141
18.1 Device Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
18.2 Block and Character Devices . . . . . . . . . . . . . . . . . . . . . . . . . 142
18.3 Major and Minor Device Numbers . . . . . . . . . . . . . . . . . . . . . . 143
18.4 Common Device Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 18.5 dd, tar, and Tricks with Block Devices . . . . . . . . . . . . . . . . . . . 147
18.5.1 Creating boot disks from boot images . . . . . . . . . . . . . . . . 147
18.5.2 Erasing disks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
18.5.3 Identifying data on raw disks . . . . . . . . . . . . . . . . . . . . . 148
18.5.4 Duplicating a disk . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
18.5.5 Backing up to floppies . . . . . . . . . . . . . . . . . . . . . . . . . 149
Contents
18.5.6 Tape backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
18.5.7 Hiding program output, creating blocks of zeros . . . . . . . . . 149
18.6 Creating Devices with mknod and /dev/MAKEDEV . . . . . . . . . . . . 150
19 Partitions, File Systems, Formatting, Mounting 153
19.1 The Physical Disk Structure . . . . . . . . . . . . . . . . . . . . . . . . . . 153
19.1.1 Cylinders, heads, and sectors . . . . . . . . . . . . . . . . . . . . . 153
19.1.2 Large Block Addressing . . . . . . . . . . . . . . . . . . . . . . . . 154
19.1.3 Extended partitions . . . . . . . . . . . . . . . . . . . . . . . . . . 154
19.2 Partitioning a New Disk . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
19.3 Formatting Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
19.3.1 File systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 19.3.2 mke2fs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
19.3.3 Formatting floppies and removable drives . . . . . . . . . . . . . 161
19.3.4 Creating MS-DOS floppies . . . . . . . . . . . . . . . . . . . . . . 162 19.3.5 mkswap, swapon, and swapoff . . . . . . . . . . . . . . . . . . . 162
19.4 Device Mounting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
19.4.1 Mounting CD-ROMs . . . . . . . . . . . . . . . . . . . . . . . . . 163
19.4.2 Mounting floppy disks . . . . . . . . . . . . . . . . . . . . . . . . 164
19.4.3 Mounting Windows and NT partitions . . . . . . . . . . . . . . . 164
19.5 File System Repair: fsck . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
19.6 File System Errors on Boot . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
19.7 Automatic Mounts: fstab . . . . . . . . . . . . . . . . . . . . . . . . . . 166
19.8 Manually Mounting /proc . . . . . . . . . . . . . . . . . . . . . . . . . . 167
19.9 RAM and Loopback Devices . . . . . . . . . . . . . . . . . . . . . . . . . 167
19.9.1 Formatting a floppy inside a file . . . . . . . . . . . . . . . . . . . 167
19.9.2 CD-ROM files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
19.10 Remounting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
19.11 Disk sync . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
20 Advanced Shell Scripting 171
20.1 Lists of Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
20.2 Special Parameters: $?, $*,. . . . . . . . . . . . . . . . . . . . . . . . . . . 172
20.3 Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
20.4 Built-in Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
20.5 Trapping Signals — the trap Command . . . . . . . . . . . . . . . . . . 176
Contents
20.9.4 Locking inside C programs . . . . . . . . . . . . . . . . . . . . . . 191
21.4.9 Log file rotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
21.4.8 Log files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
21.4.7 Spool files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
21.4.6 Service initialization files . . . . . . . . . . . . . . . . . . . . . . . 196
21.4.5 Configuration files . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
21.4.4 Daemon and administrator programs . . . . . . . . . . . . . . . . 196
21.4.3 User programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
21.4.2 Web pages, mailing lists, and download points . . . . . . . . . . 195
21.4.1 Documentation files . . . . . . . . . . . . . . . . . . . . . . . . . . 195
21.4 Package Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
21.3 LPRng vs. Legacy lpr-0.nn . . . . . . . . . . . . . . . . . . . . . . . . . 195
21.2 Downloading and Installing . . . . . . . . . . . . . . . . . . . . . . . . . . 194
21.1 Using lpr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
193
20.9.3 Directory versus file locking . . . . . . . . . . . . . . . . . . . . . 190
20.6 Internal Settings — the set Command . . . . . . . . . . . . . . . . . . . 177
20.9.2 Locking over NFS . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
20.9.1 Locking a mailbox file . . . . . . . . . . . . . . . . . . . . . . . . . 188
20.9 File Locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
20.8.1 Customizing the PATH and LD LIBRARY PATH . . . . . . . . . . 187
20.8 Shell Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
20.7.12 Processing the process list . . . . . . . . . . . . . . . . . . . . . . . 185
20.7.11 Persistent background processes . . . . . . . . . . . . . . . . . . . 184
20.7.10 Securely erasing files . . . . . . . . . . . . . . . . . . . . . . . . . . 184
20.7.9 Conversion of graphics formats of many files . . . . . . . . . . . 183
20.7.8 Calculations with bc . . . . . . . . . . . . . . . . . . . . . . . . . . 183
20.7.6 Recursive search and replace . . . . . . . . . . . . . . . . . . . . . 181 20.7.7 cut and awk — manipulating text file fields . . . . . . . . . . . . 182
20.7.5 Recursive grep (search) . . . . . . . . . . . . . . . . . . . . . . . . 180
20.7.4 Internet connectivity test . . . . . . . . . . . . . . . . . . . . . . . 180
20.7 Useful Scripts and Commands . . . . . . . . . . . . . . . . . . . . . . . . 178 20.7.1 chroot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 20.7.2 if conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 20.7.3 patching and diffing . . . . . . . . . . . . . . . . . . . . . . . . 179
21 System Services and lpd
Contents
21.4.10 Environment variables . . . . . . . . . . . . . . . . . . . . . . . . 199
21.5 The printcap File in Detail . . . . . . . . . . . . . . . . . . . . . . . . . 199
21.6 PostScript and the Print Filter . . . . . . . . . . . . . . . . . . . . . . . . . 200
21.7 Access Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
21.8 Printing Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
21.9 Useful Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 21.9.1 printtool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 21.9.2 apsfilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 21.9.3 mpage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 21.9.4 psutils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
21.10 Printing to Things Besides Printers . . . . . . . . . . . . . . . . . . . . . . 205
22 Trivial Introduction to C
22.1 C Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
22.1.11 C comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 22.1.12 #define and #if — C macros . . . . . . . . . . . . . . . . . . . 222
22.4.2 Putting it all together . . . . . . . . . . . . . . . . . . . . . . . . . 231
22.4.1 Completing our example Makefile . . . . . . . . . . . . . . . . 231
22.4 C Projects — Makefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
22.3 C Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
22.2.2 Examining core files . . . . . . . . . . . . . . . . . . . . . . . . . 227 22.2.3 strace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
22.2 Debugging with gdb and strace . . . . . . . . . . . . . . . . . . . . . . 223 22.2.1 gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
22.1.9 A more complicated example . . . . . . . . . . . . . . . . . . . . . 218 22.1.10 #include statements and prototypes . . . . . . . . . . . . . . . . 220
22.1.1 The simplest C program . . . . . . . . . . . . . . . . . . . . . . . . 208
22.1.8 Reading command-line arguments inside C programs . . . . . . 218
22.1.7 File operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
22.1.6 String operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
207
22.1.3 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 22.1.4 for, while, if, and switch statements . . . . . . . . . . . . . . 211
22.1.2 Variables and types . . . . . . . . . . . . . . . . . . . . . . . . . . 209
22.1.5 Strings, arrays, and memory allocation . . . . . . . . . . . . . . . 213 Contents
23 Shared Libraries 233
23.1 Creating DLL .so Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
23.2 DLL Versioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
23.3 Installing DLL .so Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
24 Source and Binary Packages 237
24.1 Building GNU Source Packages . . . . . . . . . . . . . . . . . . . . . . . . 237
24.2 RedHat and Debian Binary Packages . . . . . . . . . . . . . . . . . . . . 240
24.2.1 Package versioning . . . . . . . . . . . . . . . . . . . . . . . . . . 240
24.2.2 Installing, upgrading, and deleting . . . . . . . . . . . . . . . . . 240
24.2.3 Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
24.2.4 Package queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
24.2.5 File lists and file queries . . . . . . . . . . . . . . . . . . . . . . . . 242
24.2.6 Package verification . . . . . . . . . . . . . . . . . . . . . . . . . . 243
24.2.7 Special queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 24.2.8 dpkg/apt versus rpm . . . . . . . . . . . . . . . . . . . . . . . . . 245
24.3 Source Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
25 Introduction to IP 247
25.1 Internet Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
25.2 Special IP Addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
25.3 Network Masks and Addresses . . . . . . . . . . . . . . . . . . . . . . . . 250
25.4 Computers on a LAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
25.5 Configuring Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
25.6 Configuring Routing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
25.7 Configuring Startup Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . 254
25.7.1 RedHat networking scripts . . . . . . . . . . . . . . . . . . . . . . 254
25.7.2 Debian networking scripts . . . . . . . . . . . . . . . . . . . . . . 255
25.8 Complex Routing — a Many-Hop Example . . . . . . . . . . . . . . . . . 256
25.9 Interface Aliasing — Many IPs on One Physical Card . . . . . . . . . . . 259
25.10 Diagnostic Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 25.10.1 ping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 25.10.2 traceroute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 25.10.3 tcpdump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Contents
28 Network File System, NFS 285
29.4 The xinetd Alternative . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
29.3 Various Service Explanations . . . . . . . . . . . . . . . . . . . . . . . . . 294
29.2.4 Distribution conventions . . . . . . . . . . . . . . . . . . . . . . . 294
29.2.3 Invoking an inetd “TCP wrapper” service . . . . . . . . . . . . 293
29.2.2 Invoking an inetd service . . . . . . . . . . . . . . . . . . . . . . 292
29.2.1 Invoking a standalone service . . . . . . . . . . . . . . . . . . . . 292
29.2 Invoking Services with /etc/inetd.conf . . . . . . . . . . . . . . . . 291
29.1 The inetd Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
29 Services Running Under inetd 291
28.5 Kernel NFS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
28.4 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
28.3 Access Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
28.2 Configuration Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
28.1 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
27.8 The dig Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
26 TCP and UDP 263
27.2 Resolving DNS Names to IP Addresses . . . . . . . . . . . . . . . . . . . 274
26.1 The TCP Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
26.2 A Sample TCP Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
26.3 User Datagram Protocol (UDP) . . . . . . . . . . . . . . . . . . . . . . . . 268 26.4 /etc/services File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
26.5 Encrypting and Forwarding TCP . . . . . . . . . . . . . . . . . . . . . . . 270
27 DNS and Name Resolution 273
27.1 Top-Level Domains (TLDs) . . . . . . . . . . . . . . . . . . . . . . . . . . 273
27.2.1 The Internet DNS infrastructure . . . . . . . . . . . . . . . . . . . 275
27.7.1 NS, MX, PTR, A and CNAME records . . . . . . . . . . . . . . . . . . 283
27.2.2 The name resolution process . . . . . . . . . . . . . . . . . . . . . 276
27.3 Configuring Your Local Machine . . . . . . . . . . . . . . . . . . . . . . . 277
27.4 Reverse Lookups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
27.5 Authoritative for a Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
27.6 The host, ping, and whois Command . . . . . . . . . . . . . . . . . . . 281
27.7 The nslookup Command . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
29.5 Configuration Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
Contents
29.5.1 Limiting access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
29.6 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
30 exim and sendmail 299
30.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
30.1.1 How mail works . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
30.1.2 Configuring a POP/IMAP server . . . . . . . . . . . . . . . . . . 301
30.1.3 Why exim? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 30.2 exim Package Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 30.3 exim Configuration File . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
30.3.1 Global settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
30.3.2 Transports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
30.3.3 Directors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
30.3.4 Routers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
30.4 Full-blown Mail server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
30.5 Shell Commands for exim Administration . . . . . . . . . . . . . . . . . 308
30.6 The Queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 30.7 /etc/aliases for Equivalent Addresses . . . . . . . . . . . . . . . . . 310
30.8 Real-Time Blocking List — Combating Spam . . . . . . . . . . . . . . . . 311
30.8.1 What is spam? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
30.8.2 Basic spam prevention . . . . . . . . . . . . . . . . . . . . . . . . . 312
30.8.3 Real-time blocking list . . . . . . . . . . . . . . . . . . . . . . . . . 313
30.8.4 Mail administrator and user responsibilities . . . . . . . . . . . . 313
30.9 Sendmail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
31 lilo, initrd, and Booting 317
31.1 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
31.2 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
31.2.1 Kernel boot sequence . . . . . . . . . . . . . . . . . . . . . . . . . 318
31.2.2 Master boot record . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
31.2.3 Booting partitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
31.2.4 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 31.3 lilo.conf and the lilo Command . . . . . . . . . . . . . . . . . . . . 319
31.4 Creating Boot Floppy Disks . . . . . . . . . . . . . . . . . . . . . . . . . . 321
31.5 SCSI Installation Complications and initrd . . . . . . . . . . . . . . . . 322
31.6 Creating an initrd Image . . . . . . . . . . . . . . . . . . . . . . . . . . 322
31.7 Modifying lilo.conf for initrd . . . . . . . . . . . . . . . . . . . . . 324
31.8 Using mkinitrd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Contents NIX
32 init, ?getty, and U Run Levels 325
32.1 init — the First Process . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 32.2 /etc/inittab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
32.2.1 Minimal configuration . . . . . . . . . . . . . . . . . . . . . . . . . 326
32.2.2 Rereading inittab . . . . . . . . . . . . . . . . . . . . . . . . . . 328
32.2.3 The respawning too fast error . . . . . . . . . . . . . . . . . 328
32.3 Useful Run Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 32.4 getty Invocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
32.5 Bootup Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
32.6 Incoming Faxes and Modem Logins . . . . . . . . . . . . . . . . . . . . . 330 32.6.1 mgetty with character terminals . . . . . . . . . . . . . . . . . . 330 32.6.2 mgetty log files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330 32.6.3 mgetty with modems . . . . . . . . . . . . . . . . . . . . . . . . . 330 32.6.4 mgetty receiving faxes . . . . . . . . . . . . . . . . . . . . . . . . 331
33 Sending Faxes 333
33.1 Fax Through Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
33.2 Setgid Wrapper Binary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
34 uucp and uux 337
34.1 Command-Line Operation . . . . . . . . . . . . . . . . . . . . . . . . . . 338
34.2 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
34.3 Modem Dial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 34.4 tty/UUCP Lock Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
34.5 Debugging uucp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
34.6 Using uux with exim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
34.7 Scheduling Dialouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
INUX
35 The L File System Standard 347
35.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
35.1.1 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
35.1.2 Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
35.2 The Filesystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
35.3 The Root Filesystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
35.3.1 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
35.3.2 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
35.3.3 Specific Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352 Contents
35.3.4 /bin : Essential user command binaries (for use by all users) . . 353 35.3.5 /boot : Static files of the boot loader . . . . . . . . . . . . . . . . . 354 35.3.6 /dev : Device files . . . . . . . . . . . . . . . . . . . . . . . . . . . 355 35.3.7 /etc : Host-specific system configuration . . . . . . . . . . . . . . 355 35.3.8 /home : User home directories (optional) . . . . . . . . . . . . . . 358 35.3.9 /lib : Essential shared libraries and kernel modules . . . . . . . . 358 35.3.10 /lib<qual> : Alternate format essential shared libraries (optional) 359 35.3.11 /mnt : Mount point for a temporarily mounted filesystem . . . . 359 35.3.12 /opt : Add-on application software packages . . . . . . . . . . . 360 35.3.13 /root : Home directory for the root user (optional) . . . . . . . . 361 35.3.14 /sbin : System binaries . . . . . . . . . . . . . . . . . . . . . . . . 361 35.3.15 /tmp : Temporary files . . . . . . . . . . . . . . . . . . . . . . . . 362