Take Control of the Mac Command Line with Terminal, 3rd Edition

Book description

Learn how to unleash your inner Unix geek!
Version 3.3, updated February 12, 2024

Release your inner geek and harness the power of the Unix underpinnings of macOS! This book from Joe Kissell explains everything you need to know to become comfortable working on the command line in Terminal, and provides numerous "recipes" for performing useful tasks.

If you've ever thought you should learn to use the Unix command line that underlies macOS, or felt at sea when typing commands into Terminal, Joe Kissell is here to help! With this 228-page book, you'll become comfortable working on the Mac's command line, starting with the fundamentals and adding more advanced topics as your knowledge increases.

Joe includes 67 real-life "recipes" for tasks that are best done from the command line, as well as directions for working with permissions, carrying out grep-based searches, creating shell scripts, and installing Unix software.

The book begins by teaching you these core concepts:

  • The differences among Unix, a command line, a shell, and Terminal
  • Exactly how commands, arguments, and flags work
  • The basics of Terminal's interface and how to customize it

Next, it's on to the command line, where you'll learn:

  • How to navigate your Mac's directory structure
  • Basic file management: creating, copying, moving, renaming, opening, viewing, and deleting files
  • Creating symbolic links
  • The types of command-line programs
  • How to start and stop a command-line program
  • How to edit a text file in nano
  • How to customize your prompt and other shell defaults
  • The importance of your PATH and how to change it, if you need to
  • How to get help (Joe goes way beyond telling you to read the man pages)

You'll extend your skills as you discover how to:

  • Create basic shell scripts to automate repetitive tasks.
  • Make shell scripts that have variables, user input, conditional statements, loops, and math.
  • See which programs are running and what system resources they're consuming.
  • Quit programs that refuse to quit normally.
  • Enable the command line to interact with the Finder.
  • Control another Mac via its command line with ssh.
  • Understand and change an item's permissions, owner, and group.
  • Run commands as the root user using sudo.
  • Handle output with pipe (|) or redirect (> or <).
  • Use grep to search for text patterns in files and filter output.
  • Install new command-line software from scratch or with a package manager.
  • Use handy shortcuts in the Terminal app itself and in zsh.

Questions answered include:

  • What changed on the command line in recent versions of macOS?
  • What are the differences between the zsh shell and the bash shell?
  • Which shell am I using, and how can I change my default shell?
  • How do I quickly figure out the path to an item on my Mac?
  • How can I customize my Terminal window so I can see man pages behind it?
  • How can I make a shortcut to avoid retyping the same long command?
  • Is there a trick for entering a long path quickly?
  • What should I say when someone asks if I know how to use vi?
  • How do I change my prompt to suit my mood or needs?
  • What is Command Line Tools for Xcode?
  • When it comes to package managers, which one should I use?

Finally, to help you put it all together, the book showcases 67 real-world "recipes" that combine commands to perform useful tasks, such as listing users who've logged in recently, manipulating graphics, using a separate FileVault password, creating and editing user accounts, figuring out why a disk won't eject, copying the source code of a webpage, determining which apps have open connections to the internet, flushing the DNS cache, finding out why a Mac won't sleep, sending an SMS message, and deleting stubborn items from the Trash.

Table of contents

  1. Read Me First
    1. Updates and More
    2. Basics
    3. Settings vs. Preferences
    4. What’s New in Version 3.3
    5. What Was New in Version 3.2.1
    6. What Was New in Version 3.2
  2. Introduction
  3. macOS Command Line Quick Start
  4. Understand Basic Command-Line Concepts
    1. What’s Unix?
    2. What’s a Command Line?
    3. What’s a Shell?
    4. What’s Terminal?
    5. What Are Commands, Arguments, and Flags?
    6. What Changed in Catalina?
    7. What Changed in Big Sur?
    8. What Changed in Monterey?
    9. What Changed in Ventura?
    10. What Changed in Sonoma?
    11. How to Download Scripting Languages
  5. Get to Know (and Customize) Terminal
    1. Learn the Basics of Terminal
    2. Modify the Window
    3. Open Multiple Sessions
    4. Change the Window’s Attributes
    5. Change Your Current Shell
    6. Set a Default Shell
  6. Look Around
    1. Discover Where You Are
    2. See What’s Here
    3. Repeat a Command
    4. Cancel a Command
    5. Move into Another Directory
    6. Jump Home
    7. Understand How Paths Work
    8. Understand the macOS Directory Structure
    9. Use Tab Completion
    10. Find a File
    11. View a Text File
    12. Get Help
    13. Clear the Screen
    14. End a Shell Session
  7. Work with Files and Directories
    1. Create a File
    2. Create a Directory
    3. Copy a File or Directory
    4. Move or Rename a File or Directory
    5. Delete a File
    6. Delete a Directory
    7. Use Symbolic Links
  8. Work with Programs
    1. Learn Command-Line Program Basics
    2. Run a Program or Script
    3. Run a Program in the Background
    4. See What Programs Are Running
    5. Stop a Program
    6. Edit a Text File
    7. Create Your Own Shell Script
  9. Customize Your Defaults
    1. About Startup Files
    2. Edit .zshrc or .bash_profile
    3. Create Aliases
    4. Modify Your PATH
    5. Change Your Prompt
  10. Bring the Command Line into the Real World
    1. Get the Path of a File or Folder
    2. Open the Current Directory in the Finder
    3. Open a Hidden Directory without Using Terminal
    4. Open the Current Folder in Terminal
    5. Run a Shell Script from the Finder
    6. Open a macOS App
    7. Open a URL
    8. Open a File in macOS
  11. Log In to Another Computer
    1. Start an SSH Session
    2. Run Commands on Another Computer
    3. End an SSH Session
    4. Transfer Files with sftp or scp
  12. Work with Permissions
    1. Understand Permission Basics
    2. Change an Item’s Permissions
    3. Change an Item’s Owner or Group
    4. Perform Actions as the Root User
  13. Learn Advanced Techniques
    1. Pipe and Redirect Data
    2. Get a Grip on grep
    3. Add Logic to Shell Scripts
  14. Install New Software
    1. Use Command Line Tools for Xcode
    2. Install Unix Software from Scratch
    3. Use a Package Manager
  15. Learn Command-Line Shortcuts
    1. Terminal Tips and Shortcuts
    2. Zsh Tips and Shortcuts
  16. Command-Line Recipes
    1. Change Defaults
    2. Perform Administrative Actions
    3. Modify Files
    4. Work with Information on the Web
    5. Manage Network Activities
    6. Do More with SSH
    7. Work with Remote Macs
    8. Troubleshoot and Repair Problems
    9. Get Help in Style
    10. Do Other Random Tricks
  17. About This Book
    1. Ebook Extras
    2. About the Author and Publisher
  18. Also by Joe Kissell
  19. Copyright and Fine Print

Product information

  • Title: Take Control of the Mac Command Line with Terminal, 3rd Edition
  • Author(s): Joe Kissell
  • Release date: February 2024
  • Publisher(s): Take Control Books
  • ISBN: 9781947282513