What file flag would you set to prevent users from deleting it?

A sticky bit is a permission bit that is set on a directory that allows only the owner of the file within that directory or the root user to delete or rename the file. No other user has the needed privileges to delete the file created by some other user.

How can I setup the sticky bit for a directory?

I’ll set a sticky bit on a directory called test on my Desktop.

Symbolic way (t represents the sticky bit):

chmod o+t ~/Desktop/test
or

chmod +t ~/Desktop/test
Numerical/octal way (1, sticky bit bit as value 1 in the first position)

chmod 1757 ~/Desktop/test
Now let us test the results:

ls -li ~/Desktop/test

1551793 drwxrwxrwt 45 hadi hadi 20485 Mar 11 14:35 ~/Desktop/test
To delete/Remove a sticky bit

chmod o-t ~/Desktop/test
Now let us test the results:

ls -li ~/Desktop/test

1551793 drwxrwxrwx 45 hadi hadi 20485 Mar 11 14:35 ~/Desktop/test

 

This usage of the sticky bit only applies to directories, not files.

 

chmod, he is very good.

Chattr
is a command used to set / unset file attributes in Linux. Using chattr it is possible to make a file immutable. That is, even a root user will be prohibited from deleting the file.

chattr +i filename
+i can only be set by the root user