There are some important files that I might delete by accident (if I'm not careful), and I need to ensure that these files cannot be deleted or moved. Is it possible to set file permissions so that I cannot delete or move certain specific files? Also, is it possible to prevent files from being moved or deleted by non-root users?
Also:
sudo chattr +i <file>
is a good trick. It makes the file immutable.You only need to do this in your home directory as the system files in
/etc, /var or /usr
are already set the way you want by default:You can remove the write permission of the file for everybody (owner user, group and others). This way the file will be readable by you (or the owner of the file) and won't be writable (or deleted/moved) (obs: and also not editable)
Via command line:
chmod -w filename
for directories (recursive to all files inside):
chmod -R -w diretory
Obs: you need to use sudo to apply these commands only if you are not the owner of the file.
Via graphic interface in Nautilus:
Right-click on the file and go to permissions to adjust.
You can see a more detailed explanation about permissions in Ubuntu Help
chmod 000 <file>
(as root or sudo) would prevent any modification to<file>
from a non-root user.Change read-write permission of your own files in your
/home
folder to read only for the owner, group and others: