ls: .: Operation not permitted - Mac Big Sur Terminal Zsh Error

Recently when I tried to run ls command in Mac Terminal Zsh shell on macOS Big Sur, I got the below error,

code2care@mac % ls
ls: .: Operation not permitted

This was really weird, I was able to fix this issue by following the below steps,

  1. Click on the Apple logo on Menu Bar,
  2. Select System Preferences...
  3. Click on Security & Privacy,
  4. Select Files & Folders,
  5. Under - Allow the Apps below to access files & folders, look for terminal and check - Desktop Folder, you will get the below alert,
    Terminal” will not have access to files on your desktop until it is quit. 

    You can choose to quit “Terminal” now, or do it on your own later.
  6. Click on Quit & Reopen
  7. You will not be able to access ls and other commands in desktop.
Security and Privacy Option
Security and Privacy Option
Select Desktop folder from Files and Folders
Select Desktop folder from Files and Folders

✏️ You can get such a error while trying to access Network volumes, Download or Documents folder if the option in Files and Folders is unchecked for Terminal.

Recent Posts:

Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.