Home > Article > Operation and Maintenance > How to set writable and non-deletable files in Linux
In Linux, you can use the chattr command to set a writable and non-deletable file. This command is used to change the file attributes. When the parameter is set to "a", the file can be made writable and non-deletable, " " means Turn on this attribute of the file or directory. "a" means to make the file or directory only for additional purposes. The syntax is "chattr a file name".
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
Linux chattr command is used to change file attributes.
This command can change the attributes of files or directories stored on the ext2 file system. These attributes have the following 8 modes:
a: Make the file or directory only for additional purposes.
b: Do not update the last access time of the file or directory.
c: Compress the file or directory and store it.
d: Exclude files or directories from dumping operations.
i: Files or directories are not allowed to be changed arbitrarily.
s: Confidentially delete files or directories.
S: Update files or directories instantly.
u: Prevent accidental deletion.
Syntax
chattr [-RV][-v<版本编号>][+/-/=<属性>][文件或目录...]
Parameters
-R Recursive processing, processing all files and subdirectories in the specified directory together.
-v8374bdef9e793e18f32cacf9d41d5cc5 Set the file or directory version.
-V displays the instruction execution process.
155b2d3f130a5568e7cefbd0db3033c6 Turn on this attribute of the file or directory.
-155b2d3f130a5568e7cefbd0db3033c6 Turn off the attribute of the file or directory.
=50911cc176bc2bfcefb2e67861bd2b2f Specify the attribute of the file or directory.
Examples are as follows:
(1) Set /home/test.txt to be readable and writable but not delete command (file setting):
sudo chattr +a /home/test.txt
(2) Cancel this Permission command (file setting):
sudo chattr -a /home/test.txt
(3) Recursively set the /home/data folder to be readable and writable, but cannot be deleted. Permission command (directory setting):
sudo chattr +a -R /home/data
( 4) Recursively cancel this attribute of the folder (directory setting):
sudo chattr -a -R /home/data
Recommended learning: Linux video tutorial
The above is the detailed content of How to set writable and non-deletable files in Linux. For more information, please follow other related articles on the PHP Chinese website!