This article is a mirror article of machine translation, please click here to jump to the original article.

View: 1796|Reply: 1

[linux] Linux protection files cannot be deleted or modified

[Copy link]
Posted on 1/14/2025 9:55:41 AM | | | |
Requirements: Sometimes there are important data on the server that cannot be modified or deleted (e.g., attachments, etc.). If you have a head, you may delete files by mistake, how to protect files or folders from deletion or modification?

Linux chattr commands are used to change file properties.

This command changes the file or directory properties stored on the ext2 file system, which have 8 modes:

A: Make the file or directory for additional use only.
b : the last access time of a file or directory that is not updated.
c: Compress the file or directory and store it.
d: Excluding a file or directory from the dumping operation.
i: Do not arbitrarily change files or directories.
s: Confidentiality deletion of files or directories.
S: Update files or directories on the fly.
u: Prevent accidental deletion.

Setup file

Set the file to immutable:


Cancel the immutable properties of a file:


Set up folders

How to make a directory not deleted

Using the -R parameter, you can recursively change the properties of the directory and the files in the directory:


Note: After setting this property,You also can't write files to the folder



Cancel the attribute so that it can be deleted:


View properties

The command is as follows:





Previous:Rocky Linux 9 wake on lan
Next:Subdomain scanning, domain name record resolution scanning
 Landlord| Posted on 1/14/2025 11:33:55 AM |
The .net/c# settings file is immutable, and the code is as follows:




If you try to delete a file, an exception is thrown

System.UnauthorizedAccessException: Access to the path '/root/a1/aaaaaa' is denied.
---> System.IO.IOException: Operation not permitted
   --- End of inner exception stack trace ---
   at System.IO.FileSystem.DeleteFile(String fullPath)

Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com