Reputation: 2740
I'm looking for a simple way of preventing a file from being deleted in MacOSX. I know there is always a way of deleting it, like loading the HD with another operating system, but I'm looking for some easy method to make it a bit difficult for someone without technical knowledge.
I tried changing the privileges of the containing folder to read only, and changing the owner to "nobody", but the user can easily delete it using finder with the admin password.
I've also tried opening the file with fileHandleForUpdatingAtPath, I thought it won't be possible to delete a file in use, but finder just deletes it without problem.
Is there a way to prevent a file from being deleted in MacOSX?
Upvotes: 1
Views: 765
Reputation: 27629
It is possible to lock files, so that even root can't delete them.
Using the chflags command, various options are available:
arch "archived flag"
opaque "opaque flag"
nodump "nodump flag"
sappnd "system append-only flag"
schg "system immutable flag"
uappnd "user append-only flag"
uchg "user immutable flag"
Assuming we have a file called testFile
, do the following
chflags schg testfile
Attempting to delete the file, even as root, will be denied. Now, the only method to remove the file is to boot into Single User mode.
Upvotes: 3