大名鼎鼎的Brian W. Kernighan & Rob Pike合写的Unix编程环境一书,就不用多介绍了。非常经典。CONTENTSfa1. UNIX for Beginners1. 1 Getting started21.2 Day-to-day use: files and common commands111.3 More about files: directories1. 4 The shell261. 5 The rest of the UNIX system382. The File System2. 1 The basics of files412.2 What's in a file?462, 3 Directories and filenames482. 4 Permissions522.5 Inodes2.6 The directory hierarchy632.7 Devices3. Using the Shell3.1 Command line structure713.2 Metacharacters743.3 Creating new commands3.4 Command arguments and parameters3.5 Program output as arguments863.6 Shell variables883. 7 More on I/O redirection923.8 Looping in shell programs943.9 bundle: putting it all together973.10 Why a programmable shell?Filters1014. 1 The grep family1024.2 Other filters106CONTENTS4. 3 The stream editor sed1084.4 The awk pattern scanning and processing language1144. 5 Good files and good filters130Shell Programming1335. 1 Customizing the cal command1335.2 Which command is which?1385.3 while and until loops: watching for things1445.4 Traps: catching interrupts1505.5 Replacing a file: overwrite1525.6 zap: killing processes by name1565.7 The pick command: blanks vs arguments1595. 8 The news command: community service messages1625.9 get and put: tracking file changes1655. A look back1696. Programming with Standard IO1716. 1 Standard input and output: vis1726.2 Program arguments: vis version 21746. 3 File access: vis version 31766.4 A screen-at-a-time printer:p1806.5 An example: pick1866.6 On bugs and debugging1876. 7 An example: zap1906.8 An interactive file comparison program: idiff1926.9 Accessing the environment1997UNIX System Calls2017.1 Low-level I/O2017.2 File system: directories2083 File system: inodes2144 Processes2207.5 Signals and interrupts2258. Program Development2338.1 Stage 1: A four-function calculator2348.2 Stage 2: Variables and error recovery2428.3 Stage 3: Arbitrary variable names; built-in functions2458.4 Stage 4: Compilation into a machine2588.5 Stage 5: Control flow and relational operators2668.6 Stage 6: Functions and procedures; input/output2738. 7 Performance evaluation2848. 8 A look back2869. Document Preparation899. 1 The ms macro package2909.2 The troff level2979. 3 The tbl and eqn preprocessors3019. 4 The manual page3089.5 Other document preparation tools31310. Epilog315Appendix 1: Editor Summary319Appendix 2: hoc Manual329Appendix 3: hoc Listing335Ind349CONTENTS4.3 The stream editor sed1084. 4 The awk pattern scanning and processing language1144.5 Good files and good filters130Shell Programming1335.1 Customizing the cal command1335.2 Which command is which?1385.3 while and until loops: watching for things1445.4 Traps: catching interrupts1505.5 Replacing a file: overwrite1525.6 zap: killing processes by name1565.7 The pick command: blanks vs arguments1595. 8 The news command: community service messages1625.9 get and put: tracking file changes1655.10A look backProgramming with Standard I/O1716. 1 Standard input and output: vis1726.2 Program arguments: vis version 21746. 3 File access: vis version 31766. 4 A screen-at-a-time printer: p1806. 5 An example: pick1866.6 On bugs and debugging1876. 7 An example: zap1906. 8 An interactive file comparison program: idiff1926.9 Accessing the environment199UNIX SyStem Calls2017.1 Low-level 1/o2017. 2 File system: directories2087. 3 File system: inodes2147. 4 Processes2207.5 Signals and interrupts2258.Program Development2338. 1 Stage 1: A four-function calculator2348.2 Stage 2: Variables and error recovery2428.3 Stage 3: Arbitrary variable names; built-in functions2458.4 Stage 4: Compilation into a machine2588.5 Stage 5: Control flow and relational operators2668.6 Stage 6: Functions and procedures; input/output2738.7 Performance evaluation2848.8 A look back286CONTENTS9. Document Preparation2899. 1 The ms macro package2909.2 The troff level2979.3 The tbl and eqn preprocessors3019.4 The manual page3089. 5 Other document preparation tools31310. Epilog315Appendix 1: Editor Summary319Appendix 2: hoc Manual329Appendix 3: hoc Listing335Index349PREFACEThe number of UNIX installations has grown to 10, with more expected(The UNIX Programmer's Manual, 2nd Edition, June, 1972.)The uNiX operating system started on a cast-off DEC PDP-7 at Bell Laboratories in 1969. Ken Thompson, with ideas and support from Rudd Canaday,Doug Mcllroy, Joe Ossanna, and Dennis Ritchie, wrote a small general-purpose time-sharing system comfortable enough to attract enthusiastic usersand eventually enough credibility for the purchase of a larger machinePDP-11/20. One of the early users was Ritchie, who helped move the systemto the PDP-ll in 1970. Ritchie also designed and wrote a compiler for the cprogramming language. In 1973, Ritchie and Thompson rewrote the uniX ker-nel in C, breaking from the tradition that system software is written in assem-bly language. With that rewrite, the system became essentially what it istodayAround 1974 it was licensed to universities"for educational purposes""anda few years later became available for commercial use. During this time, UNIXsystems prospered at Bell Labs, finding their way into laboratories, softwaredevelopment projects, word processing centers, and operations support systemsin telephone companies. Since then, it has spread world-wide, with tens ofthousands of systems installed, from microcomputers to the largest mainframesWhat makes the UNIX System So successful? We can discern several reasons. First, because it is written in C, it is portable--UNIX Systems run on arange of computers from microprocessors to the largest mainframes; this is astrong commercial advantage. Second, the source code is available and writtenin a high-level language, which makes the system easy to adapt to particularrequirements. Finally, and most important, it is a good operating systemf UNIX is a trademark of Bell Laboratories. UNIX"is not an acronym, but a weak pun on mulTICS, the operating system that Thompson and Ritchie worked on before UNIXVIll PREFACEespecially for programmers. The UNIX programming environment is unusuallyrich and productivEven though the UNIX system introduces a number of innovative programsand techniques, no single program or idea makes it work well. Instead, whatmakes it effective is an approach to programming, a philosophy of using thecomputer. Although that philosophy can't be written down in a single sentence, at its heart is the idea that the power of a system comes more from therelationships among programs than from the programs themselves. Many UNIXprograms do quite trivial tasks in isolation, but, combined with other programs, become general and useful toolsOur goal in this book is to communicate the UNIX programming philosophyBecause the philosophy is based on the relationships between programs, wemust devote most of the space to discussions about the individual tools, butthroughout run the themes of combining programs and of using programs tobuild programs. To use the UNIX system and its components well, you mustunderstand not only how to use the programs, but also how they fit into theenvironmentAs the UNIX System has spread, the fraction of its users who are skilled inits application has decreased. Time and again, we have seen experiencedusers, ourselves included, find only clumsy solutions to a problem, or writeprograms to do jobs that existing tools handle easily. Of course, the elegantsolutions are not easy to see without some experience and understanding. Wehope that by reading this book you will develop the understanding to makeyour use of the system- whether you are a new or seasoned user -effectiveand enjoyable. We want you to use the UNIX System wellWe are aiming at individual programmers, in the hope that, by makingtheir work more productive, we can in turn make the work of groups moreproductive. Although our main target is programmers, the first four or fivechapters do not require programming experience to be understood, so theyshould be helpful to other users as well.Wherever possible we have tried to make our points with real examplesrather than artificial ones. Although some programs began as examples for thebook, they have since become part of our own set of everyday programs. Allexamples have been tested directly from the text, which is in machine-readableormhe book is organized as follows. Chapter 1 is an introduction to the mostbasic use of the system. It covers logging in, mail, the file system, commonly-used commands, and the rudiments of the command interpreter. Experiencedusers can skip this chapterChapter 2 is a discussion of the UNIX file system. The file system is centralto the operation and use of the system, so you must understand it to use thesystem well. This chapter describes files and directories, permissions and filemodes, and inodes. It concludes with a tour of the file system hierarchy andan explanation of device files