# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?<command>^\s*[0-9].[^0-9][A-z ,’]+)"
test_str = (" Part I\n"
"Table of Contents\n"
"How to Use This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix\n"
"Basic Unix Environment\n"
"1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3\n"
"1.1 What’s Special About Unix? 3\n"
"1.2 Power Grows on You 4\n"
"1.3 The Core of Unix 6\n"
"1.4 Communication with Unix 6\n"
"1.5 Programs Are Designed to Work Together 8\n"
"1.6 There Are Many Shells 9\n"
"1.7 Which Shell Am I Running?\n"
"1.8 Anyone Can Program the Shell\n"
"1.9 Internal and External Commands\n"
"1.10 The Kernel and Daemons\n"
"1.11 Filenames\n"
"1.12 Filename Extensions\n"
"1.13 Wildcards\n"
"1.14 The Tree Structure of the Filesystem\n"
"1.15 Your Home Directory\n"
"1.16 Making Pathnames\n"
"1.17 File Access Permissions\n"
"1.18 The Superuser (Root)\n"
"1.19 When Is a File Not a File?\n"
"1.20 Scripting\n"
"1 1 1 1 1 3 1 4 1 6 1 7 1 8 2 0 2 2 2 3 2 5 2 6 2 7 2 7\n"
"iii\n"
" \n"
" Part II\n"
"1.21 Unix Networking and Communications 2 8\n"
"1.22 The X Window System 3 0\n"
"2. Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32\n"
"2.1 The man Command 32\n"
"2.2 whatis: One-Line Command Summaries 33\n"
"2.3 whereis: Finding Where a Command Is Located 33\n"
"2.4 Searching Online Manual Pages 34\n"
"2.5 How Unix Systems Remember Their Names 36\n"
"2.6 Which Version Am I Using? 36\n"
"2.7 What tty Am I On? 37\n"
"2.8 Who’s On? 38\n"
"2.9 The info Command 38\n"
"Customizing Your Environment\n"
"3. Setting Up Your Unix Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43\n"
"3.1 What Happens When You Log In 43\n"
"3.2 The Mac OS X Terminal Application 44\n"
"3.3 Shell Setup Files—Which, Where, and Why 44\n"
"3.4 Login Shells, Interactive Shells 48\n"
"3.5 What Goes in Shell Setup Files? 49\n"
"3.6 Tip for Changing Account Setup: Keep a Shell Ready 50\n"
"3.7 Use Absolute Pathnames in Shell Setup Files 51\n"
"3.8 Setup Files Aren’t Read When You Want? 51\n"
"3.9 Gotchas in set prompt Test 53\n"
"3.10 Automatic Setups for Different Terminals 54\n"
"3.11 Terminal Setup: Testing TERM 55\n"
"3.12 Terminal Setup: Testing Remote Hostname and X Display 56\n"
"3.13 Terminal Setup: Testing Port 57\n"
"3.14 Terminal Setup: Testing Environment Variables 57\n"
"3.15 Terminal Setup: Searching Terminal Table 58\n"
"3.16 Terminal Setup: Testing Window Size 58\n"
"3.17 Terminal Setup: Setting and Testing Window Name 59\n"
"3.18 A .cshrc.$HOST File for Per Host Setup 60\n"
"3.19 Making a “Login” Shell 61\n"
"3.20 RC Files 62\n"
"3.21 Make Your Own Manpages Without Learning troff 65\n"
"3.22 Writing a Simple Manpage with the –man Macros 67\n"
"Table of Contents\n"
" iv\n\n"
" 4. Interacting with Your Environment\n"
". . . . . . . . . . . . . . . . . . . . . 70 70\n"
"4.1 Basics of Setting the Prompt\n"
"4.2 Static Prompts\n"
"4.3 Dynamic Prompts\n"
"4.4 Simulating Dynamic Prompts\n"
"4.5 C-Shell Prompt Causes Problems in vi, rsh, etc. 73\n"
"4.6 Faster Prompt Setting with Built-ins 74\n"
"4.7 Multiline Shell Prompts 76\n"
"4.8 Session Info in Window Title or Status Line 77\n"
"4.9 A “Menu Prompt” for Naive Users 79\n"
"4.10 Highlighting and Color in Shell Prompts 79\n"
"4.11 Right-Side Prompts 81\n"
"4.12 Show Subshell Level with $SHLVL 82\n"
"4.13 What Good Is a Blank Shell Prompt? 83\n"
"4.14 dirs in Your Prompt: Better Than $cwd 84\n"
"4.15 External Commands Send Signals to Set Variables 86\n"
"4.16 Preprompt, Pre-execution, and Periodic Commands 87\n"
"4.17 Running Commands When You Log Out 89\n"
"4.18 Running Commands at Bourne/Korn Shell Logout 90\n"
"4.19 Stop Accidental Bourne-Shell Logouts 90\n"
"5. Getting the Most out of Terminals, xterm,\n"
"and X Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92\n"
"5.1 There’s a Lot to Know About Terminals\n"
"5.2 The Idea of a Terminal Database\n"
"5.3 Setting the Terminal Type When You Log In\n"
"5.4 Querying Your Terminal Type: qterm\n"
"5.5 Querying Your xterm Size: resize\n"
"5.6 Checklist: Terminal Hangs When I Log In\n"
"5.7 Find Out Terminal Settings with stty\n"
"5.8 Setting Your Erase, Kill, and Interrupt Characters\n"
"5.9 Working with xterm and Friends\n"
"5.10 Login xterms and rxvts\n"
"5.11 Working with Scrollbars\n"
"5.12 How Many Lines to Save?\n"
"5.13 Simple Copy and Paste in xterm\n"
"5.14 Defining What Makes Up a Word for Selection Purposes\n"
"5.15 Setting the Titlebar and Icon Text\n"
"5.16 The Simple Way to Pick a Font\n"
"Table of Contents\n"
"92 93 95 97 99\n"
"1 00 1 04 1 04 1 06 1 07 1 08 1 09 1 09 1 10 1 11 1 12\n"
"v\n"
"70 71 72\n"
" \n"
" Part III\n"
"5.17 The xterm Menus 113\n"
"5.18 Changing Fonts Dynamically 115\n"
"5.19 Working with xclipboard 117\n"
"5.20 Problems with Large Selections 119\n"
"5.21 Tips for Copy and Paste Between Windows 120\n"
"5.22 Running a Single Command with xterm –e 122\n"
"5.23 Don’t Quote Arguments to xterm –e 123\n"
"6. Your X Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124\n"
"6.1 Defining Keys and Button Presses with xmodmap 124\n"
"6.2 Using xev to Learn Keysym Mappings 127\n"
"6.3 X Resource Syntax 128\n"
"6.4 X Event Translations 130\n"
"6.5 Setting X Resources: Overview 133\n"
"6.6 Setting Resources with the –xrm Option 135\n"
"6.7 How –name Affects Resources 135\n"
"6.8 Setting Resources with xrdb 136\n"
"6.9 Listing the Current Resources for a Client: appres 139\n"
"6.10 Starting Remote X Clients 140\n"
"Working with Files and Directories\n"
"7. Directory Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147\n"
"7.1 What? Me, Organized?\n"
"7.2 Many Homes\n"
"7.3 Access to Directories\n"
"7.4 A bin Directory for Your Programs and Scripts 149\n"
"7.5 Private (Personal) Directories 150\n"
"7.6 Naming Files 150\n"
"7.7 Make More Directories! 151\n"
"7.8 Making Directories Made Easier 152\n"
"8. Directories and Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154\n"
"8.1 Everything but the find Command\n"
"8.2 The Three Unix File Times\n"
"8.3 Finding Oldest or Newest Files with ls –t and ls –u 155\n"
"8.4 List All Subdirectories with ls –R 157\n"
"8.5 The ls –d Option 157\n"
"8.6 Color ls 158\n"
"Table of Contents\n"
"147 148 148\n"
"1 54 1 54\n"
" vi\n\n"
" 8.7 Some GNU ls Features\n"
"8.8 A csh Alias to List Recently Changed Files\n"
"8.9 Showing Hidden Files with ls –A and –a\n"
"8.10 Useful ls Aliases\n"
"8.11 Can’t Access a File? Look for Spaces in the Name\n"
"8.12 Showing Nonprintable Characters in Filenames\n"
"8.13 Counting Files by Types\n"
"8.14 Listing Files by Age and Size\n"
"8.15 newer: Print the Name of the Newest File\n"
"8.16 oldlinks: Find Unconnected Symbolic Links\n"
"8.17 Picking a Unique Filename Automatically\n"
"9. Finding Files with find . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"9.1 How to Use find\n"
"9.2 Delving Through a Deep Directory Tree\n"
"9.3 Don’t Forget –print\n"
"9.4 Looking for Files with Particular Names\n"
"9.5 Searching for Old Files\n"
"9.6 Be an Expert on find Search Operators\n"
"9.7 The Times That find Finds\n"
"9.8 Exact File-Time Comparisons\n"
"9.9 Running Commands on What You Find\n"
"9.10 Using –exec to Create Custom Tests\n"
"9.11 Custom –exec Tests Applied\n"
"9.12 Finding Many Things with One Command\n"
"9.13 Searching for Files by Type\n"
"9.14 Searching for Files by Size\n"
"9.15 Searching for Files by Permission\n"
"9.16 Searching by Owner and Group\n"
"9.17 Duplicating a Directory Tree\n"
"9.18 Using “Fast find” Databases\n"
"9.19 Wildcards with “Fast find” Database\n"
"9.20 Finding Files (Much) Faster with a find Database\n"
"9.21 grepping a Directory Tree\n"
"9.22 lookfor: Which File Has That Word?\n"
"9.23 Using Shell Arrays to Browse Directories\n"
"9.24 Finding the (Hard) Links to a File\n"
"9.25 Finding Files with –prune\n"
"9.26 Quick finds in the Current Directory\n"
"Table of Contents\n"
"1 61 1 62 1 63 1 63 165 166 167 168 1 69 1 69 1 70\n"
"171\n"
"1 71 1 73 175 175 175 176 178 179 179 181 182 182 184 185 185 186 187 187 189 190 192 193 194 197 198 199\n"
"vii\n"
" \n"
" 9.27 Skipping Parts of a Tree in find\n"
"9.28 Keeping find from Searching Networked Filesystem\n"
"1 9 9 2 0 0\n"
"10. Linking, Renaming, and Copying Files . . . . . . . . . . . . . . . . 201\n"
"10.1 What’s So Complicated About Copying Files 201\n"
"10.2 What’s Really in a Directory? 201\n"
"10.3 Files with Two or More Names 203\n"
"10.4 More About Links 205\n"
"10.5 Creating and Removing Links 208\n"
"10.6 Stale Symbolic Links 209\n"
"10.7 Linking Directories 210\n"
"10.8 Showing the Actual Filenames for Symbolic Links 212\n"
"10.9 Renaming, Copying, or Comparing a Set of Files 212\n"
"10.10 Renaming a List of Files Interactively 213\n"
"10.11 One More Way to Do It 213\n"
"10.12 Copying Directory Trees with cp –r 214\n"
"10.13 Copying Directory Trees with tar and Pipes 216\n"
"11. Comparing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218\n"
"11.1 Checking Differences with diff 218\n"
"11.2 Comparing Three Different Versions with diff3 220\n"
"11.3 Context diffs 221\n"
"11.4 Side-by-Side diffs: sdiff 224\n"
"11.5 Choosing Sides with sdiff 225\n"
"11.6 Problems with diff and Tabstops 225\n"
"11.7 cmp and diff 226\n"
"11.8 Comparing Two Files with comm 227\n"
"11.9 More Friendly comm Output 229\n"
"11.10 make Isn’t Just for Programmers! 230\n"
"11.11 Even More Uses for make\n"
"12. Showing What’s in a File\n"
"232\n"
"236\n"
"12.1 Cracking the Nut\n"
"12.2 What Good Is a cat?\n"
"12.3 “less” is More\n"
"12.4 Show Nonprinting Characters with cat –v or od –c 237\n"
"12.5 What’s in That Whitespace? 239\n"
"12.6 Finding File Types 240\n"
"12.7 Squash Extra Blank Lines 241\n"
"12.8 How to Look at the End of a File: tail 242\n"
"viii Table of Contents\n"
". . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 234 234\n"
" \n"
" 12.9 Finer Control on tail\n"
"12.10 How to Look at Files as They Grow\n"
"12.11 GNU tail File Following\n"
"12.12 Printing the Top of a File\n"
"12.13 Numbering Lines\n"
"243 243 245 246 246\n"
"247\n"
"247 248 249 250 251 251 252 254 255 256 257 258 258 2 59 2 59 2 60\n"
"262\n"
"2 62 2 62 2 63 265 265 266 266 267 268 269 269 270 271 271\n"
"ix\n"
"13. Searching Through Files\n"
". . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"13.1 Different Versions of grep\n"
"13.2 Searching for Text with grep\n"
"13.3 Finding Text That Doesn’t Match\n"
"13.4 Extended Searching for Text with egrep\n"
"13.5 grepping for a List of Patterns\n"
"13.6 Approximate grep: agrep\n"
"13.7 Search RCS Files with rcsgrep\n"
"13.8 GNU Context greps\n"
"13.9 A Multiline Context grep Using sed\n"
"13.10 Compound Searches\n"
"13.11 Narrowing a Search Quickly\n"
"13.12 Faking Case-Insensitive Searches\n"
"13.13 Finding a Character in a Column\n"
"13.14 Fast Searches and Spelling Checks with “look”\n"
"13.15 Finding Words Inside Binary Files\n"
"13.16 A Highlighting grep\n"
"14. Removing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"14.1 The Cycle of Creation and Destruction\n"
"14.2 How Unix Keeps Track of Files: Inodes\n"
"14.3 rm and Its Dangers\n"
"14.4 Tricks for Making rm Safer\n"
"14.5 Answer “Yes” or “No” Forever with yes\n"
"14.6 Remove Some, Leave Some\n"
"14.7 A Faster Way to Remove Files Interactively\n"
"14.8 Safer File Deletion in Some Directories\n"
"14.9 Safe Delete: Pros and Cons\n"
"14.10 Deletion with Prejudice: rm –f\n"
"14.11 Deleting Files with Odd Names\n"
"14.12 Using Wildcards to Delete Files with Strange Names\n"
"14.13 Handling a Filename Starting with a Dash (–)\n"
"14.14 Using unlink to Remove a File with a Strange Name\n"
"Table of Contents\n"
" \n"
" Part IV\n"
"14.15 Removing a Strange File by its i-number\n"
"14.16 Problems Deleting Directories\n"
"14.17 Deleting Stale Files\n"
"14.18 Removing Every File but One\n"
"14.19 Using find to Clear Out Unneeded Files\n"
"15. Optimizing Disk Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"15.1 Disk Space Is Cheap\n"
"15.2 Instead of Removing a File, Empty It\n"
"15.3 Save Space with “Bit Bucket” Log Files and Mailboxes\n"
"15.4 Save Space with a Link\n"
"15.5 Limiting File Sizes\n"
"15.6 Compressing Files to Save Space\n"
"15.7 Save Space: tar and compress a Directory Tree\n"
"15.8 How Much Disk Space?\n"
"15.9 Compressing a Directory Tree: Fine-Tuning\n"
"15.10 Save Space in Executable Files with strip\n"
"15.11 Disk Quotas\n"
"Basic Editing\n"
"16. Spell Checking, Word Counting, and Textual Analysis . .\n"
"16.1 The Unix spell Command\n"
"16.2 Check Spelling Interactively with ispell\n"
"16.3 How Do I Spell That Word?\n"
"16.4 Inside spell\n"
"16.5 Adding Words to ispell’s Dictionary\n"
"16.6 Counting Lines, Words, and Characters: wc\n"
"16.7 Find a a Doubled Word\n"
"16.8 Looking for Closure\n"
"16.9 Just the Words, Please\n"
"17. vi Tips and Tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"17.1 The vi Editor: Why So Much Material?\n"
"17.2 What We Cover\n"
"17.3 Editing Multiple Files with vi\n"
"17.4 Edits Between Files\n"
"17.5 Local Settings for vi\n"
"17.6 Using Buffers to Move or Copy Text\n"
"Table of Contents\n"
"2 72 2 72 2 74 275 276\n"
"277\n"
"277 277 279 279 280 281 284 286 288 2 89 290\n"
"295\n"
"295 296 298 299 301 303 305 305 306\n"
"308\n"
"308 309 309 311 312 313\n"
" x\n\n"
" 17.7 Get Back What You Deleted with Numbered Buffers 313\n"
"17.8 Using Search Patterns and Global Commands 314\n"
"17.9 Confirming Substitutions in vi 315\n"
"17.10 Keep Your Original File, Write to a New File 316\n"
"17.11 Saving Part of a File 316\n"
"17.12 Appending to an Existing File 317\n"
"17.13 Moving Blocks of Text by Patterns 317\n"
"17.14 Useful Global Commands (with Pattern Matches) 318\n"
"17.15 Counting Occurrences; Stopping Search Wraps 320\n"
"17.16 Capitalizing Every Word on a Line 320\n"
"17.17 Per-File Setups in Separate Files 321\n"
"17.18 Filtering Text Through a Unix Command 322\n"
"17.19 vi File Recovery Versus Networked Filesystems 324\n"
"17.20 Be Careful with vi –r Recovered Buffers 325\n"
"17.21 Shell Escapes: Running One Unix\n"
"Command While Using Another 326\n"
"17.22 vi Compound Searches 327\n"
"17.23 vi Word Abbreviation 328\n"
"17.24 Using vi Abbreviations as Commands\n"
"(Cut and Paste Between vi’s) 330\n"
"17.25 Fixing Typos with vi Abbreviations 330\n"
"17.26 vi Line Commands Versus Character Commands 331\n"
"17.27 Out of Temporary Space? Use Another Directory 332\n"
"17.28 Neatening Lines\n"
"17.29 Finding Your Place with Undo\n"
"17.30 Setting Up vi with the .exrc File\n"
"333 334 334\n"
". . . . . . . . . . . . . . . . . . . . 336 336\n"
"18.2 Save Time and Typing with the vi map Commands 336\n"
"18.3 What You Lose When You Use map! 339\n"
"18.4 vi @-Functions 340\n"
"18.5 Keymaps for Pasting into a Window Running vi 343\n"
"18.6 Protecting Keys from Interpretation by ex 343\n"
"18.7 Maps for Repeated Edits 345\n"
"18.8 More Examples of Mapping Keys in vi 347\n"
"18.9 Repeating a vi Keymap 348\n"
"18.10 Typing in Uppercase Without CAPS LOCK 348\n"
"18.11 Text-Input Mode Cursor Motion with No Arrow Keys 349 Table of Contents xi\n"
"18. Creating Custom Commands in vi\n"
"18.1 Why Type More Than You Have To?\n"
" \n"
" 18.12 Don’t Lose Important Functions with vi Maps: Use noremap\n"
"18.13 vi Macro for Splitting Long Lines\n"
"18.14 File-Backup Macros\n"
"19. GNU Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"19.1 Emacs: The Other Editor\n"
"19.2 Emacs Features: A Laundry List\n"
"19.3 Customizations and How to Avoid Them\n"
"19.4 Backup and Auto-Save Files\n"
"19.5 Putting Emacs in Overwrite Mode\n"
"19.6 Command Completion\n"
"19.7 Mike’s Favorite Timesavers\n"
"19.8 Rational Searches\n"
"19.9 Unset PWD Before Using Emacs\n"
"19.10 Inserting Binary Characters into Files\n"
"19.11 Using Word-Abbreviation Mode\n"
"19.12 Directories for Emacs Hacks\n"
"19.13 An Absurd Amusement\n"
"20. Batch Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"20.1 Why Line Editors Aren’t Dinosaurs\n"
"20.2 Writing Editing Scripts\n"
"20.3 Line Addressing\n"
"20.4 Useful ex Commands\n"
"20.5 Running Editing Scripts Within vi\n"
"20.6 Change Many Files by Editing Just One\n"
"20.7 ed/ex Batch Edits: A Typical Example\n"
"20.8 Batch Editing Gotcha: Editors Fail on Big Files\n"
"20.9 patch: Generalized Updating of Files That Differ\n"
"20.10 Quick Reference: awk\n"
"20.11 Versions of awk\n"
"21. You Can’t Quite Call This Editing . . . . . . . . . . . . . . . . . . . . . .\n"
"21.1 And Why Not?\n"
"21.2 Neatening Text with fmt\n"
"21.3 Alternatives to fmt\n"
"21.4 Clean Up Program Comment Blocks\n"
"21.5 Remove Mail/News Headers with behead\n"
"21.6 Low-Level File Butchery with dd\n"
"xii Table of Contents\n"
"3 50 3 50 3 51\n"
"353\n"
"353 354 358 358 360 360 361 362 363 363 364 366 366\n"
"367\n"
"367 368 369 370 373 373 375 376 377 378 388\n"
"390\n"
"390 391 392 394 395 396\n"
" \n"
" Part V\n"
"21.7 offset: Indent Text 396\n"
"21.8 Centering Lines in a File 397\n"
"21.9 Splitting Files at Fixed Points: split 398\n"
"21.10 Splitting Files by Context: csplit 401\n"
"21.11 Hacking on Characters with tr 404\n"
"21.12 Encoding “Binary” Files into ASCII 406\n"
"21.13 Text Conversion with dd 410\n"
"21.14 Cutting Columns or Fields 410\n"
"21.15 Making Text in Columns with pr 411\n"
"21.16 Make Columns Automatically with column 413\n"
"21.17 Straightening Jagged Columns 415\n"
"21.18 Pasting Things in Columns 416\n"
"21.19 Joining Lines with join 417\n"
"21.20 What Is (or Isn’t) Unique? 418\n"
"21.21 Rotating Text 419\n"
"22. Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421\n"
"22.1 Putting Things in Order 421\n"
"22.2 Sort Fields: How sort Sorts 422\n"
"22.3 Changing the sort Field Delimiter 424\n"
"22.4 Confusion with Whitespace Field Delimiters 424\n"
"22.5 Alphabetic and Numeric Sorting 426\n"
"22.6 Miscellaneous sort Hints 427\n"
"22.7 lensort: Sort Lines by Length 429\n"
"22.8 Sorting a List of People by Last Name 430\n"
"Processes and the Kernel\n"
"23. Job Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435\n"
"23.1 Job Control in a Nutshell 435\n"
"23.2 Job Control Basics 437\n"
"23.3 Using jobs Effectively 438\n"
"23.4 Some Gotchas with Job Control 440\n"
"23.5 The “Current Job” Isn’t Always What You Expect 442\n"
"23.6 Job Control and autowrite: Real Timesavers! 442\n"
"23.7 System Overloaded? Try Stopping Some Jobs 443\n"
"23.8 Notification When Jobs Change State 444\n"
"23.9 Stop Background Output with stty tostop 444\n"
"23.10 nohup 445 Table of Contents xiii\n"
" \n"
" 23.11 Disowning Processes\n"
"23.12 Linux Virtual Consoles\n"
"23.13 Stopping Remote Login Sessions\n"
"24. Starting, Stopping, and Killing Processes . . . . . . . . . . . . .\n"
"24.1 What’s in This Chapter\n"
"24.2 fork and exec\n"
"24.3 Managing Processes: Overall Concepts\n"
"24.4 Subshells\n"
"24.5 The ps Command\n"
"24.6 The Controlling Terminal\n"
"24.7 Tracking Down Processes\n"
"24.8 Why ps Prints Some Commands in Parentheses\n"
"24.9 The /proc Filesystem\n"
"24.10 What Are Signals?\n"
"24.11 Killing Foreground Jobs\n"
"24.12 Destroying Processes with kill\n"
"24.13 Printer Queue Watcher: A Restartable Daemon Shell Script\n"
"24.14 Killing All Your Processes\n"
"24.15 Killing Processes by Name?\n"
"24.16 Kill Processes Interactively\n"
"24.17 Processes Out of Control? Just STOP Them\n"
"24.18 Cleaning Up an Unkillable Process\n"
"24.19 Why You Can’t Kill a Zombie\n"
"24.20 The Process Chain to Your Window\n"
"24.21 Terminal Windows Without Shells\n"
"24.22 Close a Window by Killing Its Process(es)\n"
"25. Delayed Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"25.1 Building Software Robots the Easy Way\n"
"25.2 Periodic Program Execution: The cron Facility\n"
"25.3 Adding crontab Entries\n"
"25.4 Including Standard Input Within a cron Entry\n"
"25.5 The at Command\n"
"25.6 Making Your at Jobs Quiet\n"
"25.7 Checking and Removing Jobs\n"
"25.8 Avoiding Other at and cron Jobs\n"
"25.9 Waiting a Little While: sleep\n"
"xiv Table of Contents\n"
"4 4 6 4 4 7 4 4 9\n"
"451\n"
"4 51 4 52 4 53 455 456 4 59 4 60 4 62 4 63 468 469 470 471 473 474 476 478 479 480 480 482 484\n"
"488\n"
"488 4 89 494 495 495 496 496 497 498\n"
" \n"
" Part VI\n"
"26.1 Timing Is Everything\n"
"26.2 Timing Programs\n"
"26.3 What Commands Are Running and How Long Do They Take?\n"
"26.4 Checking System Load: uptime\n"
"26.5 Know When to Be “nice” to Other Users...and When Not To\n"
"26.6 A nice Gotcha\n"
"26.7 Changing a Running Job’s Niceness\n"
"Scripting\n"
"27. Shell Interpretation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"27.1 What the Shell Does\n"
"27.2 How the Shell Executes Other Commands\n"
"27.3 What’s a Shell, Anyway?\n"
"27.4 Command Evaluation and Accidentally Overwriting Files\n"
"27.5 Output Command-Line Arguments One by One\n"
"27.6 Controlling Shell Command Searches\n"
"27.7 Wildcards Inside Aliases\n"
"27.8 eval: When You Need Another Chance\n"
"27.9 Which One Will bash Use?\n"
"27.10 Which One Will the C Shell Use?\n"
"27.11 Is It “2 >&1 file” or “> file 2 >&1 ”? Why?\n"
"27.12 Bourne Shell Quoting\n"
"27.13 Differences Between Bourne and C Shell Quoting\n"
"27.14 Quoting Special Characters in Filenames\n"
"27.15 Verbose and Echo Settings Show Quoting\n"
"27.16 Here Documents\n"
"27.17 “Special” Characters and Operators\n"
"27.18 How Many Backslashes?\n"
"28. Saving Time on the Command Line . . . . . . . . . . . . . . . . . . .\n"
"28.1 What’s Special About the Unix Command Line\n"
"28.2 Reprinting Your Command Line with CTRL-r\n"
"28.3 Use Wildcards to Create Files?\n"
"26. System Performance and Profiling\n"
". . . . . . . . . . . . . . . . . . .\n"
"500\n"
"50 0 50 3 50 4 506 506 51 0 51 0\n"
"513\n"
"51 3 51 4 515 517 518 518 52 0 52 1 52 3 52 4 526 526 53 1 53 3 53 3 53 4 535 54 0\n"
"542\n"
"54 2 54 3 54 4 545 547 54 9\n"
"xv\n"
"28.4 Build Strings with { }\n"
"28.5 String Editing (Colon) Operators\n"
"28.6 Automatic Completion\n"
" Table of Contents\n\n"
" 28.7 Don’t Match Useless Files in Filename Completion 553\n"
"28.8 Repeating Commands 554\n"
"28.9 Repeating and Varying Commands 554\n"
"28.10 Repeating a Command with Copy-and-Paste 557\n"
"28.11 Repeating a Time-Varying Command 558\n"
"28.12 Multiline Commands, Secondary Prompts 559\n"
"28.13 Here Document Example #1 : Unformatted Form Letters 560\n"
"28.14 Command Substitution 561\n"
"28.15 Handling Lots of Text with Temporary Files 563\n"
"28.16 Separating Commands with Semicolons 563\n"
"28.17 Dealing with Too Many Arguments 565\n"
"28.18 Expect 567\n"
"29. Custom Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571\n"
"29.1 Creating Custom Commands 571\n"
"29.2 Introduction to Shell Aliases 571\n"
"29.3 C-Shell Aliases with Command-Line Arguments 572\n"
"29.4 Setting and Unsetting Bourne-Type Aliases 574\n"
"29.5 Korn-Shell Aliases 575\n"
"29.6 zsh Aliases 576\n"
"29.7 Sourceable Scripts 576\n"
"29.8 Avoiding C-Shell Alias Loops 578\n"
"29.9 How to Put if-then-else in a C-Shell Alias 579\n"
"29.10 Fix Quoting in csh Aliases with makealias and quote 580\n"
"29.11 Shell Function Basics 581\n"
"29.12 Shell Function Specifics 585\n"
"29.13 Propagating Shell Functions 586\n"
"29.14 Simulated Bourne Shell Functions and Aliases\n"
"59 1\n"
"30. The Use of History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593\n"
"30.1 The Lessons of History 593\n"
"30.2 History in a Nutshell 594\n"
"30.3 My Favorite Is !$ 595\n"
"30.4 My Favorite Is !:n* 595\n"
"30.5 My Favorite Is ^^ 596\n"
"30.6 Using !$ for Safety with Wildcards 597\n"
"30.7 History by Number 597\n"
"30.8 History Substitutions 599\n"
"30.9 Repeating a Cycle of Commands 604\n"
"xvi Table of Contents\n"
" \n"
" 30.10 Running a Series of Commands on a File 604\n"
"30.11 Check Your History First with :p 605\n"
"30.12 Picking Up Where You Left Off 606\n"
"30.13 Pass History to Another Shell 608\n"
"30.14 Shell Command-Line Editing 609\n"
"30.15 Changing History Characters with histchars 615\n"
"30.16 Instead of Changing History Characters 616\n"
"31. Moving Around in a Hurry . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617\n"
"31.1 Getting Around the Filesystem 617\n"
"31.2 Using Relative and Absolute Pathnames 618\n"
"31.3 What Good Is a Current Directory? 620\n"
"31.4 How Does Unix Find Your Current Directory? 621\n"
"31.5 Saving Time When You Change Directories: cdpath 622\n"
"31.6 Loop Control: break and continue 623\n"
"31.7 The Shells’ pushd and popd Commands 624\n"
"31.8 Nice Aliases for pushd 626\n"
"31.9 Quick cds with Aliases 627\n"
"31.10 cd by Directory Initials 627\n"
"31.11 Finding (Anyone’s) Home Directory, Quickly 629\n"
"31.12 Marking Your Place with a Shell Variable 630\n"
"31.13 Automatic Setup When You Enter/Exit a Directory 630\n"
"32. Regular Expressions (Pattern Matching) . . . . . . . . . . . . . . 633\n"
"32.1 That’s an Expression\n"
"633\n"
"32.2 Don’t Confuse Regular Expressions with Wildcards 634\n"
"32.3 Understanding Expressions 635\n"
"32.4 Using Metacharacters in Regular Expressions 637\n"
"32.5 Regular Expressions: The Anchor Characters ^ and $ 638\n"
"32.6 Regular Expressions: Matching a Character\n"
"with a Character Set 639\n"
"32.7 Regular Expressions: Match Any Character with . (Dot) 640\n"
"32.8 Regular Expressions: Specifying\n"
"a Range of Characters with [...] 640\n"
"32.9 Regular Expressions: Exceptions in a Character Set 641\n"
"32.10 Regular Expressions: Repeating Character Sets with * 641\n"
"32.11 Regular Expressions: Matching a Specific\n"
"Number of Sets with \\ { and \\ } 642\n"
"32.12 Regular Expressions: Matching Words with \\ < and \\ > 643\n"
"Table of Contents xvii\n"
" \n"
" 32.13 Regular Expressions: Remembering Patterns with \\ (, \\ ), and \\1\n"
"32.14 Regular Expressions: Potential Problems\n"
"32.15 Extended Regular Expressions\n"
"32.16 Getting Regular Expressions Right\n"
"32.17 Just What Does a Regular Expression Match?\n"
"32.18 Limiting the Extent of a Match\n"
"32.19 I Never Meta Character I Didn’t Like\n"
"32.20 Valid Metacharacters for Different Unix Programs\n"
"32.21 Pattern Matching Quick Reference with Examples\n"
"33. Wildcards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"33.1 File-Naming Wildcards\n"
"33.2 Filename Wildcards in a Nutshell\n"
"33.3 Who Handles Wildcards?\n"
"33.4 What if a Wildcard Doesn’t Match?\n"
"33.5 Maybe You Shouldn’t Use Wildcards in Pathnames\n"
"33.6 Getting a List of Matching Files with grep –l\n"
"33.7 Getting a List of Nonmatching Files\n"
"33.8 nom: List Files That Don’t Match a Wildcard\n"
"34. The sed Stream Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"34.1 sed Sermon^H^H^H^H^H^HSummary\n"
"34.2 Two Things You Must Know About sed\n"
"34.3 Invoking sed\n"
"34.4 Testing and Using a sed Script: checksed, runsed\n"
"34.5 sed Addressing Basics\n"
"34.6 Order of Commands in a Script\n"
"34.7 One Thing at a Time\n"
"34.8 Delimiting a Regular Expression\n"
"34.9 Newlines in a sed Replacement\n"
"34.10 Referencing the Search String in a Replacement\n"
"34.11 Referencing Portions of a Search String\n"
"34.12 Search and Replacement: One Match Among Many\n"
"34.13 Transformations on Text\n"
"34.14 Hold Space: The Set-Aside Buffer\n"
"34.15 Transforming Part of a Line\n"
"34.16 Making Edits Across Line Boundaries\n"
"34.17 The Deliberate Scrivener\n"
"34.18 Searching for Patterns Split Across Lines\n"
"Table of Contents\n"
"64 4 64 4 645 646 648 64 9 650 651 652\n"
"657\n"
"657 658 660 662 663 664 664 666\n"
"668\n"
"668 669 669 670 672 674 675 675 676 677 678 679 680 680 683 685 688 69 0\n"
" xviii\n\n"
" 34.19 Multiline Delete\n"
"34.20 Making Edits Everywhere Except...\n"
"34.21 The sed Test Command\n"
"34.22 Uses of the sed Quit Command\n"
"34.23 Dangers of the sed Quit Command\n"
"34.24 sed Newlines, Quoting, and Backslashes in a Shell Script\n"
"35. Shell Programming for the Uninitiated . . . . . . . . . . . . . . . .\n"
"35.1 Writing a Simple Shell Program\n"
"35.2 Everyone Should Learn Some Shell Programming\n"
"35.3 What Environment Variables Are Good For\n"
"35.4 Parent-Child Relationships\n"
"35.5 Predefined Environment Variables\n"
"35.6 The PATH Environment Variable\n"
"35.7 PATH and path\n"
"35.8 The DISPLAY Environment Variable\n"
"35.9 Shell Variables\n"
"35.10 Test String Values with Bourne-Shell case\n"
"35.11 Pattern Matching in case Statements\n"
"35.12 Exit Status of Unix Processes\n"
"35.13 Test Exit Status with the if Statement\n"
"35.14 Testing Your Success\n"
"35.15 Loops That Test Exit Status\n"
"35.16 Set Exit Status of a Shell (Script)\n"
"35.17 Trapping Exits Caused by Interrupts\n"
"35.18 read: Reading from the Keyboard\n"
"35.19 Shell Script “Wrappers” for awk, sed, etc.\n"
"35.20 Handling Command-Line Arguments in Shell Scripts\n"
"35.21 Handling Command-Line Arguments with a for Loop\n"
"35.22 Handling Arguments with while and shift\n"
"35.23 Loop Control: break and continue\n"
"35.24 Standard Command-Line Parsing\n"
"35.25 The Bourne Shell set Command\n"
"35.26 test: Testing Files and Strings\n"
"35.27 Picking a Name for a New Command\n"
"35.28 Finding a Program Name and Giving Your Program Multiple Names\n"
"35.29 Reading Files with the . and source Commands\n"
"35.30 Using Shell Functions in Shell Scripts\n"
"Table of Contents\n"
"69 2 69 3 695 696 696 697\n"
"698\n"
"698 70 0 70 2 705 705 708 709 710 711 713 714 715 716 718 719 720 721 723 724 725 727 728 73 0 73 0 73 2 735 736\n"
"736 737 738\n"
"xix\n"
" \n"
" 36. Shell Programming for the Initiated\n"
"36.1 Beyond the Basics\n"
"36.2 The Story of : # #!\n"
". . . . . . . . . . . . . . . . . .\n"
"741\n"
"74 1 74 2 74 3 744 745 746 747\n"
"748 749 749 750 750 751 753 753 756 759 760 761 761 762 764 764 768 770 770 772\n"
"775\n"
"775 777 777 778 779 781 782 783 784\n"
"36.3 Don’t Need a Shell for Your Script? Don’t Use One\n"
"36.4 Making #! Search the PATH\n"
"36.5 The exec Command\n"
"36.6 The Unappreciated Bourne Shell “:” Operator\n"
"36.7 Parameter Substitution\n"
"36.8 Save Disk Space and Programming: Multiple Names for a Program\n"
"36.9 Finding the Last Command-Line Argument\n"
"36.10 How to Unset All Command-Line Parameters\n"
"36.11 Standard Input to a for Loop\n"
"36.12 Making a for Loop with Multiple Variables\n"
"36.13 Using basename and dirname\n"
"36.14 A while Loop with Several Loop Control Commands\n"
"36.15 Overview: Open Files and File Descriptors\n"
"36.16 n>&m: Swap Standard Output and Standard Error\n"
"36.17 A Shell Can Read a Script from Its Standard Input, but...\n"
"36.18 Shell Scripts On-the-Fly from Standard Input\n"
"36.19 Quoted hereis Document Terminators: sh Versus csh\n"
"36.20 Turn Off echo for “Secret” Answers\n"
"36.21 Quick Reference: expr\n"
"36.22 Testing Characters in a String with expr\n"
"36.23 Grabbing Parts of a String\n"
"36.24 Nested Command Substitution\n"
"36.25 Testing Two Strings with One case Statement\n"
"36.26 Outputting Text to an X Window\n"
"36.27 Shell Lockfile\n"
"37. Shell Script Debugging and Gotchas . . . . . . . . . . . . . . . . . .\n"
"37.1 Tips for Debugging Shell Scripts\n"
"37.2 Bourne Shell Debugger Shows a Shell Variable\n"
"37.3 Stop Syntax Errors in Numeric Tests\n"
"37.4 Stop Syntax Errors in String Tests\n"
"37.5 Quoting and Command-Line Parameters\n"
"37.6 How Unix Keeps Time\n"
"37.7 Copy What You Do with script\n"
"37.8 Cleaning script Files\n"
"37.9 Making an Arbitrary-Size File for Testing\n"
"xx Table of Contents\n"
" \n"
" Part VII\n"
"Extending and Managing Your Environment\n"
"38. Backing Up Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"38.1 What Is This “Backup” Thing?\n"
"38.2 tar in a Nutshell\n"
"38.3 Make Your Own Backups\n"
"38.4 More Ways to Back Up\n"
"38.5 How to Make Backups to a Local Device\n"
"38.6 Restoring Files from Tape with tar\n"
"38.7 Using tar to a Remote Tape Drive\n"
"38.8 Using GNU tar with a Remote Tape Drive\n"
"38.9 On-Demand Incremental Backups of a Project\n"
"38.10 Using Wildcards with tar\n"
"38.11 Avoid Absolute Paths with tar\n"
"38.12 Getting tar’s Arguments in the Right Order\n"
"38.13 The cpio Tape Archiver\n"
"38.14 Industrial Strength Backups\n"
"39. Creating and Reading Archives . . . . . . . . . . . . . . . . . . . . . . .\n"
"39.1 Packing Up and Moving\n"
"39.2 Using tar to Create and Unpack Archives\n"
"39.3 GNU tar Sampler\n"
"39.4 Managing and Sharing Files with RCS and CVS\n"
"39.5 RCS Basics\n"
"39.6 List RCS Revision Numbers with rcsrevs\n"
"39.7 CVS Basics\n"
"39.8 More CVS\n"
"40. Software Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"40.1 /usr/bin and Other Software Directories\n"
"40.2 The Challenges of Software Installation on Unix\n"
"40.3 Which make?\n"
"40.4 Simplifying the make Process\n"
"40.5 Using Debian’s dselect\n"
"40.6 Installing Software with Debian’s Apt-Get\n"
"40.7 Interruptable gets with wget\n"
"40.8 The curl Application and One-Step GNU-Darwin Auto-Installer for OS X\n"
"40.9 Installation with FreeBSD Ports\n"
"787\n"
"787 788 788 790 790 795 797 798 798 800 803 804 805 806\n"
"808\n"
"808 809 813 814 815 817 818 819\n"
"822\n"
"82 2 82 4 824 824 825 832 834\n"
"836 837\n"
"xxi\n"
" Table of Contents\n\n"
" 40.10 Installing with FreeBSD Packages\n"
"40.11 Finding and Installing RPM Packaged Software\n"
"41. Perl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"41.1 High-Octane Shell Scripting\n"
"41.2 Checking your Perl Installation\n"
"41.3 Compiling Perl from Scratch\n"
"41.4 Perl Boot Camp, Part 1 : Typical Script Anatomy\n"
"41.5 Perl Boot Camp, Part 2 : Variables and Data Types\n"
"41.6 Perl Boot Camp, Part 3 : Branching and Looping\n"
"41.7 Perl Boot Camp, Part 4 : Pattern Matching\n"
"41.8 Perl Boot Camp, Part 5: Perl Knows Unix\n"
"41.9 Perl Boot Camp, Part 6: Modules\n"
"41.10 Perl Boot Camp, Part 7: perldoc\n"
"41.11 CPAN\n"
"41.12 Make Custom grep Commands (etc.) with Perl\n"
"41.13 Perl and the Internet\n"
"42. Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"42.1 What Is Python?\n"
"42.2 Installation and Distutils\n"
"42.3 Python Basics\n"
"42.4 Python and the Web\n"
"42.5 urllib\n"
"42.6 urllib2\n"
"42.7 htmllib and HTMLParser\n"
"42.8 cgi\n"
"42.9 mod_python\n"
"42.10 What About Perl?\n"
"PartVIII Communication and Connectivity\n"
"43. Redirecting Input and Output . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"43.1 Using Standard Input and Output\n"
"43.2 One Argument with a cat Isn’t Enough\n"
"43.3 Send (Only) Standard Error Down a Pipe\n"
"43.4 Problems Piping to a Pager\n"
"43.5 Redirection in C Shell: Capture Errors, Too?\n"
"43.6 Safe I/O Redirection with noclobber\n"
"xxii Table of Contents\n"
"83 7 83 8\n"
"839\n"
"83 9 83 9 84 1 84 2 845 852 854 856 859 861 862 865 866\n"
"869\n"
"869 869 871 876 876 877 878 878 879 880\n"
"885\n"
"885 888 888 889 891 892\n"
" \n"
" 43.7 The () Subshell Operators\n"
"43.8 Send Output Two or More Places\n"
"43.9 How to tee Several Commands into One Place\n"
"43.10 Redirecting Output to More Than One Place\n"
"43.11 Named Pipes: FIFOs\n"
"43.12 What Can You Do with an Empty File?\n"
"44. Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"44.1 Quick Introduction to Hardware\n"
"44.2 Reading Kernel Boot Output\n"
"44.3 Basic Kernel Configuration\n"
"44.4 Disk Partitioning\n"
"44.5 Filesystem Types and /etc/fstab\n"
"44.6 Mounting and Unmounting Removable Filesystems\n"
"44.7 Loopback Mounts\n"
"44.8 Network Devices—ifconfig\n"
"44.9 Mounting Network Filesystems—NFS, SMBFS\n"
"44.10 Win Is a Modem Not a Modem?\n"
"44.11 Setting Up a Dialup PPP Session\n"
"44.12 USB Configuration\n"
"44.13 Dealing with Sound Cards and Other Annoying Hardware\n"
"44.14 Decapitating Your Machine—Serial Consoles\n"
"45. Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"45.1 Introduction to Printing\n"
"45.2 Introduction to Printing on Unix\n"
"45.3 Printer Control with lpc\n"
"45.4 Using Different Printers\n"
"45.5 Using Symbolic Links for Spooling\n"
"45.6 Formatting Plain Text: pr\n"
"45.7 Formatting Plain Text: enscript\n"
"45.8 Printing Over a Network\n"
"45.9 Printing Over Samba\n"
"45.10 Introduction to Typesetting\n"
"45.11 A Bit of Unix Typesetting History\n"
"45.12 Typesetting Manpages: nroff\n"
"45.13 Formatting Markup Languages— troff, LATEX, HTML, and So On\n"
"45.14 Printing Languages—PostScript, PCL, DVI, PDF\n"
"Table of Contents\n"
"89 3 89 4 895 895 897 898\n"
"900\n"
"900 900 902 903 904 906 907 908 908 909 910 911 911 912\n"
"914\n"
"914 915 917 918 919 920 922 923 923 925 926 927\n"
"928 929\n"
"xxiii\n"
" \n"
" Part IX\n"
"xxiv\n"
"45.15 Converting Text Files into a Printing Language\n"
"45.16 Converting Typeset Files into a Printing Language\n"
"45.17 Converting Source Files Automagically Within the Spooler\n"
"45.18 The Common Unix Printing System (CUPS)\n"
"45.19 The Portable Bitmap Package\n"
"46. Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"46.1 TCP/IP—IP Addresses and Ports\n"
"46.2 /etc/services Is Your Friend\n"
"46.3 Status and Troubleshooting\n"
"46.4 Where, Oh Where Did That Packet Go?\n"
"46.5 The Director of Operations: inetd\n"
"46.6 Secure Shell (SSH)\n"
"46.7 Configuring an Anonymous FTP Server\n"
"46.8 Mail—SMTP, POP, and IMAP\n"
"46.9 Domain Name Service (DNS)\n"
"46.10 Dynamic Host Configuration Protocol (DHCP)\n"
"46.11 Gateways and NAT\n"
"46.12 Firewalls\n"
"46.13 Gatewaying from a Personal LAN over a Modem\n"
"47. Connecting to MS Windows . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"47.1 Building Bridges\n"
"47.2 Installing and Configuring Samba\n"
"47.3 Securing Samba\n"
"47.4 SWAT and GUI SMB Browsers\n"
"47.5 Printing with Samba\n"
"47.6 Connecting to SMB Shares from Unix\n"
"47.7 Sharing Desktops with VNC\n"
"47.8 Of Emulators and APIs\n"
"47.9 Citrix: Making Windows Multiuser\n"
"Security\n"
"48. Security Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"
"48.1 Understanding Points of Vulnerability\n"
"48.2 CERT Security Checklists\n"
"48.3 Keeping Up with Security Alerts\n"
"48.4 What We Mean by Buffer Overflow\n"
"Table of Contents\n"
"930 931 932 933 933\n"
"936\n"
"936 938 939 941 942 943 944 944 945 947 948 949 9 50\n"
"951\n"
"951 951 955 956 958 9 59 9 59 9 62 9 63\n"
"969\n"
"9 69 9 70 9 71 9 72\n"
" \n"
" 48.5 What We Mean by DoS\n"
"48.6 Beware of Sluggish Performance\n"
"48.7 Intruder Detection\n"
"48.8 Importance of MOTD\n"
"48.9 The Linux proc Filesystem\n"
"48.10 Disabling inetd\n"
"48.11 Disallow rlogin and rsh\n"
"48.12 TCP Wrappers\n"
"49. Root, Group, and User Management\n"
". . . . . . . . . . . . . . . . . .\n"
"9 73 9 74 977 978 9 79 9 79 9 80 9 80\n"
"982\n"
"9 82 9 82 9 84 985 985 986 988 989 990 990 991 992 993\n"
"994\n"
"994 994 998 999\n"
"1 000 1 001 1 002 1 003 1 003 1 004 1 006 1 007 1 009 1 009 1 010\n"
"xxv\n"
"49.1 Unix User/Group Infrastructure\n"
"49.2 When Does a User Become a User\n"
"49.3 Forgetting the root Password\n"
"49.4 Setting an Exact umask\n"
"49.5 Group Permissions in a Directory with the setgid Bit\n"
"49.6 Groups and Group Ownership\n"
"49.7 Add Users to a Group to Deny Permissions\n"
"49.8 Care and Feeding of SUID and SGID Scripts\n"
"49.9 Substitute Identity with su\n"
"49.10 Never Log In as root\n"
"49.11 Providing Superpowers with sudo\n"
"49.12 Enabling Root in Darwin\n"
"49.13 Disable logins\n"
"50. File Security, Ownership, and Sharing\n"
". . . . . . . . . . . . . . . .\n"
"50.1 Introduction to File Ownership and Security\n"
"50.2 Tutorial on File and Directory Permissions\n"
"50.3 Who Will Own a New File?\n"
"50.4 Protecting Files with the Sticky Bit\n"
"50.5 Using chmod to Change File Permission\n"
"50.6 The Handy chmod = Operator\n"
"50.7 Protect Important Files: Make Them Unwritable\n"
"50.8 cx, cw, c–w: Quick File Permission Changes\n"
"50.9 A Loophole: Modifying Files Without Write Access\n"
"50.10 A Directory That People Can Access but Can’t List\n"
"50.11 Juggling Permissions\n"
"50.12 File Verification with md5sum\n"
"50.13 Shell Scripts Must Be Readable and (Usually) Executable\n"
"50.14 Why Can’t You Change File Ownership?\n"
"50.15 How to Change File Ownership Without chown\n"
"Table of Contents\n"
" \n"
" 51.1 51.2 51.3 51.4 51.5 51.6 51.7\n"
"Glossary . Index . . . .\n"
"Enabling Remote Access on Mac OS X 1011 Protecting Access Through SSH 1011 Free SSH with OpenSSH 1012 SSH Problems and Solutions 1013 General and Authentication Problems 1013 Key and Agent Problems 1019 Server and Client Problems 1021\n"
". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1030 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1037\n"
"51. SSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1011\n"
" xxvi Table of Contents\n")
subst = "${command}"
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0, re.MULTILINE | re.IGNORECASE | re.DOTALL)
if result:
print (result)
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html