Setting the not removable bit is a technique used in computer programming and systems administration to mark a file or directory as unalterable or undeletable by users with standard permissions.
In Unix-like operating systems such as Linux, this is often achieved through the use of the chattr
command, which allows setting attributes on files and directories. One of the attributes that can be set is the "immutable" attribute, denoted by the letter "i". When this attribute is set on a file or directory, it prevents it from being modified, deleted, or renamed, even by the root user, until the attribute is explicitly removed.
Setting the not removable bit can be useful in various scenarios, such as protecting critical system files from accidental deletion or tampering, safeguarding configuration files from unauthorized modifications, or preventing important data from being altered or deleted unintentionally. However, it's important to use this feature judiciously, as it can also cause inconvenience if applied indiscriminately, potentially hindering legitimate system maintenance tasks or software updates.
#Set not removable bit
sudo chattr +i file.txt
#Remove the bit so you can delete it
sudo chattr -i file.txt