I can successfully run ls, but if I run ls -l on the same folder I get "Operation not permitted".
Difference between ls
and ls -l
ls
displays the name of the files/directories contained in a directory, while ls -l
displays a lot of more information (excerpt from man ls
):
If the -l option is given, the following information is displayed for each
file: file mode, number of links, owner name, group name, number of bytes
in the file, abbreviated month, day-of-month file was last modified, hour
file last modified, minute file last modified, and the pathname.
Usually, read access to the parent directory should be enough to get this information, but in this particular case (SIP enabled and datavault
flag set, see below), it's not.
For example, to get the number of links, you need to know the inode number. You can get that information with ls -i
, and you will see it fails for a number of files and directories (and consequently ls -l
will fail for those files/directories, too):
ls -i /private/var/folders/51/y66nwk4x1b700xgy1fs5d_9w0000gq/0/
ls: com.apple.LaunchServices.dv: Operation not permitted
ls: com.apple.SharedWebCredentials: Operation not permitted
ls: com.apple.lockoutagent: Operation not permitted
ls: com.apple.nsurlsessiond: Operation not permitted
ls: dmd: Operation not permitted
18693497 com.apple.ScreenTimeAgent 18701711 com.apple.corespeechd 18688786 com.apple.icloud.searchpartyd 18687284 com.apple.progressd
18693950 com.apple.Spotlight 18687828 com.apple.dmd 18687147 com.apple.notificationcenter 18691540 com.apple.routined
18688254 com.apple.bird 18702008 com.apple.dock.launchpad 11150084 com.apple.pluginkit
On the other hand, ls
simply displays filenames, and that information can be retrieved for all files.
Why doesn't sudo ls -l
work?
sudo
let's you run commands as root
:
$ sudo whoami
root
but root
is no longer an almighty user: since OS X 10.11 "El Capitan", its powers are restricted by System Integrity Protection (SIP):
System Integrity Protection restricts the root user account and limits the actions that the root user can perform on protected parts of the Mac operating system.
Before System Integrity Protection, the root user had no permission restrictions, so it could access any system folder or app on your Mac. Software obtained root-level access when you entered your administrator name and password to install the software. That allowed the software to modify or overwrite any system file or app.
System Integrity Protection includes
protection for these parts of the system:
so /var
is one of the protected folders that root
has no longer unrestricted access to.
But there's more going on: disabling SIP makes these files accessible to root
and to the owner. All files that couldn't be read have the extended attribute com.apple.rootless
set, which marks them as being protected by SIP, but they also have the datavault
flag enabled, for example:
ls -ledD@ com.apple.LaunchServices.dv
drwx------@ 4 jaume staff datavault 128 Jan 17 10:35 com.apple.LaunchServices.dv
com.apple.rootless 27
which makes them unreadable except for apps with the corresponding entitlement (when SIP is disabled, access is again governed by mode and ownership, as in a traditional UNIX-like file system).
I found this because timemachine can't back up these files
/private/var/folders
stores transient data and its contents are not backed up by Time Machine.
/var
is nominally transitory. In practice, a lot of the data is pretty long-lived, and some of it (such as log files) can be useful to back up.