In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use the commonly used Linux command chattr for you. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
The Linux common command chattr command is used to change the file properties, which can change the file or directory properties stored on the ext2 file system
Syntax chattr [- RV] [- v] [+ /-/ =] [file or directory.] Parameter-R recursive processing, all files and subdirectories under the specified directory are processed together.
-v sets the file or directory version.
-V displays the instruction execution process.
+ Open this property of the file or directory.
-turn off this property of the file or directory.
= specifies the property of the file or directory.
The example [example 1] assigns an I attribute to the file.
[root@localhost ~] # touch ftest\ # create a test file [root@localhost ~] # chattr + I ftest [root@localhost ~] # rm-rf ftest rm:cannot remove 'ftest':Operation not permitted\ # cannot delete "ftesr", and the operation does not allow root to delete [root@localhost ~] # echo 111 > > ftest bash:ftest:Permission denied\ # after being assigned an I attribute, and cannot modify the data in the file. You can see the file with I attribute set. Even root users cannot delete and modify data.
[example 2] assign the I attribute to the directory.
[root@localhost ~] # mkdir dtest\ # create a test directory [root@localhost dtest] # touch dtest/abc\ # create a test file abc [root@localhost ~] # chattr + I dtest\ # assign the directory I attribute [root@localhost ~] # cd dtest [root@localhost dtest] # touch bed touch: cannot touch 'bed':Permission denied\ # unable to create "bcd", insufficient permissions Dtest directory cannot create a new file [root@localhost dtest] # echo 11 > > abc [root@localhost dtest] # cat abc 11\ # you can modify the file content [root@localhost dtest] # rm-rf abc rm: cannot remove 'abc': Permission denied\ # cannot delete "abc". Once the I attribute is set to the directory, even root users cannot create or delete files within the directory, but can modify the file contents.
It is also easy to delete this attribute for files with the I attribute set, simply change the + in the chattr command to -.
[example 3] demonstrates the role of the an attribute. Suppose there is such an application, we automatically back up the logs of the server to the specified directory every day, and the backup directory can set the an attribute so that only files can be created and cannot be deleted. The command is as follows:
[root@localhost ~] # mkdir-p / back/log\ # create a backup directory [root@localhost ~] # chattr + a / back/log\ # assign an attribute [root@localhost ~] # cp / var/log/messages / back/log\ # copy files and create new files to the specified directory [root@localhost ~] # rm-rf / back/log/messages rm: cannot remove'/ back/log/messages': Permission denied\ # cannot delete / back/log/messages Operation is not allowed to pay attention to, in general, do not use the chattr command to modify the hidden properties of /, / dev/, / tmp/, / var/ and other directories, it is easy to cause the system not to start. In addition, the chatrr command is often used in conjunction with the lsattr command, which modifies the hidden properties of a file or directory, while the latter is used to see if the modification is successful. The lsattr command will be explained in the next section.
This is the end of the article on "how to use chattr in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.