How do you make a file immutable?
How do you make a file immutable?
To make the files immutable, “chattr” command can be used. The filesystems in Linux ext2, ext3, ext4, btrfs supports all the flags, however all the flags won’t support all non-native FS. One cannot delete or modify file/folder once attributes are sets with chattr command, even though you have full permission.
Which of the following commands is used to make a file immutable?
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. The trick lies in setting the appropriate attribute for the file.
What is an immutable file?
An immutable file cannot be changed or renamed. An appendOnly file allows append operations, but not delete, modify, or rename operations. An immutable directory cannot be deleted or renamed, and files cannot be added or deleted under such a directory.
How to set immutable attribute in chattr command?
To set a file attribute we will use chattr command with + operator followed by the attribute name. Let check with examples how to set immutable attribute to a file. Only root or user with sudo privilege can set and remove immutable flag on a file. A file with an immutable attribute:
What does it mean to make a file immutable?
If a file is accessed with ‘ A ‘ attribute set, its atime record is not updated. If a file is modified with ‘ S ‘ attribute set, the changes are updates synchronously on the disk. A file is set with ‘ a ‘ attribute, can only be open in append mode for writing. A file is set with ‘ i ‘ attribute, cannot be modified (immutable).
How to use chattr to make files unchangeable?
This enables the user to ask for its undeletion. + : Adds the attribute to the existing attribute of the files. – : Removes the attribute to the existing attribute of the files. = : Keep the existing attributes that the files have. Here, we are going to demonstrate some of the chattr command examples to set/unset attributes to a file and folders.
Can a chattr be set or unset by lsattr?
The following attributes are read-only. They cannot be set or unset by chattr, but can be listed by lsattr. The filesystem is not able to automatically compress this file. The file is storing its blocks in units of the filesystem’s blocksize instead of in sectors. The file is, or previously was, larger than 2 TB.