Take Control of the Mac Command Line with Terminal
Total Page:16
File Type:pdf, Size:1020Kb
EBOOK EXTRAS: v3.0 Downloads, Updates, Feedback TAKE CONTROL OF THE MAC COMMAND LINE WITH TERMINAL by JOE KISSELL $14.99 3rd Click here to buy “Take Control of the Mac Command Line with Terminal” for only $14.99! EDITION Table of Contents Read Me First ............................................................... 6 Updates and More ............................................................. 6 Basics .............................................................................. 7 What’s New in the Third Edition ........................................... 8 Introduction .............................................................. 11 macOS Command Line Quick Start ............................. 14 Understand Basic Command-Line Concepts ............... 16 What’s Unix? ................................................................... 16 What’s a Command Line? ................................................. 17 What’s a Shell? ............................................................... 18 What’s Terminal? ............................................................. 19 What Are Commands, Arguments, and Flags? ..................... 21 What Changed in Catalina? ............................................... 25 Get to Know (and Customize) Terminal ..................... 33 Learn the Basics of Terminal ............................................. 33 Modify the Window .......................................................... 35 Open Multiple Sessions .................................................... 36 Change the Window’s Attributes ........................................ 37 Change Your Current Shell ................................................ 40 Set a Default Shell ........................................................... 41 Look Around .............................................................. 44 Discover Where You Are ................................................... 44 See What’s Here ............................................................. 45 Repeat a Command ......................................................... 47 Cancel a Command .......................................................... 49 Move into Another Directory ............................................. 49 Jump Home .................................................................... 52 Understand How Paths Work ............................................. 53 Understand the macOS Directory Structure ......................... 55 2 Click here to buy the full 215-page “Take Control of the Mac Command Line with Terminal” for only $14.99! Use Tab Completion ......................................................... 57 Find a File ...................................................................... 59 View a Text File ............................................................... 61 Get Help ........................................................................ 63 Clear the Screen ............................................................. 64 End a Shell Session ......................................................... 65 Work with Files and Directories ................................. 66 Create a File ................................................................... 66 Create a Directory ........................................................... 67 Copy a File or Directory .................................................... 68 Move or Rename a File or Directory ................................... 70 Delete a File ................................................................... 72 Delete a Directory ........................................................... 73 Use Symbolic Links .......................................................... 74 Work with Programs .................................................. 76 Learn Command-Line Program Basics ................................. 76 Run a Program or Script ................................................... 79 Run a Program in the Background ...................................... 83 See What Programs Are Running ....................................... 84 Stop a Program ............................................................... 88 Edit a Text File ................................................................ 89 Create Your Own Shell Script ............................................ 92 Customize Your Defaults ........................................... 96 About Startup Files .......................................................... 96 Edit .zshrc or .bash_profile ............................................... 97 Create Aliases ................................................................. 97 Modify Your PATH ............................................................ 99 Change Your Prompt ........................................................ 99 Bring the Command Line into the Real World .......... 102 Get the Path of a File or Folder ........................................ 102 Open the Current Directory in the Finder .......................... 104 Open a Hidden Directory without Using Terminal ................ 104 Open the Current Folder in Terminal ................................. 105 3 Click here to buy the full 215-page “Take Control of the Mac Command Line with Terminal” for only $14.99! Open a macOS App ........................................................ 107 Open a File in macOS ..................................................... 107 Log In to Another Computer .................................... 108 Start an SSH Session ..................................................... 108 Run Commands on Another Computer .............................. 110 End an SSH Session ....................................................... 111 Transfer Files with sftp or scp .......................................... 111 Work with Permissions ............................................ 115 Understand Permission Basics ......................................... 115 Change an Item’s Permissions ......................................... 119 Change an Item’s Owner or Group ................................... 121 Perform Actions as the Root User ..................................... 122 Learn Advanced Techniques .................................... 126 Pipe and Redirect Data ................................................... 126 Get a Grip on grep ......................................................... 130 Add Logic to Shell Scripts ............................................... 133 Install New Software ............................................... 144 Use Command Line Tools for Xcode .................................. 145 Install Unix Software from Scratch ................................... 147 Use a Package Manager .................................................. 151 Learn Command-Line Shortcuts ............................... 159 Terminal Tips and Shortcuts ............................................ 159 Zsh Tips and Shortcuts ................................................... 161 Command-Line Recipes ........................................... 167 Change Defaults ............................................................ 167 Perform Administrative Actions ........................................ 171 Modify Files .................................................................. 177 Work with Information on the Web ................................... 182 Manage Network Activities .............................................. 183 Do More with SSH .......................................................... 187 Work with Remote Macs ................................................. 190 Troubleshoot and Repair Problems ................................... 191 4 Click here to buy the full 215-page “Take Control of the Mac Command Line with Terminal” for only $14.99! Get Help in Style ........................................................... 199 Do Other Random Tricks ................................................. 202 About This Book ...................................................... 210 Ebook Extras ................................................................. 210 About the Author and Publisher ....................................... 211 Also by Joe Kissell ................................................... 213 Copyright and Fine Print .......................................... 215 5 Click here to buy the full 215-page “Take Control of the Mac Command Line with Terminal” for only $14.99! Read Me First Welcome to Take Control of the Mac Command Line with Terminal, Third Edition, version 3.0, published in February 2020 by alt concepts inc. This book was written by Joe Kissell and edited by Geoff Duncan. This book introduces you to the macOS command line environment, teaching you how to use the Terminal utility to accomplish useful, interesting tasks that are either difficult or impossible to perform in the graphical interface. Most of the examples work with 10.6 Snow Leopard and later, although a few techniques require more recent versions of macOS. If you want to share this ebook with a friend, we ask that you do so as you would with a physical book: “lend” it for a quick look, but ask your friend to buy a copy for careful reading or reference. Discounted classroom and user group copies are available. Copyright © 2020, alt concepts inc. All rights reserved. Updates and More You can access extras related to this ebook on the web (use the link in Ebook Extras, near the end; it’s available only to purchasers). On the ebook’s Take Control Extras page, you can: • Download any available new version of the ebook for free, or buy any subsequent