PacktHal.tgz
Android for BeagleBone Black书中例子的源代码
unix power tools
Table of Contents
1. Introduction....................................................................................................................................................2
1.1 What's Special About UNIX?............................................................................................................2
..............................................................................................................................................................................4
1.2 Who Listens to What You Type?.......................................................................................................4
..............................................................................................................................................................................6
1.3 Programs Are Designed to Work Together.......................................................................................6
..............................................................................................................................................................................7
1.4 Using Pipes to Create a New Tool.....................................................................................................7
..............................................................................................................................................................................9
1.5 Anyone Can Program the Shell..........................................................................................................9
............................................................................................................................................................................11
1.6 Power Tools for Editing...................................................................................................................11
............................................................................................................................................................................12
1.7 Power Grows on You.......................................................................................................................12
............................................................................................................................................................................14
1.8 There Are Many Shells....................................................................................................................14
............................................................................................................................................................................16
1.9 Which Shell Am I Running?............................................................................................................16
............................................................................................................................................................................17
1.10 Internal and External Commands...................................................................................................17
............................................................................................................................................................................18
1.11 How the Shell Executes Other Commands....................................................................................18
............................................................................................................................................................................19
1.12 What Makes a Shell Script?...........................................................................................................19
............................................................................................................................................................................20
1.13 Why Fundamentals Are Important.................................................................................................20
............................................................................................................................................................................21
1.14 The Kernel and Daemons...............................................................................................................21
............................................................................................................................................................................23
1.15 Filenames......................................................................................................................................23
............................................................................................................................................................................25
1.16 Wildcards......................................................................................................................................25
............................................................................................................................................................................27
1.17 Filename Extensions.....................................................................................................................27
............................................................................................................................................................................29
1.18 Who Handles Wildcards?..............................................................................................................29
............................................................................................................................................................................31
1.19 The Tree Structure of the Filesystem.............................................................................................31
............................................................................................................................................................................34
1.20 Your Home Directory....................................................................................................................34
............................................................................................................................................................................35
1.21 Making Pathnames........................................................................................................................35
............................................................................................................................................................................37
1.22 How UNIX Keeps Track of Files: Inodes......................................................................................37
............................................................................................................................................................................39
1.23 File Access Permissions.................................................................................................................39
............................................................................................................................................................................42
1.24 The Superuser (Root).....................................................................................................................42
............................................................................................................................................................................43
1.25 Access to Directories....................................................................................................................43
1.26 What a Multiuser System Can Do for You....................................................................................44
............................................................................................................................................................................45
1.27 How Background Processing Works.............................................................................................45
............................................................................................................................................................................46
1.28 Some Gotchas with Background Processing.................................................................................46
............................................................................................................................................................................48
1.29 When Is a File Not a File?.............................................................................................................48
............................................................................................................................................................................49
1.30 Redirecting Input and Output.........................................................................................................49
............................................................................................................................................................................50
1.31 The X Window System..................................................................................................................50
............................................................................................................................................................................51
1.32 One Big Hole................................................................................................................................51
............................................................................................................................................................................52
1.33 UNIX Networking and Communications......................................................................................52
............................................................................................................................................................................54
1.34 What's Wrong with UNIX.............................................................................................................54
............................................................................................................................................................................55
2. Logging In.....................................................................................................................................................56
2.1 Customizing the Shell......................................................................................................................56
............................................................................................................................................................................57
2.2 Shell Setup Files−Which, Where, and Why....................................................................................57
2.2.1 Bourne Shell....................................................................................................................57
2.2.2 C Shell.............................................................................................................................57
2.2.3 Korn Shell........................................................................................................................58
2.2.4 bash.................................................................................................................................58
2.2.5 tcsh..................................................................................................................................58
............................................................................................................................................................................59
2.3 What Goes in Shell Setup Files?......................................................................................................59
............................................................................................................................................................................61
2.4 Tip for Changing Account Setup: Keep a Shell Ready...................................................................61
............................................................................................................................................................................62
2.5 Tips for Speeding up Slow Logins..................................................................................................62
2.5.1 Quick Login.....................................................................................................................62
2.5.2 A Second Alias and Command File.................................................................................63
2.5.3 Once−a−Day Setup..........................................................................................................63
............................................................................................................................................................................65
2.6 Use Absolute Pathnames in Shell Setup Files.................................................................................65
............................................................................................................................................................................66
2.7 C Shell Setup Files Aren't Read When You Want Them to Be?.....................................................66
............................................................................................................................................................................68
2.8 Identifying Login Shells..................................................................................................................68
............................................................................................................................................................................69
2.9 Speeding Up Your C Shell with set prompt Test.............................................................................69
............................................................................................................................................................................70
2.10 Gotchas in set prompt Test............................................................................................................70
............................................................................................................................................................................72
2.11 Faster ksh and bash Startup with $− Test......................................................................................72
.............................................76
2.13 A .cshrc.$HOST File for Per Host Setup.......................................................................................76
............................................................................................................................................................................77
2.14 motd.diff: Show New Lines in Login Messages............................................................................77
............................................................................................................................................................................79
2.15 Unclutter Logins: Show Login Messages Just Once.....................................................................79
............................................................................................................................................................................80
2.16 Approved Shells: Using Unapproved Login Shell.........................................................................80
............................................................................................................................................................................83
3. Logging Out..................................................................................................................................................84
3.1 Running Commands When You Log Out........................................................................................84
............................................................................................................................................................................86
3.2 Running Commands at Bourne/Korn Shell Logout.........................................................................86
............................................................................................................................................................................87
3.3 Electronic Fortune Cookies..............................................................................................................87
............................................................................................................................................................................88
3.4 Automatic File Cleanup...................................................................................................................88
............................................................................................................................................................................89
3.5 Stop Accidental C Shell Logouts.....................................................................................................89
............................................................................................................................................................................90
3.6 Stop Accidental Bourne Shell Logouts............................................................................................90
............................................................................................................................................................................91
3.7 Detaching a Session with screen......................................................................................................91
............................................................................................................................................................................92
3.8 What tty Am I On?...........................................................................................................................92
............................................................................................................................................................................93
4. Organizing Your Home Directory...............................................................................................................94
4.1 What? Me, Organized?....................................................................................................................94
............................................................................................................................................................................95
4.2 A bin Directory for Your Programs and Scripts..............................................................................95
............................................................................................................................................................................96
4.3 Organizing Nonexecutable Scripts..................................................................................................96
............................................................................................................................................................................97
4.4 Directories for Emacs Hacks...........................................................................................................97
............................................................................................................................................................................98
4.5 Private (Personal) Directories..........................................................................................................98
............................................................................................................................................................................99
4.6 Naming Files...................................................................................................................................99
..........................................................................................................................................................................100
4.7 Make More Directories!.................................................................................................................100
..........................................................................................................................................................................102
4.8 Making Directories Made Easier...................................................................................................102
..........................................................................................................................................................................104
4.9 Setting Up vi with the .exrc File....................................................................................................104
..........................................................................................................................................................................105
4.10 Find All Command Versions with whereiz.................................................................................105
5. Setting Up Your Terminal.........................................................................................................................108
5.1 There's a Lot to Know About Terminals.......................................................................................108
..........................................................................................................................................................................109
5.2 The Idea of a Terminal Database...................................................................................................109
..........................................................................................................................................................................111
5.3 Setting the Terminal Type When You Log In...............................................................................111
..........................................................................................................................................................................114
5.4 Setting the TERMCAP Variable with tset.....................................................................................114
..........................................................................................................................................................................115
5.5 Querying Your Terminal Type: qterm...........................................................................................115
..........................................................................................................................................................................118
5.6 Checklist: Terminal Hangs When I Log In....................................................................................118
..........................................................................................................................................................................120
5.7 What termcap and terminfo Do and Don't Control........................................................................120
..........................................................................................................................................................................121
5.8 Terminal Escape Sequences...........................................................................................................121
..........................................................................................................................................................................123
5.9 Setting Your Erase, Kill, and Interrupt Characters........................................................................123
..........................................................................................................................................................................125
5.10 Finding What Terminal Names You Can Use.............................................................................125
..........................................................................................................................................................................127
5.11 Initializing the Terminal with tset................................................................................................127
..........................................................................................................................................................................128
5.12 Initializing the Terminal with tput...............................................................................................128
..........................................................................................................................................................................130
6. Shell and Environment Variables..............................................................................................................131
6.1 What Environment Variables Are Good For.................................................................................131
..........................................................................................................................................................................133
6.2 Parent−Child Relationships...........................................................................................................133
..........................................................................................................................................................................134
6.3 Predefined Environment Variables................................................................................................134
..........................................................................................................................................................................136
6.4 The PATH Environment Variable.................................................................................................136
..........................................................................................................................................................................138
6.5 PATH and path.............................................................................................................................138
..........................................................................................................................................................................139
6.6 The TZ Environment Variable.......................................................................................................139
..........................................................................................................................................................................140
6.7 What Time Is It in Japan?..............................................................................................................140
..........................................................................................................................................................................141
6.8 Shell Variables..............................................................................................................................141
..........................................................................................................................................................................143
6.9 Special C Shell Variables...............................................................................................................143
..........................................................................................................................................................................146
6.10 Running a Command with a Temporarily Different Environment..............................................146
..........................................................................................................................................................................147
7. Setting Your Shell Prompt.........................................................................................................................148
7.1 Why Change Your Prompt?...........................................................................................................148
7.2 Basics of Setting the Prompt..........................................................................................................149
..........................................................................................................................................................................150
7.3 C Shell Prompt Causes Problems in vi, rsh, etc............................................................................150
..........................................................................................................................................................................151
7.4 Faster Prompt Setting with Built−Ins............................................................................................151
..........................................................................................................................................................................153
7.5 Multiline Shell Prompts.................................................................................................................153
..........................................................................................................................................................................155
7.6 Session Information in Your Terminal's Status Line.....................................................................155
..........................................................................................................................................................................157
7.7 A "Menu Prompt" for Naive Users................................................................................................157
..........................................................................................................................................................................158
7.8 Highlighting in Shell Prompts.......................................................................................................158
..........................................................................................................................................................................160
7.9 Show Subshell Level with $SHLVL.............................................................................................160
..........................................................................................................................................................................162
7.10 What Good Is a Blank Shell Prompt?..........................................................................................162
..........................................................................................................................................................................163
7.11 dirs in Your Prompt: Better than $cwd........................................................................................163
..........................................................................................................................................................................165
7.12 External Commands Send Signals to Set Variables....................................................................165
..........................................................................................................................................................................167
7.13 Pre−Prompt Commands in bash..................................................................................................167
..........................................................................................................................................................................169
8. How the Shell Interprets What You Type................................................................................................170
8.1 What the Shell Does.......................................................................................................................170
..........................................................................................................................................................................172
8.2 Introduction to bash.......................................................................................................................172
..........................................................................................................................................................................174
8.3 Introduction to tcsh........................................................................................................................174
..........................................................................................................................................................................176
8.4 Command Evaluation and Accidentally Overwriting Files...........................................................176
..........................................................................................................................................................................177
8.5 Command−Line Evaluation...........................................................................................................177
..........................................................................................................................................................................180
8.6 Output Command−Line Arguments..............................................................................................180
8.6.1 Portability......................................................................................................................180
8.6.2 Making Error Messages.................................................................................................181
..........................................................................................................................................................................182
8.7 Setting Your Search Path...............................................................................................................182
8.7.1 Setting Path in Shell Setup Files....................................................................................182
8.7.2 Changing Path on the Command Line...........................................................................183
..........................................................................................................................................................................184
8.8 A Directory for Commands You Shouldn't Run............................................................................184
..........................................................................................................................................................................186
8.9 Wildcards Inside of Aliases...........................................................................................................186
..........................................................................................................................................................................187
8.10 eval: When You Need Another Chance.......................................................................................187
8.11 Which One Will bash Use?..........................................................................................................189
..........................................................................................................................................................................191
8.12 Which One Will the C Shell Use?...............................................................................................191
..........................................................................................................................................................................193
8.13 Is It "2>&1 file" or "> file 2>&1"? Why?...................................................................................193
..........................................................................................................................................................................194
8.14 Bourne Shell Quoting..................................................................................................................194
8.14.1 Special Characters........................................................................................................194
8.14.2 How Quoting Works....................................................................................................194
8.14.3 Single Quotes Inside Single Quotes?...........................................................................196
8.14.4 Multiline Quoting........................................................................................................196
..........................................................................................................................................................................198
8.15 Differences Between Bourne and C Shell Quoting.....................................................................198
8.15.1 Special Characters........................................................................................................198
8.15.2 How Quoting Works....................................................................................................198
..........................................................................................................................................................................200
8.16 Quoting Handles Special Characters in Filenames......................................................................200
..........................................................................................................................................................................201
8.17 verbose and echo Variables Show Quoting.................................................................................201
..........................................................................................................................................................................202
8.18 Here Documents..........................................................................................................................202
..........................................................................................................................................................................204
8.19 "Special" Characters and Operators.............................................................................................204
..........................................................................................................................................................................207
8.20 How Many Backslashes?.............................................................................................................207
..........................................................................................................................................................................209
9. Saving Time on the Command Line..........................................................................................................210
9.1 What's Special About the UNIX Command Line..........................................................................210
..........................................................................................................................................................................212
9.2 Fix a Line Faster with Line−Kill and Word−Erase.......................................................................212
..........................................................................................................................................................................213
9.3 Reprinting Your Command Line with CTRL−r............................................................................213
..........................................................................................................................................................................214
9.4 Use Wildcards to Create Files?......................................................................................................214
..........................................................................................................................................................................215
9.5 Build Strings with { } ...................................................................................................................215
..........................................................................................................................................................................217
9.6 String Editing (Colon) Operators...................................................................................................217
..........................................................................................................................................................................220
9.7 String Editing in ksh and bash.......................................................................................................220
..........................................................................................................................................................................222
9.8 Filename Completion: Faster Filename Typing............................................................................222
..........................................................................................................................................................................224
9.9 Don't Match Useless Files in Filename Completion......................................................................224
..........................................................................................................................................................................225
9.10 Filename Completion Isn't Always the Answer..........................................................................225
..........................................................................................................................................................................226
9.11 Repeating a Command with a foreach Loop................................................................................226
9.12 The Bourne Shell for Loop..........................................................................................................228
..........................................................................................................................................................................230
9.13 Multiline Commands, Secondary Prompts..................................................................................230
..........................................................................................................................................................................232
9.14 Using Here Documents for Form Letters, etc..............................................................................232
..........................................................................................................................................................................233
9.15 Throwaway Scripts for Complicated Commands........................................................................233
..........................................................................................................................................................................234
9.16 Command Substitution................................................................................................................234
..........................................................................................................................................................................236
9.17 Handling Lots of Text with Temporary Files..............................................................................236
..........................................................................................................................................................................237
9.18 Process Substitution....................................................................................................................237
9.18.1 bash Process Substitution.............................................................................................237
9.18.2 Automatic Temporary Files with !...............................................................................238
..........................................................................................................................................................................240
9.19 For the Impatient: Type−Ahead...................................................................................................240
..........................................................................................................................................................................242
9.20 Too Many Files for the Command Line......................................................................................242
..........................................................................................................................................................................244
9.21 Handle Too−Long Command Lines with xargs..........................................................................244
..........................................................................................................................................................................246
9.22 xargs: Problems with Spaces and Newlines.................................................................................246
..........................................................................................................................................................................248
9.23 Workaround for "Arguments too long" Error..............................................................................248
..........................................................................................................................................................................249
9.24 Get File List by Editing Output of ls −l, grep, etc.......................................................................249
9.24.1 What Files Have I Just Edited?....................................................................................249
9.24.2 Search for Text with grep............................................................................................250
..........................................................................................................................................................................252
9.25 The C Shell repeat Command......................................................................................................252
..........................................................................................................................................................................254
9.26 Expect.........................................................................................................................................254
9.26.1 Dialback.......................................................................................................................254
9.26.2 Automating /bin/passwd..............................................................................................255
9.26.3 Testing: A Story...........................................................................................................256
9.26.4 Other Problems............................................................................................................256
..........................................................................................................................................................................257
10. Aliases........................................................................................................................................................258
10.1 Creating Custom Commands.......................................................................................................258
..........................................................................................................................................................................259
10.2 Aliases for Common Commands.................................................................................................259
10.2.1 Simple Aliases.............................................................................................................259
10.2.2 Using More Complex Aliases......................................................................................259
10.2.3 Setting Aliases Automatically, Unsetting Aliases.......................................................260
..........................................................................................................................................................................262
10.3 C Shell Aliases with Command−Line Arguments.......................................................................262
..........................................................................................................................................................................264
10.4 Aliases in ksh and bash................................................................................................................264
10.5 Sourceable Scripts........................................................................................................................265
..........................................................................................................................................................................267
10.6 Avoiding C Shell Alias Loops.....................................................................................................267
..........................................................................................................................................................................269
10.7 How to Put if−then−else in a C Shell Alias.................................................................................269
..........................................................................................................................................................................270
10.8 Fix Quoting in csh Aliases with makealias and quote.................................................................270
..........................................................................................................................................................................271
10.9 Shell Functions...........................................................................................................................271
..........................................................................................................................................................................272
10.10 Simulated Bourne Shell Functions and Aliases.........................................................................272
..........................................................................................................................................................................273
11. The Lessons of History............................................................................................................................274
11.1 The Lessons of History................................................................................................................274
..........................................................................................................................................................................276
11.2 History in a Nutshell....................................................................................................................276
..........................................................................................................................................................................278
11.3 My Favorite Is !$.........................................................................................................................278
..........................................................................................................................................................................279
11.4 My Favorite Is !:n*......................................................................................................................279
..........................................................................................................................................................................280
11.5 My Favorite Is ^^.........................................................................................................................280
..........................................................................................................................................................................281
11.6 Using !$ for Safety with Wildcards.............................................................................................281
..........................................................................................................................................................................282
11.7 History Substitutions...................................................................................................................282
..........................................................................................................................................................................287
11.8 Repeating a Cycle of Commands.................................................................................................287
..........................................................................................................................................................................288
11.9 Running a Series of Commands on a File....................................................................................288
..........................................................................................................................................................................289
11.10 Check Your History First with :p..............................................................................................289
..........................................................................................................................................................................290
11.11 Picking Up Where You Left Off................................................................................................290
11.11.1 bash and ksh...............................................................................................................290
11.11.2 C Shell........................................................................................................................291
..........................................................................................................................................................................292
11.12 Pass History to Another Shell....................................................................................................292
..........................................................................................................................................................................293
11.13 Shell Command−Line Editing...................................................................................................293
..........................................................................................................................................................................295
11.14 More Ways to Do Interactive History Editing...........................................................................295
11.14.1 In the C Shell: redo....................................................................................................295
11.14.2 In ksh and bash: fc.....................................................................................................296
..........................................................................................................................................................................297
11.15 Changing C Shell History Characters with histchars.................................................................297
..........................................................................................................................................................................298
11.16 Instead of Changing History Characters....................................................................................298
12. Job Control...............................................................................................................................................300
12.1 Job Control: Work Faster, Stop Runaway Jobs...........................................................................300
12.1.1 Foreground and Background.......................................................................................300
..........................................................................................................................................................................303
12.2 Other Ways to Refer to Jobs........................................................................................................303
..........................................................................................................................................................................305
12.3 The "Current Job" Isn't Always What You Expect......................................................................305
..........................................................................................................................................................................306
12.4 Job Control and autowrite: Real Time Savers!............................................................................306
..........................................................................................................................................................................307
12.5 System Overloaded? Try Stopping Some Jobs............................................................................307
..........................................................................................................................................................................308
12.6 Notification When Jobs Change State.........................................................................................308
..........................................................................................................................................................................309
12.7 Stop Background Output with stty tostop....................................................................................309
..........................................................................................................................................................................310
12.8 Job Control in a Nutshell.............................................................................................................310
..........................................................................................................................................................................312
12.9 Running Multiple Shell Sessions with screen..............................................................................312
..........................................................................................................................................................................314
13. Redirecting Input and Output.................................................................................................................315
13.1 Using Standard Input and Output................................................................................................315
..........................................................................................................................................................................318
13.2 One Argument with a cat Isn't Enough........................................................................................318
..........................................................................................................................................................................319
13.3 Send (only) Standard Error Down a Pipe....................................................................................319
..........................................................................................................................................................................320
13.4 Problems Piping to a Pager..........................................................................................................320
..........................................................................................................................................................................322
13.5 Redirection in C Shell: Capture Errors, Too?..............................................................................322
..........................................................................................................................................................................323
13.6 Safe I/O Redirection with noclobber...........................................................................................323
..........................................................................................................................................................................325
13.7 The () Subshell Operators............................................................................................................325
13.7.1 Combining Several Commands...................................................................................325
13.7.2 Temporary Change of Directory and Environment.....................................................325
..........................................................................................................................................................................327
13.8 Using {list} to Group Bourne Shell Commands..........................................................................327
..........................................................................................................................................................................329
13.9 Send Output Two or More Places with tee..................................................................................329
..........................................................................................................................................................................330
13.10 How to tee Several Commands Into One File...........................................................................330
..........................................................................................................................................................................331
13.11 tpipe−Redirecting stdout to More than One Place.....................................................................331
..........................................................................................................................................................................333
13.12
Novell® Linux Certification Practium Lab Manual
Familiarize yourself with practicum exams to successfully take either the Novell Certified Linux Professional (CLP) or the Novell Certified Linux Engineer (CLE) exam with the Novell Linux Certification Practicum Lab Manual. The first half of the book consists of exercises with scenarios and relevant background information. The second half of the book walks through the exercises and shows the reader how to obtain the needed results, and is broken into four sections:
Working with the Desktop (CLP)
Intermediate Administration (CLP and CLE)
Advanced Administration (CLE)
Answers (CLP and CLE)
You will be able to walk through the scenarios and assess your preparedness for the exam with the help of the Novell Linux Certification Practicum Lab Manual.
Realtime OS system
Realtime OS system and implementation.