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.