ebook img

Beginning Modern Unix: Learn to Live Comfortably in a Modern Unix Environment PDF

431 Pages·2018·11.61 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Beginning Modern Unix: Learn to Live Comfortably in a Modern Unix Environment

Beginning Modern Unix Learn to Live Comfortably in a Modern Unix Environment — Manish Jain Beginning Modern Unix Learn to Live Comfortably in a Modern Unix Environment Manish Jain Beginning Modern Unix Manish Jain Jaipur, Rajasthan, India ISBN-13 (pbk): 978-1-4842-3527-0 ISBN-13 (electronic): 978-1-4842-3528-7 https://doi.org/10.1007/978-1-4842-3528-7 Library of Congress Control Number: 2018950445 Copyright © 2018 by Manish Jain Tis work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifcally the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microflms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the beneft of the trademark owner, with no intention of infringement of the trademark. Te use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identifed as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. Te publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Louise Corrigan Development Editor: James Markham Coordinating Editor: Nancy Chen Cover designed by eStudioCalamar Cover image designed by Freepik (www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail Tis book is dedicated very humbly to the Regents of the University of California, Berkeley. Table of Contents About the Author ���������������������������������������������������������������������������������������������������xvii About the Technical Reviewer ��������������������������������������������������������������������������������xix Preface �������������������������������������������������������������������������������������������������������������������xxi Part 1: P reparing for Part I ����������������������������������������������������������������������������� 1 Chapter 1: E diting Text with Vim and Joe ����������������������������������������������������������������� 5 1.1 A Brief History of Unix Text Editors .......................................................................................... 5 1.2 I mportant Terms ...................................................................................................................... 6 1.2.1 L ine ................................................................................................................................. 6 1.2.2 R egular Expressions: What You Need To Know Right Now ............................................. 7 1.2.3 R emaining Terms of Endearment ................................................................................. 11 1.3 V i IMproved (Vim) .................................................................................................................. 11 1.3.1 M oving Around in the Buffer ......................................................................................... 16 1.3.2 R egisters and Clipboard Integration ............................................................................. 17 1.3.3 M arks ........................................................................................................................... 18 1.3.4 F ind and Replace .......................................................................................................... 18 1.3.5 V isual Selection Modes ................................................................................................. 19 1.3.6 Recording and Playing Macros ..................................................................................... 21 1.3.7 V im Utilities ................................................................................................................... 24 1.3.8 V im Confguration ......................................................................................................... 25 1.3.9 Vim Abbreviations and Auto-Completion Framework ................................................... 27 1.3.10 I nstalling Vim .............................................................................................................. 28 1.4 Joe’s Own Editor (Joe) .......................................................................................................... 29 1.4.1 I nstalling Joe ................................................................................................................ 32 1.5 S ummary............................................................................................................................... 33 v Table of ConTenTs Chapter 2: E ssential Unix Commands and Terminology ����������������������������������������� 35 2.1 K ernel, Shell, and Filesystem ................................................................................................ 35 2.2 F iles and Special Files .......................................................................................................... 36 2.2.1 T he Null Device ............................................................................................................. 37 2.2.2 S tandard Input .............................................................................................................. 37 2.2.3 S tandard Output ........................................................................................................... 38 2.2.4 S tandard Error .............................................................................................................. 39 2.2.5 T he Pipe ........................................................................................................................ 40 2.2.6 C onsole ......................................................................................................................... 40 2.3 Essential Unix Commands ..................................................................................................... 40 2.3.1 e cho <string> ............................................................................................................... 40 2.3.2 c d <path> .................................................................................................................... 41 2.3.3 p wd ............................................................................................................................... 41 2.3.4 l s <path> ...................................................................................................................... 41 2.3.5 m kdir <path> ............................................................................................................... 41 2.3.6 cp <source> <destination> ......................................................................................... 42 2.3.7 mv <source> <destination> ........................................................................................ 42 2.3.8 r m <path> .................................................................................................................... 42 2.3.9 ln [-s] <path> <additional> ......................................................................................... 42 2.3.10 c at <fle> .................................................................................................................... 43 2.3.11 t est <condition> ......................................................................................................... 43 2.3.12 e xpr ............................................................................................................................ 44 2.3.13 d d ............................................................................................................................... 45 2.3.14 grep <regex> [<fle>] ................................................................................................ 46 2.3.15 a wk [<fle>] ............................................................................................................... 47 2.3.16 s ed [<fle>] ................................................................................................................ 48 2.3.17 f le <path> ................................................................................................................. 49 2.3.18 f nd ............................................................................................................................. 49 2.3.19 u pdatedb .................................................................................................................... 49 2.3.20 l ocate <name> ........................................................................................................... 49 vi Table of ConTenTs 2.3.21 b asename <string> .................................................................................................... 50 2.3.22 d irname <string> ....................................................................................................... 50 2.3.23 r ealpath <path> ......................................................................................................... 50 2.3.24 h ead [<fle>] .............................................................................................................. 51 2.3.25 t ail [<fle>] ................................................................................................................. 51 2.3.26 r ev [<fle>] ................................................................................................................. 51 2.3.27 c ut [<fle>] ................................................................................................................. 52 2.3.28 t r ................................................................................................................................. 52 2.3.29 r ead <arg> ................................................................................................................. 52 2.3.30 d ate ............................................................................................................................ 53 2.3.31 t ype <executable> ..................................................................................................... 54 2.3.32 w c [<fle>] ................................................................................................................. 54 2.3.33 l ess [<fle>] ................................................................................................................ 54 2.3.34 m an <topic> ............................................................................................................... 55 2.3.35 s et ............................................................................................................................... 55 2.3.36 u name ........................................................................................................................ 56 2.3.37 w ho ............................................................................................................................. 56 2.3.38 cmp <fle1> <fle2> ................................................................................................... 56 2.3.39 diff <fle1> <fle2> .................................................................................................... 56 2.3.40 p s ................................................................................................................................ 57 2.3.41 kill [<sig>] <pid> ....................................................................................................... 57 2.3.42 s leep <n> ................................................................................................................... 58 2.3.43 s ort [<fle>] ................................................................................................................ 58 2.3.44 u niq [<fle>] ............................................................................................................... 58 2.3.45 chmod <mode> <fle> ............................................................................................... 59 2.3.46 chown <user> <fle> ................................................................................................. 60 2.3.47 c hsh [<user>]............................................................................................................. 61 2.3.48 p asswd [<user>] ........................................................................................................ 61 2.3.49 t ouch <fle> ................................................................................................................ 61 2.3.50 t ar ............................................................................................................................... 61 vii Table of ConTenTs 2.3.51 g zip ............................................................................................................................. 62 2.3.52 x z ................................................................................................................................ 63 2.3.53 s ource <fle> .............................................................................................................. 63 2.3.54 w get............................................................................................................................ 63 2.3.55 m d5[sum] <fle> ........................................................................................................ 64 2.3.56 s ha256[sum] <fle> .................................................................................................... 64 2.4 S ummary............................................................................................................................... 64 Chapter 3: B ourne Shell Scripting �������������������������������������������������������������������������� 65 3.1 I nside Our First Shell Script .................................................................................................. 65 3.2 V ariable Assignment .............................................................................................................. 66 3.3 A rithmetic and Boolean Operations....................................................................................... 69 3.4 C ommand Chaining and Grouping ........................................................................................ 70 3.5 M eta-Character Expansion.................................................................................................... 71 3.6 Q uoting: Single, Double, and Back ........................................................................................ 72 3.7 Setting the Shell Prompt ....................................................................................................... 73 3.8 Dealing with Whitespace in Filenames ................................................................................. 74 3.9 S hell Functions ..................................................................................................................... 76 3.10 S pecial Variables ................................................................................................................. 77 3.11 Branching and Looping ....................................................................................................... 79 3.12 T he shift Command ............................................................................................................. 82 3.13 Sourcing, Aliasing, and Exporting ........................................................................................ 83 3.14 P utting It All Together .......................................................................................................... 85 3.15 S ummary............................................................................................................................. 85 Part 2: P reparing for Part II �������������������������������������������������������������������������� 87 Chapter 4: P C Hardware for Unix ���������������������������������������������������������������������������� 89 4.1 A Shopping List ..................................................................................................................... 89 4.2 P reparatory Notes ................................................................................................................. 90 4.3 C PU (Central Processing Unit) ............................................................................................... 91 4.4 S ystem Board/Motherboard .................................................................................................. 92 viii Table of ConTenTs 4.5 R AM (Random Access Memory) ............................................................................................ 95 4.6 H ard Disk .............................................................................................................................. 96 4.7 S MPS (Switched Mode Power Supply) .................................................................................. 97 4.8 C abinet .................................................................................................................................. 98 4.9 G raphics Card ........................................................................................................................ 99 4.10 Optical Drive (CD/DVD Reader and Writer) ........................................................................ 102 4.11 C PU Cooler ........................................................................................................................ 103 4.12 P rinter/Scanner ................................................................................................................. 105 4.12.1 B uying an HP Printer ................................................................................................ 105 4.12.2 B uying an Epson Printer ........................................................................................... 106 4.13 S ummary........................................................................................................................... 107 Chapter 5: I nstalling and Confguring FreeBSD/Linux ������������������������������������������ 109 5.1 D isk Partitioning .................................................................................................................. 109 5.1.1 M BR (Master Boot Record) ......................................................................................... 110 5.1.2 G PT (GUID Partition Table) ........................................................................................... 111 5.2 D o We Have Enough Disk Space? ....................................................................................... 112 5.3 T he Default Partitioning Scheme......................................................................................... 113 5.4 P reparing the Computer’s CMOS for Unix ........................................................................... 114 5.5 D ownloading and Burning Installation Media ..................................................................... 116 5.6 Our Example Hard Disk ....................................................................................................... 117 5.7 I nstalling FreeBSD ............................................................................................................... 118 5.8 Installing and Confguring Linux ......................................................................................... 125 5.9 Post-Install Confguration of FreeBSD ................................................................................. 130 5.9.1 N etworking ................................................................................................................. 131 5.9.2 Software Packaging Subsystem ................................................................................. 131 5.9.3 A Friendlier Shell ........................................................................................................ 131 5.9.4X Server ....................................................................................................................... 132 5.9.5 NVIDIA Graphics Driver Addition ................................................................................. 133 5.9.6 NVIDIA and ATI Radeon Graphics Confguration .......................................................... 133 5.9.7 U ser Accounts ............................................................................................................. 134 ix Table of ConTenTs 5.9.8 G raphical Desktop Environment ................................................................................. 135 5.9.9 M aking Things Easier: A Simpler Way to Confgure FreeBSD ..................................... 135 5.10 D ual-Booting FreeBSD and Linux on a GPT Disk ............................................................... 136 5.11 S ummary........................................................................................................................... 138 Chapter 6: B asic System Administration �������������������������������������������������������������� 139 6.1 B eing Root ........................................................................................................................... 139 6.2 L ocal Filesystems ............................................................................................................... 140 6.3 P artition Management......................................................................................................... 144 6.4 C onsole Confguration ......................................................................................................... 146 6.5 I nternet Connectivity ........................................................................................................... 146 6.6 S ound Confguration ........................................................................................................... 150 6.7 X Confguration ................................................................................................................... 151 6.8 Running X Applications as Root .......................................................................................... 153 6.9 Finding Local Files Quickly ................................................................................................. 154 6.10 Confguring the Printer ...................................................................................................... 155 6.11 Using the Scanner ............................................................................................................. 157 6.12 Using an APC Powerchute UPS to Shut the System Down ................................................ 158 6.13 Building Stuff from Sources .............................................................................................. 159 6.14 U nix Virtual Filesystems .................................................................................................... 160 6.15 A dditional Commands to Administer Your Desktop ........................................................... 162 6.15.1 d f .............................................................................................................................. 162 6.15.2 d u ............................................................................................................................. 162 6.15.3 a t .............................................................................................................................. 163 6.15.4 c drecord ................................................................................................................... 164 6.15.5 Loop Device Confguration ........................................................................................ 165 6.15.6 s mtp-cli .................................................................................................................... 165 6.15.7 r sync ......................................................................................................................... 166 6.16 Mitigating the Need for Backups ...................................................................................... 168 6.17 S ummary........................................................................................................................... 172 x

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.