Apple Support 247 is an independent publication not affiliated with Apple Inc.

Mac Errors

Easy Way to Fix Error 2: No Such File or Directory on Mac

Lena HartmannUpdated 2026-09-016 min read

The macOS Terminal is an incredibly powerful tool that allows you to interact directly with the deepest layers of your operating system. But if you aren't familiar with command-line interfaces, it can also be incredibly literal and unforgiving. One of the most common roadblocks new (and experienced) users hit is the dreaded "Error 2: No such file or directory" message.

Unlike complex hardware failures or deep system corruption, Error 2 is almost always a simple case of miscommunication. You are telling your Mac to do something to a file, and your Mac is telling you that it cannot find the file where you said it would be.

In this guide, we will explain exactly why this error occurs, teach you how macOS understands file paths, and provide a foolproof, easy method to fix the error so your Terminal commands execute perfectly every time.

What Does "No Such File or Directory" Mean?

When you type a command into Terminal—whether you are trying to install software via Homebrew, run a Python script, or simply change directories using the cd command—you must provide the exact location (the "path") of the file or folder you want the command to affect.

If you receive Error 2: No such file or directory, the Terminal is essentially saying: "I went to the exact address you typed in, and the file you asked for is not there."

This happens for three main reasons:

  1. Typos: You misspelled the name of the file or folder in your command. Terminal is case-sensitive, so "Documents" and "documents" are viewed as entirely different locations.
  2. Spaces in File Names: If a file is named My Script.py, Terminal reads the space as the end of the file name. It will look for a file called "My" and fail.
  3. Relative vs. Absolute Paths: You provided a "Relative" path (assuming Terminal knows what folder you are currently in) when you actually needed to provide an "Absolute" path (the full address starting from the root of your hard drive).

The Easy Fix: The Drag-and-Drop Method

If you are struggling to get the file path exactly right in Terminal, there is a built-in macOS trick that completely eliminates the need to type paths manually. It is fast, foolproof, and completely avoids Error 2.

Step-by-step guide to the drag-and-drop method:

  1. Open the Terminal app on your Mac.
  2. Type the first part of your command (e.g., cd or python3 or chmod +x ). Make sure to include a single space after the command.
  3. Leave the Terminal window open and open Finder.
  4. Locate the exact file or folder you are trying to target in Finder.
  5. Click on the file or folder in Finder, and drag it directly into the Terminal window.
  6. Release the mouse button. Terminal will automatically paste the 100% correct, fully formatted Absolute Path of that file right where your cursor is.
  7. Press Return to execute the command.

Because macOS automatically formats the path (including adding necessary escape characters for spaces and special symbols), you will never get a "No such file" error using this method, provided the file actually exists.

How to Fix File Name Spaces (The Backslash Trick)

If you prefer to type out your commands manually, you need to know how Terminal handles spaces in file names. As mentioned earlier, if you type cd My Folder, Terminal thinks you are trying to change directory to a folder called "My" and passing a second argument called "Folder". It will instantly throw an Error 2 because a folder named just "My" doesn't exist.

To fix this, you must "escape" the space. You do this by putting a backslash (\) directly before the space.

Incorrect: cd /Users/Name/Documents/My Folder
Correct: cd /Users/Name/Documents/My\ Folder

Alternatively, you can wrap the entire path in quotation marks, which tells Terminal to treat everything inside the quotes as a single string.

Correct: cd "/Users/Name/Documents/My Folder"

Understanding Relative vs. Absolute Paths

If you typed the name of the file perfectly, with no spaces, and you are still getting Error 2, you are likely experiencing a pathing context issue. You need to understand the difference between Absolute and Relative paths.

Absolute Paths

An Absolute path is the full, complete address of a file, starting from the very root of your Mac's hard drive. It always begins with a forward slash (/) or a tilde (~, which represents your specific User folder).

Example: /Users/JohnDoe/Documents/script.py

An Absolute path will work no matter what directory you are currently in because it provides the full map to the file.

Relative Paths

A Relative path is a shortcut. It only provides the address of a file relative to the folder Terminal is currently looking at. It does not start with a slash.

Example: Documents/script.py

If you open Terminal, you are usually dropped into your Home folder (/Users/JohnDoe/) by default. If you type the Relative path Documents/script.py, Terminal looks inside your Home folder for "Documents", finds it, and runs the script. It works perfectly.

However, if you previously used the cd command to move into your "Downloads" folder, and then typed Documents/script.py, Terminal will look for a "Documents" folder inside the Downloads folder. When it doesn't find one, it throws Error 2.

The Fix: If you are getting Error 2, stop using Relative paths. Either use the Drag-and-Drop method described above to generate an Absolute path, or use the cd command to navigate exactly to the folder where the file lives before trying to run the file.

Checking if the File Actually Exists

Sometimes, Error 2 happens because the file has literally been moved, deleted, or you haven't installed the software you think you have. If you are following a tutorial that tells you to run a specific command and it fails, you should verify the file exists.

You can use the ls command to list the contents of your current directory:

  1. Open Terminal.
  2. Navigate to the folder where you think the file is using cd.
  3. Type ls -la and press Return.
  4. Terminal will print a list of every file and folder in that directory (including hidden files).

Read through the list. If the file you are looking for isn't there, you have found the reason for Error 2. You will need to locate the file in Finder, redownload it, or reinstall the software.

Conclusion

Terminal Error 2: "No such file or directory" is nothing more than a strict spelling and grammar check by your Mac. The file path must be flawless. By utilizing the drag-and-drop shortcut, escaping spaces with backslashes, and understanding the difference between relative and absolute paths, you can easily banish this error and navigate the macOS command line with confidence.

Frequently asked questions

Sources and further reading

Portrait of a technology writer in an office

Lena Hartmann

Device-help editor

Device-help editor at Apple Support 247. Lena edits troubleshooting guides for clarity, accuracy and safe sequencing of steps.

View profile →

Apple Support 247 is an independent publication and is not affiliated with Apple Inc. Apple, Mac, MacBook, iPhone and other Apple marks are trademarks of Apple Inc.

The 247 Fix

Practical Apple troubleshooting guides, weekly.