Take Control of the Mac Command Line with Terminal

Total Page:16

File Type:pdf, Size:1020Kb

Take Control of the Mac Command Line with Terminal 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
Recommended publications
  • Introduction to Xgrid: Cluster Computing for Everyone
    Introduction to Xgrid: Cluster Computing for Everyone Barbara J. Breen1, John F. Lindner2 1Department of Physics, University of Portland, Portland, Oregon 97203 2Department of Physics, The College of Wooster, Wooster, Ohio 44691 (First posted 4 January 2007; last revised 24 July 2007) Xgrid is the first distributed computing architecture built into a desktop operating system. It allows you to run a single job across multiple computers at once. All you need is at least one Macintosh computer running Mac OS X v10.4 or later. (Mac OS X Server is not required.) We provide explicit instructions and example code to get you started, including examples of how to distribute your computing jobs, even if your initial cluster consists of just two old laptops in your basement. 1. INTRODUCTION Apple’s Xgrid technology enables you to readily convert any ad hoc collection of Macintosh computers into a low-cost supercomputing cluster. Xgrid functionality is integrated into every copy of Mac OS X v10.4. For more information, visit http://www.apple.com/macosx/features/xgrid/. In this article, we show how to unlock this functionality. In Section 2, we guide you through setting up the cluster. In Section 3, we illustrate two simple ways to distribute jobs across the cluster: shell scripts and batch files. We don’t assume you know what shell scripts, batch files, or C/C++ programs are (although you will need to learn). Instead, we supply explicit, practical examples. 2. SETTING UP THE CLUSTER In a typical cluster of three or more computers (or processors), a client computer requests a job from the controller computer, which assigns an agent computer to perform it.
    [Show full text]
  • How to Disable Gatekeeper and Allow Apps from Anywhere in Macos Sierra
    How to Disable Gatekeeper and Allow Apps From Anywhere in macOS Sierra Gatekeeper, first introduced in OS X Mountain Lion, is a Mac security feature which prevents the user from launching potentially harmful applications. In macOS Sierra, however, Apple made some important changes to Gatekeeper that seemingly limit the choices of power users. But don’t worry, Gatekeeper can still be disabled in Sierra. Here’s how. Stand out at the party or promote your business with colorful powder coated and custom engraved Yeti tumblers from Perfect Etch. Traditionally, Gatekeeper offered three settings of increasing security: anywhere, App Store and identified developers, and App Store only. The first choice, as its name describes, allowed users to launch applications from any source, effectively disabling the Gatekeeper feature. The second choice allowed users to run apps from the Mac App Store as well as from software developers who have registered with Apple and securely sign their applications. Finally, the most secure setting limited users to running apps obtained from the Mac App Store only. While the secure options were good ideas for less experienced Mac users, power users found Gatekeeper to be too limiting and typically sought to disable it by setting it to “Anywhere.” In macOS Sierra, however, the “Anywhere” option is gone, leaving “App Store” and “App Store and identified developers” as the only two options. Disable Gatekeeper in macOS Sierra The Gatekeeper settings can be found in System Preferences > Security & Privacy > General. The Gatekeeper options are located beneath “All apps downloaded from:” with the choice of “Anywhere” missing. Thankfully, the “Anywhere” setting can be restored to Gatekeeper in Sierra with a Terminal command.
    [Show full text]
  • When You Can't Be There in Person
    When You Can’t Be There in Person Virtual visitation can open a door into your child’s world BY CHRISTINA S. GLENN & DENISE HALLMARK eparation and divorce will change a parent’s lifestyle in a multitude of ways, but most profoundly, in the amount of time spent with children. With so many divorces in the United States and so many couples deciding to have children, S Published in Family Advocate, Vol. 38, No. 1, but not to marry, more and more children will live apart from at least one parent, (Summer 2015) p. 19-21. © 2015 by the more commonly the father, at some point in their lives. The growth in the number of American Bar Association. Reproduced with permission. All rights reserved. This information noncustodial fathers (that is, the parent who lives apart from the children) has been or any portion thereof may not be copied or disseminated in any form or by any means or accompanied by concerns that a father’s absence can have severe and long-lasting stored in an electronic database or retrieval consequences for a child’s well-being. A noncustodial parent’s access can be even system without the express written consent of the American Bar Association. more problematic when the child lives far away. The good news is that modern technology, in the form of virtual parenting time, offers at least a partial solution to the problem of long-distance parenting. Virtual parenting time allows a parent to stay connected with his or her children electronically through e-mail, instant messaging, texting, phone calls, and video conferencing.
    [Show full text]
  • Open Directory Administration for Version 10.5 Leopard Second Edition
    Mac OS X Server Open Directory Administration For Version 10.5 Leopard Second Edition Apple Inc. © 2008 Apple Inc. All rights reserved. The owner or authorized user of a valid copy of Mac OS X Server software may reproduce this publication for the purpose of learning to use such software. No part of this publication may be reproduced or transmitted for commercial purposes, such as selling copies of this publication or for providing paid-for support services. Every effort has been made to make sure that the information in this manual is correct. Apple Inc., is not responsible for printing or clerical errors. Apple 1 Infinite Loop Cupertino CA 95014-2084 www.apple.com The Apple logo is a trademark of Apple Inc., registered in the U.S. and other countries. Use of the “keyboard” Apple logo (Option-Shift-K) for commercial purposes without the prior written consent of Apple may constitute trademark infringement and unfair competition in violation of federal and state laws. Apple, the Apple logo, iCal, iChat, Leopard, Mac, Macintosh, QuickTime, Xgrid, and Xserve are trademarks of Apple Inc., registered in the U.S. and other countries. Finder is a trademark of Apple Inc. Adobe and PostScript are trademarks of Adobe Systems Incorporated. UNIX is a registered trademark of The Open Group. Other company and product names mentioned herein are trademarks of their respective companies. Mention of third-party products is for informational purposes only and constitutes neither an endorsement nor a recommendation. Apple assumes no responsibility with regard to the performance or use of these products.
    [Show full text]
  • Tour of the Terminal: Using Unix Or Mac OS X Command-Line
    Tour of the Terminal: Using Unix or Mac OS X Command-Line hostabc.princeton.edu% date Mon May 5 09:30:00 EDT 2014 hostabc.princeton.edu% who | wc –l 12 hostabc.princeton.edu% Dawn Koffman Office of Population Research Princeton University May 2014 Tour of the Terminal: Using Unix or Mac OS X Command Line • Introduction • Files • Directories • Commands • Shell Programs • Stream Editor: sed 2 Introduction • Operating Systems • Command-Line Interface • Shell • Unix Philosophy • Command Execution Cycle • Command History 3 Command-Line Interface user operating system computer (human ) (software) (hardware) command- programs kernel line (text (manages interface editors, computing compilers, resources: commands - memory for working - hard-drive cpu with file - time) memory system, point-and- hard-drive many other click (gui) utilites) interface 4 Comparison command-line interface point-and-click interface - may have steeper learning curve, - may be more intuitive, BUT provides constructs that can BUT can also be much more make many tasks very easy human-manual-labor intensive - scales up very well when - often does not scale up well when have lots of: have lots of: data data programs programs tasks to accomplish tasks to accomplish 5 Shell Command-line interface provided by Unix and Mac OS X is called a shell a shell: - prompts user for commands - interprets user commands - passes them onto the rest of the operating system which is hidden from the user How do you access a shell ? - if you have an account on a machine running Unix or Linux , just log in. A default shell will be running. - if you are using a Mac, run the Terminal app.
    [Show full text]
  • Make a Bootable USB Drive OS X 10.8 Mountain Lion Recovery
    Make a Bootable USB Drive of OS X 10.8 Mountain Lion from the Recovery Hard Drive On every OS X 10.8 Mountain Lion there is a hidden partition to enable a method for Mountain Lion OS to be reinstalled on the machine, it is known as the Recovery Par- tition or drive and is 650mb in size. If you bought a new machine from Apple you have OS X 10.8 already installed – but no back up disk! and since you haven’t bought the OSX Lion 10.8 App from the App store you can’t re-download it – so thats why you have the recovery drive as a parti- tion in your main hard drive, to boot from it you need to restart the machine and when it starts to boot hold down “command” + “r” keys. From the Recovery Partition Hard Drivr you can run Disk Utility, access the com- mand line, get online help and do a restore from a Time Machine backup and re-in- stall Mountain Lion leaving all your other files intact – it just replaces the core oper- ating system. You can make a bootable USB drive or disk from the Recovery Partition 2 ways – the easy way and on the Terminal The Easy Way 1) Download OSX Recovery Disk Assistant and uncompress and launch it 2) Attach the USB drive that you want to copy the Recovery Partition to. 3) Select the drive and continue (All contents on it will be erased) That’s it one external bootable Recovery Drive – this works on both OSX 10.7 and 10.8 The Terminal Way 1) Launch Terminal from /Applications/Utilities and run: diskutil list The main drive in this list is No.2 with the “Identifier” of disk0s2, the boot Recovery HD drive is disk0s3 disk-util-list-drives We can also identify the Recovery drive by the name and the size – set at 650mb 2) Mount the drive by its Identifier: diskutil mount /dev/disk0s3 Output should be: Volume Recovery HD on /dev/disk0s3 mounted Now the Recovery HD is mounted in the Finder and you can see it in the sidebar un- der Devices Navigate to it from the sidebar – Recovery HD/com.apple.recovery.boot/BaseSys- tem.dmg recovery-finder-osx-lion 3) Doubleclick BaseSystem.dmg to mount it also in the sidebar.
    [Show full text]
  • 1 Avid Support Mac Cheatsheet, Ver 1.8.1 Covers up To: Media
    Ver 1.8 Updated: 10/21/08 Avid Support Mac CheatSheet, Ver 1.8.1 Covers up to: Media Composer 3.1 // Xpress Pro 5.8// Symphony 3.1 Topic: Page: Current Version Notes: 2 Apple OS X / Quicktime Compatibility 2 • Supported Editor versions 3 • Supported Quicktime versions 3 • Supported OS versions 3 OS X Leopard information 3 Supported Computers: • Mac Laptops 3 • Mac Workstations 5 Macintosh Slot configurations 7 Firewire Card support 10 Dongle Support and Information 12 • Dongle Manager (NEW) • Dongle Compatibility • How do I know what versions of software require a dongle updater? Troubleshooting Suggestions 13 .DS_Store files and You 18 DIY Information & Related Links: 21 QuickTime Links & Notes 21 How do I uninstall QuickTime? 22 Mac Editors and Unity Information 23 The attached document has been created by Avid Customer Support it's written with the knowledge we have gained working with our customers contacting the Avid Customer Support team. It is intended to help properly configure and troubleshoot Mac editing systems - both PowerPC and Intel- based. Included are some tips and tricks to maximize performance and stability of your system. Follow the tips in the document and the initial installation and configuration will be very simple. We want this to be a "living doc", updated and changed as Apple and Avid products evolve. Please use the feedback button below to let us know what you think. If you are less than 100% satisfied with the document you will be presented with a form to send comments or corrections. Use a made up email address if anonymity is desired.
    [Show full text]
  • Mac OS X Terminal Basics V2.1.2
    Mac OS X Terminal Basics v2.1.2 Neal Parikh / [email protected] / www.nparikh.org February 11, 2003 1 Table of Contents 1. Table of Contents 2. Introduction 3. Why Unix? 4. What’s Darwin? 5. Basics of Darwin 6. Introduction to shells 7. Running system commands 8. Basic shell customization 9. Permissions 10. Running programs 11. What’s NetInfo? 12. Basics of compilation 13. Process Management 14. Introduction to text editors: Pico, Emacs, and Vi 15. Introduction to X Windows / X11 1 2 Introduction This FAQ is intended to be a quick primer on Mac OS X’s BSD Subsystem. The BSD Subsystem is a powerful tool that gives you an immense array of new capabilities and access to a large number of new applications. If you learn to use them wisely, you can do some truly incredible things. 3 Why Unix? That is the main question, isn’t it? Many people are confused as to why Apple has picked Unix in the first place. There are several reasons why Apple has picked Unix to be the core of their new OS (not in order of importance): 1. The historical reason: Mac OS X’s roots trace back to NeXTSTEP, and that used Unix. 2. Developers who may be unfamiliar with the Mac platform will likely have some level of familiarity with Unix, which aids porting efforts. 3. Most users who have studied computer science in either school or college have encountered Unix on some level, and must have some basic familiarity with it. 4. There’s a reason almost every server in the world runs Unix.
    [Show full text]
  • Cocoa® Programming for Mac® Os X
    COCOA® PROGRAMMING FOR MAC® OS X FOURTH EDITION This page intentionally left blank COCOA® PROGRAMMING FOR MAC® OS X FOURTH EDITION Aaron Hillegass Adam Preble Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact: U.S. Corporate and Government Sales (800) 382-3419 [email protected] For sales outside the United States, please contact: International Sales [email protected] Visit us on the Web: informit.com/aw Library of Congress Cataloging-in-Publication Data Hillegass, Aaron. Cocoa programming for Mac OS X / Aaron Hillegass, Adam Preble.—4th ed. p. cm. Includes index. ISBN 978-0-321-77408-8 (pbk. : alk.
    [Show full text]
  • Setting up Mac OS X 10.4 Server and Clients for Xgrid, Xgrid Enabled Openmpi, LAM-MPI, and MPICH2
    Setting Up Mac OS X 10.4 Server and Clients for Xgrid, Xgrid Enabled OpenMPI, LAM-MPI, and MPICH2 Gergely V. Záruba [email protected] Version: 2007-09-10 Abstract - In this document we outline some simple (and sometimes slightly dirty) methods for setting up a MAC OS X 10.4 cluster for Xgrid (SETI@home style processing) and three popular versions of MPI, i.e., OpenMPI, LAM-MPI, and MPICH2. Our sample setup consists of one MAC OS X 10.4 server and three MAC OS X 10.4 (client) Intel based MAC Mini computers. There are many resources available on the Internet that try to make parts of such installations documented, however many of them do not work on OS X 10.4, do not provide enough information, or provide too much information (thus obfuscating the essence). We will try to make this document a usable reference for an average computer user with some general *nix and/or MAC user interface knowledge. This document is by far not a complete or a comprehensive guide to Mac OS 10.4 and in many cases we will use some tricks to get to our goal. There obviously is no liability assumed for any of the procedures described below and many of them do not consider security to be a major problem as our cluster is sitting behind a firewalled NAT router. 1. Introduction We will start our journey with some notes on installing MAC OS X 10.4 Server (from now on referred to as S10.4). Next we describe setting up Xgrid.
    [Show full text]
  • Mac OS X Server 10.4 File Services (Manual)
    Mac OS X Server File Services Administration For Version 10.4 or Later K Apple Computer, Inc. © 2005 Apple Computer, Inc. All rights reserved. The owner or authorized user of a valid copy of Mac OS X Server software may reproduce this publication for the purpose of learning to use such software. No part of this publication may be reproduced or transmitted for commercial purposes, such as selling copies of this publication or for providing paid-for support services. Every effort has been made to ensure that the information in this manual is accurate. Apple Computer, Inc., is not responsible for printing or clerical errors. Apple 1 Infinite Loop Cupertino CA 95014-2084 www.apple.com The Apple logo is a trademark of Apple Computer, Inc., registered in the U.S. and other countries. Use of the “keyboard” Apple logo (Option-Shift-K) for commercial purposes without the prior written consent of Apple may constitute trademark infringement and unfair competition in violation of federal and state laws. Apple, the Apple logo, AppleShare, AppleTalk, Mac, Macintosh, QuickTime, Xgrid, and Xserve are trademarks of Apple Computer, Inc., registered in the U.S. and other countries. Finder is a trademark of Apple Computer, Inc. Adobe and PostScript are trademarks of Adobe Systems Incorporated. UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company, Ltd. Other company and product names mentioned herein are trademarks of their respective companies. Mention of third-party products is for informational purposes only and constitutes neither an endorsement nor a recommendation.
    [Show full text]
  • Cocoa® Programming Developer's Handbook
    Cocoa® Programming Developer’s Handbook This page intentionally left blank Cocoa® Programming Developer’s Handbook David Chisnall Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City Cocoa® Programming Developer’s Handbook Editor-in-Chief Copyright © 2010 Pearson Education, Inc. Mark L. Taub All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, Managing Editor or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, John Fuller without written permission from the publisher. No patent liability is assumed with respect to Full-Service the use of the information contained herein. Although every precaution has been taken in Production the preparation of this book, the publisher and author assume no responsibility for errors Manager or omissions. Nor is any liability assumed for damages resulting from the use of the Julie B. Nahil information contained herein. Technical Reviewer ISBN-13: 978-0-321-63963-9 Gregory ISBN-10: 0-321-63963-4 Casamento Book Designer Library of Congress Cataloging-in-Publication Data Gary Adair Chisnall, David. Composition Cocoa programming developer’s handbook / David Chisnall. David Chisnall p. cm. Includes index. ISBN 978-0-321-63963-9 (pbk. : alk. paper) 1. Cocoa (Application development environment) 2. Object-oriented programming (Computer science) 3. Application program interfaces (Computer software) 4. Mac OS. I. Title. QA76.64.C485 2010 005.26’8—dc22 2009042661 Printed in the United States on recycled paper at Edwards Brothers in Ann Arbor, Michigan. First Printing December 2009 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized.
    [Show full text]