How to fix the "operation not permitted" error in Terminal

5 min read

Unable to execute commands in Terminal because of the "ls: .: operation not permitted" error message? Although irritating, it's not entirely uncommon to encounter error messages within Terminal, and luckily, we've got the fixes you need for this particular error right here.

Terminal is possibly one of the least used but most powerful tools on our MacBooks, unnecessarily feared by many. Once you know how to use it, you'll never look back.

To put it simply, Terminal enables text-based access to your operating system so that you can control, customize and manage your Mac.

Why does Terminal say "operation not permitted" on Mac?

Essentially the Mac "ls operation not permitted" error indicates you do not have the privilege to access protected directories and files on your device.

If you've just upgraded your macOS to Big Sur, Monterey, or Ventura, then you're likely encountering this issue because of new security enhancements and updates to Full Disk Access and SIP (System Integrity Protection).

Thankfully, it's a pretty simple fix, and we'll show you how to solve it in the next section.

For those who are new to Macs, if you're wondering where to locate the Terminal app, here's a quick reminder:

Open Finder > Applications > Utilities > Terminal.

Utilities window

Or you could open a Spotlight search by pressing the Command and Spacebar keys and typing in Terminal.   

Now to the fixes.

How to fix the "ls operation not permitted error"

Follow these four simple steps to eliminate this annoying error; let's go.

1. Ensure Full Disk Access is enabled

The Full Disk Access security feature from Apple was first introduced with macOS 10.14 Mojave. It's ultimately built to protect your personal data from unauthorized access. If Terminal doesn't have Full Disk Access enabled, then it will struggle to operate. Here's how to turn it on:

Ensure Full Disk Access is enabled

  • Select the main Apple menu > System Settings > Privacy & Security.
  • Locate and select Full Disk Access from the list.
  • Find Terminal in the list and toggle the button to the on position.
  • Enter your admin password to make the change.
  • Now, open Terminal and test your command to see if it works.

2. Check and adjust file permission

Locked files are more common than you think, and they can be another reason why users encounter error messages in Terminal. When certain files are locked, you won't be able to make changes via Terminal. In other words, you don't have sufficient privileges to alter or access certain files.

You'll first need to unlock the file you're trying to change before you can run any commands in Terminal. Here's how:

How to check and adjust file permission

  • Locate the file you are trying to alter in the Finder.
  • Once located, right-click on the file icon and select Get Info.
  • Under Sharing & Permission, select your User name.
  • Now, change Privilege to Read & Write.
  • Now that the file is unlocked, try running your command again in Terminal.

Don't worry if you already have read-and-write access and this tip didn't help; we've got a few more tricks below to help you solve this problem once and for all.

3. General MacBook maintenance

You might be surprised to see this tip on the list, but regular and consistent MacBook maintenance is a great preventative step to stopping issues like this one from ever happening in the first place. 

If you haven't already got a regular maintenance plan, now's the time to start. Maintenance can increase your Mac's performance, eliminate application errors, and fix disk permission issues, thus preventing many annoying problems from ever occurring. It's very beneficial to the longevity and health of your device.

Many users let this one slide because it does have a reputation for being a rather manual and laborious task. Well, the good news is not anymore! 
These days, running maintenance tasks is pretty easy, thanks to tools like CleanMyMac X. We use the Maintenance Module from this Apple notarized application to handle all Mac maintenance. It can quickly run a set of scripts that rotate logs, repair permissions, and resolve troublesome application errors. Here's how to do it:

Free up Mac RAM with CleanMyMacX

  • Open CleanMyMac X (or first, download it for free here).
  • Navigate to Maintenance from the sidebar and click View All Tasks.
  • Select the following tasks:

    - Repair Disk Permissions 
    - Run Maintenance Scripts 
    - Free Up Purgeable Space 
    - Free Up RAM

  • Click Run.

Did you know? What is great about Mac is that everything works just fine most of the time. However, sometimes, you may encounter all types of issues, such as "ls: operation not permitted" error message in Terminal, MacBook not sleeping when the lid is closed, or Trackpad not working, to name just a few. On our blog, you can find fixes for these and any other Mac glitches.

    4. Temporarily disable your Macs System Integrity Protection 

    If the "operation not permitted" error still happens after you've granted Terminal Full Disk Access and run some general maintenance, you can, as a final step, try temporarily disabling your SIP.

    The SIP (System Integrity Protection) feature is designed to protect your entire macOS system by stopping the performance of unauthorized code. It's actually pretty standard practice for developers to turn this feature off, so they can test codes, fix application bugs, and install new macOS extensions.

    Here's how to temporarily disable it:

    You'll first need to boot your Mac into recovery mode; depending on your device, this will vary. Here are the official steps from Apple for Macs with Apple silicon and for Intel-based Macs.

    Once you've successfully booted your Mac into recovery mode, follow these steps:

    1. From the top main menu, select Utilities >Terminal.

    2. Type the below command, pressing enter to execute it:

      csrutil disable 

    3. Now, click the main Apple menu > Restart.

    4. Once your Mac boots up, open Terminal and try to run the original command you wanted to execute.

        After you've successfully performed the necessary tasks in Terminal, It's a good idea to enable the SIP feature again to prevent your Mac from any future virus or malware attacks. 

        To do this, simply repeat the step above, but this time, type in the following command: csrutil enable

        So we've reached the end. Thanks to these simple and easy-to-follow tips, the pesky "ls: .: operation not permitted" error message should be a distant memory.

        Your Mac deserves the best ❤️
        Try 7 Days Free

        or Buy Now

        System requirements: macOS 10.13+
        Follow us
        Blog FAQ

        MacPaw uses cookies to personalize your experience on our website. By continuing to use this site, you agree to our cookie policy. Click here to learn more.