I want my file not to be deleted by any user. Can I know the chmod mode command for the same?
I need to get this kind of msg (rm ctl_model_fact.csv: Permission denied)
I want my file not to be deleted by any user. Can I know the chmod mode command for the same?
I need to get this kind of msg (rm ctl_model_fact.csv: Permission denied)
root
can always delete a file (at least on the chmod
level; you need file system attributes or a Linux Security Module (SELinux, AppArmor) to prevent that).
For ordinary users you have to remove the write permission of the parent directory for all users.
As long as you're not trying to keep root from deleting the file, you actually need to modify the permissions on the directory in which ctl_model_fact.csv
resides. chmod go-w [your directory]
will do it, but it will affect all files in your directory, not just ctl_model_fact.csv
. If you also want to make sure other users are unable to change the file, use chmod go-w ctl_model_fact.csv
.
Deletion is a write operation so you need to remove write access from the directory that contains the file (using the file ~/foo/bar.txt
as an example):
chmod a-w ~/foo/
or
chmod 666 ~/foo/
This, however still allows root to delete the file. If don't even want to allow that, things get more complex. As far as I know, the best way (and this is easily circumvented by reversing the command) is to set it to "immutable":
sudo chattr +i ~/foo/bar.txt
That will stop root from deleting the file but they can always just run chattr -i ~/foo/bar.txt
again to undo it so it's more like a obstacle than a full block. It does, however, stop non-root users from deleting it and they won't have the right to run chattr -i
on it so this is the easiest way since it does not affect all files in the directory.