Chflags Command

I wish to make to make a file undeletable by any user but the root user. However, I would like be able to read/write to the file.

I have choseen to do so using the chflags command. I type:

chflags sunlnk myfile

but i get the error:

chflags: invalid flag: sunlnk

I am the owner of the file and my permissions are rwxr-xr-x

Thanks for any help.

Posted on Oct 26, 2005 3:32 AM

Reply
10 replies

Oct 26, 2005 6:34 AM in response to anastasi

Dangerous, very dangerous. Messing with flags can do weird things (the schg flag is the worst in the matter)...

By the way the sunlnk flag prevents even the root user from deleting the file. You have first to change (if you can, that is, cf Michael's message) it using chflags nosunlnk before being able to delete the file...

You should sudo it or even su to be able to be able to change the sunlnk flag. Look at man chflags...

Oct 26, 2005 9:59 AM in response to anastasi

Ruby
I have tried the uunlnk flag too and i get the invalid flag message.


Well I don't know why that would be since you are the owner. But it is interesting that although CHFLAGS(1) lists 'uunlnk and 'sunlnk', CHFLAGS(2) does not list these. This is strange since the man page for chflags(1) is newer than that for chflags(2).

I need a difficult way to delete myfile.


Well if there are other 'admin' users on your machine, this is nigh impossible. But if the other users do not have admin privileges, just make sure the file is in a directory to which no-one else has write access. To prevent them overwriting or deleting the content of the file, again make sure they don't have write access, this time to the file.

(If 'uunlnk' didn't work, did you try 'uunlink', which is also supposed to work?)

Oct 27, 2005 9:27 AM in response to Frank STENGEL

Frank
It is not even present in the source code


I can't find that option anywhere in my books (including a FreeBSD tome) or in any FreeBSD man page, except for the OS X man page in section 1.

I thought of suggesting a simple lock, ie 'uchg' but that is trivial for another admin user to change. If there are no other admin users though, what I suggested should work (and doesn't need any effort since the permissions I suggested are the default for things in, e.g. your Home/Documents folder.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Chflags Command

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.