keepcalculator

06 Numbers and Powers

Mac Terminal Basics: A Beginner’s Guide

Card No. 06·75268 · Updated · Standard formula, shown below

This guide explains how to use the Mac Terminal for the first time: what it is, how to open it, and the essential commands you need to navigate files and folders. You’ll learn the core commands, how to run a command safely, and how to avoid common mistakes. By the end, you’ll be comfortable moving around your Mac and performing basic file operations from the command line.

What Is the Terminal?

The Terminal is a built-in macOS app that gives you a text-based interface to your computer. Instead of clicking icons and menus, you type commands to tell the system what to do. It’s a powerful tool used by developers, system administrators, and power users to perform tasks quickly, automate repetitive work, and access features not available in the graphical interface. While it may look intimidating, the basics are simple and safe to learn.

Opening the Terminal

You can open Terminal in a few ways:

  • Open Finder, go to Applications > Utilities, and double-click Terminal.
  • Use Spotlight (press Cmd + Space), type “Terminal”, and press Return.
  • If you use Launchpad, find the Terminal icon (it’s a black box with a white prompt).

Once open, you’ll see a window with a prompt, usually ending in $ (or % depending on your shell). This is where you type commands.

The Prompt and Basic Syntax

The prompt shows that the shell is ready for input. A typical prompt looks like:

mycomputer:~ username$

Here, ~ means you are in your home directory (e.g., /Users/username). The $ indicates you are a normal user (not root). Commands follow a simple structure: command [options] [arguments]. For example, ls -la Documents lists all files in the Documents folder, including hidden ones, with details.

Essential Commands: Navigation and Files

Here are the commands you’ll use most often:

  • pwd – Print working directory. Shows your current path.
  • ls – List files and folders in the current directory. Add -l for details, -a to show hidden files, and -h for human-readable sizes.
  • cd – Change directory. Example: cd Documents moves into the Documents folder. Use cd .. to go up one level, and cd ~ to go to your home directory.
  • mkdir – Create a new folder. Example: mkdir Projects.
  • touch – Create a new empty file. Example: touch notes.txt.
  • cp – Copy files or folders. Example: cp file.txt backup.txt.
  • mv – Move or rename files. Example: mv old.txt new.txt.
  • rm – Delete files or folders. Use rm -r to delete a folder and its contents. Be careful: this is permanent and doesn’t go to Trash.

Working with Text and Getting Help

To view a file’s contents, use cat filename (prints the whole file) or less filename (lets you scroll through). To edit a file, you can use nano filename, which opens a simple text editor in the Terminal. To get help on any command, type man command (e.g., man ls) to open the manual page. Press q to quit.

Common Tasks and Examples

Let’s put these together for real-world tasks:

  • Create a project folder and a file inside it:
    mkdir MyProject
    cd MyProject
    touch README.md
  • Copy a file from your Desktop to Documents:
    cp ~/Desktop/report.pdf ~/Documents/
  • Rename a file:
    mv draft.txt final.txt
  • Delete a file (be careful):
    rm oldfile.txt

Common Mistakes and How to Avoid Them

Beginners often make these errors:

  • Spacing mistakes: Commands are case-sensitive. CD won’t work; it must be cd.
  • Using rm without care: Always double-check the path. rm -rf is extremely powerful and can delete your entire system if used incorrectly. Never run it unless you are absolutely sure.
  • Spaces in filenames: If a filename has spaces, quote it: cd "My Folder" or escape the space with a backslash: cd My\ Folder.
  • Forgetting to use cd before running commands: You might be in the wrong directory. Use pwd to check.

Frequently Asked Questions

Is using Terminal dangerous?

It can be if you run commands you don’t understand. However, the basic commands like ls, cd, and mkdir are harmless. The main risk is with rm and commands that modify system settings. Always research a command before running it, and never paste a command from a random website without knowing what it does.

What is the difference between Terminal and a shell?

Terminal is the app that provides the window and text interface. The shell is the program inside it that interprets your commands. macOS uses zsh (Z shell) as the default since Catalina (2019). Bash is also available if you need it.

How do I quit Terminal?

You can type exit or press Cmd + Q. If a process is running, you might need to press Ctrl + C to interrupt it first.

Can I undo a command I just ran?

No, there is no general undo. For file operations, if you deleted a file with rm, it’s gone (unless you had a backup). This is why it’s crucial to be careful. You can use mv to rename instead of delete if you’re unsure.

How do I copy and paste in Terminal?

You can use Cmd + C and Cmd + V as usual. To copy from the Terminal, select text with the mouse and press Cmd + C. To paste, press Cmd + V. You can also drag and drop a file onto the Terminal window to insert its path.

Next Steps

Once you’re comfortable with these basics, you can explore more: use grep to search inside files, find to locate files, and chmod to change permissions. The Terminal is a lifelong tool—practice on a test folder until you feel confident. Remember, the command line is just another way to interact with your Mac; it’s not magic, and with a little practice, it becomes second nature.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →