How to set writable and non-deletable files in Linux

WBOY
Release: 2022-07-11 16:52:01
Original
4601 people have browsed it

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".

How to set writable and non-deletable files in Linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to set writable and non-deletable files in Linux

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<版本编号>][+/-/=<属性>][文件或目录...]
Copy after login

Parameters

 -R Recursive processing, processing all files and subdirectories in the specified directory together.

 -v Set the file or directory version.

 -V displays the instruction execution process.

Turn on this attribute of the file or directory.

 - Turn off the attribute of the file or directory.

 = 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
Copy after login

(2) Cancel this Permission command (file setting):

sudo chattr -a /home/test.txt
Copy after login

(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
Copy after login

( 4) Recursively cancel this attribute of the folder (directory setting):

sudo chattr -a -R /home/data
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!