How to fix the "ls: .: operation not permitted" error in Terminal
Unable to execute commands in Terminal because of the "ls: .: operation not permitted" error?" This message can appear when macOS restricts access to certain directories, preventing even basic commands from running. While frustrating, this isn’t just a random glitch — it’s your Mac actively protecting sensitive system areas.
However, a few adjustments in System Settings can resolve the issue. In this article, we’ll break down why Terminal displays this error and walk you through the steps to fix it.
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 recently upgraded your system, this issue is likely caused by enhanced security measures, including changes to Full Disk Access and System Integrity Protection (SIP).
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.
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:
- 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:
- 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 Mac maintenance is a great preventative step to preventing issues like this one from ever happening.
Maintenance can increase your Mac's performance, eliminate application errors, and fix disk permission issues, thus preventing many annoying problems from ever occurring and extending the lifespan of your computer.
Many users overlook maintenance because it's often considered a time-consuming, manual task. However, it doesn't have to be that way.
Thanks to tools like CleanMyMac, running maintenance is quick and effortless. The app's Performance feature runs a set of scripts that helps improve performance, prevent application errors, and optimize your Mac's resources. With just a few clicks, it can rotate logs, repair disk permissions, and resolve stubborn application errors. Here's how to do it:
- Get your free CleanMyMac trial
- Open the app and go to Performance
- Run a quick scan
- Click Run Tasks to perform recommended optimizations
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 macOS Recovery; 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:
-
From the top main menu, select Utilities >Terminal.
-
Type the below command, pressing enter to execute it:
csrutil disable -
Now, click the main Apple menu > Restart.
-
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
What to do if nothing helped
If you've tried every solution and still face the same Terminal error, reinstalling macOS might be the best course of action. This process will reset all system files, permissions, and security settings, helping resolve persistent issues.
To reinstall macOS, you'll need to start your Mac in macOS Recovery. You can find detailed instructions on Apple's official website to guide you through the process. Hopefully, this will eliminate your Terminal issue for good.
So we've reached the end. Thanks to these simple and easy-to-follow tips, the irritating "ls: .: operation not permitted" error message should be a distant memory.