To access the command line on a MacBook, open the Terminal app via Spotlight search (Command + Space) and type "Terminal". This provides a direct text-based interface to the macOS Unix-based operating system, allowing you to execute system commands, manage files, and run scripts that are not available through the standard graphical user interface (GUI). Note that menu labels and some command behaviors may differ slightly depending on your macOS version or the shell you are using (such as Zsh or Bash).

What You'll Need

  • A MacBook running any current version of macOS.
  • An administrator account password (required for commands that modify system files).
  • Basic familiarity with your file system (knowing where your Documents and Downloads folders are located).

Step-by-Step

  1. Open the Terminal Application: Press Command + Space on your keyboard to launch Spotlight. Type "Terminal" into the search bar and press Enter. The Terminal window will open, displaying a command prompt which typically shows your username and the current working directory.
  2. Understand the Command Prompt: Look at the line ending in a % or $ symbol. This is the prompt. Everything you type to the right of this symbol is a command that the computer will execute once you press Enter.
  3. Check Your Current Location: Type pwd (Print Working Directory) and press Enter. The system will return the full path of the folder you are currently in, such as /Users/YourName. This is crucial because most commands act on the folder you are currently "inside."
  4. List Files in the Current Directory: Type ls and press Enter. This lists all visible files and folders in your current location. To see hidden files (those starting with a dot), type ls -a.
  5. Navigate to a Different Folder: Use the cd (Change Directory) command. For example, to move into your Documents folder, type cd Documents and press Enter. To move back up one level to the parent folder, type cd ...
  6. Create a New Folder: Type mkdir FolderName (replacing "FolderName" with your desired name) and press Enter. You can verify it was created by typing ls again.
  7. Create an Empty File: Type touch filename.txt and press Enter. This creates a blank text file in your current directory.
  8. Read the Contents of a File: To view the text inside a file without opening a separate app, type cat filename.txt. If the file is very long, use less filename.txt, which allows you to scroll through the text using the arrow keys; press q to exit the view.
  9. Move or Rename a File: Use the mv command. To rename a file, type mv oldname.txt newname.txt. To move a file to another folder, type mv filename.txt Documents/.
  10. Copy a File: Type cp source_file.txt destination_folder/. To copy an entire folder and its contents, you must add the recursive flag: cp -r source_folder destination_folder/.
  11. Delete Files or Folders: To remove a file, type rm filename.txt. To remove an empty directory, type rmdir foldername. To remove a directory and everything inside it, type rm -rf foldername. Use extreme caution with rm -rf as it deletes data permanently without sending it to the Trash.
  12. Execute Administrative Commands: Some commands require root privileges. To do this, prefix the command with sudo (SuperUser Do). For example, sudo nano /etc/hosts. After pressing Enter, you will be prompted for your Mac login password. Note that the cursor will not move and no characters will appear as you type your password for security reasons; simply type it and press Enter.

Common Mistakes

One of the most frequent errors for beginners is ignoring case sensitivity. In the macOS Terminal, Documents is not the same as documents. If you type a folder name with the wrong capitalization, you will receive a "No such file or directory" error. Another common mistake is forgetting the space between a command and its argument. For example, typing cdDocuments instead of cd Documents will result in a "command not found" error.

Many users also struggle with file paths containing spaces. If you try to cd My Folder, the Terminal treats "My" as the destination and "Folder" as a separate, confusing argument. To fix this, you must either wrap the path in quotes (cd "My Folder") or use a backslash to escape the space (cd My\ Folder). A pro tip to avoid this is to type the first few letters of the folder and press the Tab key; macOS will automatically complete the name and handle the spaces for you.

Finally, running sudo commands without fully understanding what the command does is a significant risk. Because sudo bypasses standard user permissions, it is possible to delete critical system files that can render the operating system unbootable. Never copy and paste a sudo rm -rf command from an untrusted website without verifying exactly which directory is being targeted.

Tips

To speed up your workflow, master the use of the Tab key for auto-completion. Whether you are typing a filename or a directory path, pressing Tab will fill in the rest of the word if there is only one match. If there are multiple matches, pressing Tab twice will list all possible options.

Use the history command to see a list of all commands you have previously entered in the current session. If you need to run a complex command again, you can use the up and down arrow keys to cycle through your recent history instead of retyping the entire string. To clear the screen when it becomes cluttered with text, type clear or press Command + K.

If you find yourself frequently navigating to a deep folder (e.g., /Users/Name/Documents/Projects/2026/Work), you can create a shortcut called an alias. Type alias work="cd /Users/Name/Documents/Projects/2026/Work". Now, whenever you type work and press Enter, the Terminal will jump straight to that directory. To make aliases permanent, you would need to add them to your shell configuration file, typically .zshrc for modern macOS versions.

Troubleshooting

If you receive a "Permission Denied" error, it means your current user account does not have the authority to modify that file or folder. The first step is to check if you are the owner of the file. If the file is a system file, try prefixing the command with sudo. If you are still blocked, check the System Settings > Privacy & Security > Full Disk Access section and ensure that Terminal is toggled "On." macOS protects sensitive areas like Mail, Messages, and Safari data even from the command line unless explicit permission is granted.

If a command seems to be "hanging" or running indefinitely without returning to the prompt, you can force it to stop by pressing Control + C. This sends an interrupt signal to the process and returns you to the command prompt. If the entire Terminal app becomes unresponsive, use Option + Command + Esc to bring up the Force Quit menu and restart the application.

When you encounter a "command not found" error for a tool you believe is installed (like git or python), it usually means the tool is not in your system's PATH. The PATH is a list of directories the shell searches through to find executable files. You can check your current path by typing echo $PATH. If a tool is missing, you may need to install the Xcode Command Line Tools by typing xcode-select --install and following the on-screen prompts to download the necessary developer utilities.

Frequently Asked Questions

What is the difference between Zsh and Bash?

Zsh (Z shell) is the default shell for macOS in recent versions, while Bash was the default in older versions. Zsh is largely compatible with Bash but offers more advanced features like better auto-completion, plugin support (via Oh My Zsh), and more customizable prompts.

Can I recover files deleted with the rm command?

No. Unlike dragging a file to the Trash in the Finder, the rm command deletes the file immediately from the file system index. Unless you have a Time Machine backup or a third-party data recovery tool, files deleted via Terminal are generally unrecoverable.

How do I know if a command is safe to run?

Avoid running any command that starts with sudo rm -rf / or contains complex pipes (|) and redirects (>) if you do not understand each part. Use a "man page" by typing man [command] (e.g., man ls) to read the official manual for any command before using it.

Why does the screen not show my password when I use sudo?

This is a standard security feature in Unix-based systems called "silent password entry." It prevents anyone looking over your shoulder from seeing how many characters are in your password. Just type the password blindly and press Enter.

How do I exit the Terminal?

You can close the current session by typing exit and pressing Enter, or you can quit the entire application by pressing Command + Q.