Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Mac Command Prompt: How to Find and Use Terminal on macOS

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To use the Mac version of the command prompt, open the Terminal app. Terminal is a built-in macOS utility that provides a command-line interface (CLI), allowing you to interact directly with the underlying Unix-based operating system using text commands instead of clicking icons in a graphical user interface (GUI). Because macOS is built on a Unix foundation, the commands used in Terminal are based on Zsh (the default shell in modern macOS) or Bash, which differ significantly from the commands used in the Windows Command Prompt (CMD).

What You'll Need

  • A Mac computer running any current version of macOS.
  • An administrator account password (required only for commands that modify system-level files).

Step-by-Step

  1. Open the Terminal Application
    There are two primary ways to launch Terminal. The fastest method is using Spotlight: press Command + Space on your keyboard, type "Terminal" into the search bar, and press Enter. Alternatively, you can find it manually by opening Finder, selecting Applications from the sidebar, opening the Utilities folder, and double-clicking the Terminal icon. Note that menu labels and folder locations can differ slightly depending on your macOS version or region.
  2. Understand the Command Prompt
    Once the window opens, you will see a line of text ending in a percent sign (%) or a dollar sign ($). This is the prompt. It typically displays your current username, the name of your computer, and the directory (folder) you are currently in. The flashing cursor indicates that the system is ready to receive a command. You must type a command and press Enter to execute it.
  3. Check Your Current Location (pwd)
    Before moving files or creating folders, it is important to know where you are in the system hierarchy. Type pwd (which stands for "print working directory") and press Enter. Terminal will display the full path to the folder you are currently accessing, such as /Users/yourusername. This is your home directory.
  4. List Files and Folders (ls)
    To see what is inside your current directory, type ls and press Enter. This will list all visible files and folders. To see more detail, such as file sizes and modification dates, use ls -l. To see hidden files (files that start with a dot, which are usually configuration files), use ls -a. Combining these as ls -la provides a comprehensive list of all files with full details.
  5. Navigate Between Folders (cd)
    To move from one folder to another, use the cd (change directory) command. For example, to enter your Documents folder, type cd Documents and press Enter. To move back up one level to the parent folder, type cd .. and press Enter. If you want to return immediately to your home directory from anywhere in the system, simply type cd and press Enter.
  6. Create a New Folder (mkdir)
    To create a new directory, use the mkdir (make directory) command followed by the name you want to give the folder. For example, type mkdir MyTestFolder and press Enter. You can verify the folder was created by running the ls command again.
  7. Create an Empty File (touch)
    To create a new, empty text file, use the touch command. For example, type touch notes.txt and press Enter. This creates a file named "notes.txt" in your current working directory.
  8. Run Commands as an Administrator (sudo)
    Some system files are protected and cannot be modified by a standard user. To perform these actions, use sudo (superuser do) before your command. For example, sudo nano /etc/hosts allows you to edit the system hosts file. After pressing Enter, Terminal will ask for your Mac login password. As you type the password, no characters or asterisks will appear on the screen for security reasons; simply type the password and press Enter.

Common Mistakes

  • Using Windows Commands: A frequent error for those switching from PC is using dir to list files or cls to clear the screen. On Mac, you must use ls and clear, respectively.
  • Ignoring Case Sensitivity: While the macOS file system is often case-insensitive, the shell commands themselves are case-sensitive. Typing LS instead of ls will result in a "command not found" error.
  • Handling Spaces in File Names: If a folder is named "My Projects", typing cd My Projects will fail because the shell thinks "Projects" is a separate argument. You must either wrap the path in quotes (cd "My Projects") or use a backslash to escape the space (cd My\ Projects).
  • Running Dangerous Commands: Using sudo rm -rf / is a critical mistake that can delete your entire hard drive. Never run commands starting with sudo rm -rf unless you are absolutely certain of the specific directory path you are targeting.

Tips

  • Use Tab Completion: You do not have to type out long folder names. Type the first few letters of a file or folder and press the Tab key. Terminal will automatically fill in the rest of the name. If multiple files start with the same letters, press Tab twice to see a list of options.
  • Access Command History: Instead of retyping a long command, use the Up Arrow and Down Arrow keys to scroll through the history of commands you have previously entered in the current session.
  • Use the Manual (man): If you are unsure how a specific command works or what flags it supports, type man followed by the command name (e.g., man ls). This opens the official manual page. Press q to exit the manual and return to the prompt.
  • Drag and Drop Paths: If you need to target a file or folder but the path is too complex to type, type your command (like cd), add a space, and then drag the folder from the Finder window directly into the Terminal window. macOS will automatically paste the exact file path for you.

Troubleshooting

If Terminal is not behaving as expected, try these steps in order:

  • "Permission Denied": This occurs when you try to modify a file owned by the system or another user. Ensure you are using sudo at the beginning of the command. If you still get this error, check the file permissions in Finder by right-clicking the file and selecting Get Info.
  • "Command Not Found": This usually means there is a typo in the command or the utility you are trying to use is not installed. Double-check the spelling and ensure you aren't using a Windows-specific command.
  • Terminal is Frozen: If a command is taking too long or seems to have hung the session, press Control + C. This sends an interrupt signal to the current process and forces it to stop, returning you to the command prompt.
  • Screen is Cluttered: If the window is filled with text and hard to read, type clear and press Enter to wipe the visible screen and start fresh at the top.

Frequently Asked Questions

What is the difference between Bash and Zsh?

Bash and Zsh are both "shells" that interpret your commands. Zsh is the default in modern macOS because it offers more advanced features like better auto-completion and customization. For most basic users, the commands are identical.

Is it safe to use Terminal?

Terminal is safe as long as you know what the commands do. Because it bypasses the safety warnings of the GUI, it is possible to delete critical system files. Always double-check commands found online before running them, especially those using sudo.

How do I close Terminal completely?

You can type exit and press Enter to end the current session, then press Command + Q to quit the application. Simply closing the window with the red X does not always stop the processes running inside the session.

Can I change the look of the Terminal?

Yes. Open Terminal and go to Terminal > Settings (or Preferences) in the top menu bar. Under the Profiles tab, you can change the background color, text font, and cursor style to make the interface more readable.

How do I run a script file in Terminal?

To run a script, you generally need to navigate to the folder containing the file using cd, make the file executable using chmod +x filename.sh, and then execute it by typing ./filename.sh.