How to create an unchangeable file in Linux system

  
                

Sometimes important files are stored on your computer, and users don't want them to be changed by the system or by others. Setting read and write permissions for this file is one way to protect file security, but this method is not enough. You can create a file as an unchangeable file so you can keep it safe. So how should a Linux system create unchangeable files?

chattr is a Linux command can set or cancel flag file, and its standard file permissions (read, write, execute) are separate. Another command related to this is lsattr, which shows which flags of the file are set. Initially only the EXT file system (EXT2/3/4) supported the flags managed by chattr and lsattr, but many other native Linux filesystems are now supported, such as XFS, Btrfs, ReiserFS, and so on.

In this tutorial, I will demonstrate if you use chattr to make files in Linux unchangeable.

The chattr and lsattr commands are part of the e2fsprogs package, which is pre-installed on all modern Linux distributions.

Basic syntax for chattr

$ chattr [-RVf][operator][flag] file. . .

where the operator can be “+” (add the selected flag to the list of flags), “-” (remove the selected flag from the list of flag bits), Or “=” (force the selected flag bit).

Below are some of the available flags.

a: Can only be opened in append mode.

A: Atime (file access time) cannot be updated.

c: Automatically compressed when written to disk.

C: Turn off “copy when copying”.

i: Cannot be changed.

s: Safely deleted by auto-zeroing. (LCTT Annotation: After the general situation file is deleted, the content will not be modified. If the flag is changed, the original content will be replaced by “0”) Previous 12 Next Page Total 2 Pages

Copyright © Windows knowledge All Rights Reserved