Linux Command explanation (19) detailed explanation of modifying file attributes lsattr and chattr commands,

Source: Internet
Author: User

Linux Command explanation (19) detailed explanation of modifying file attributes lsattr and chattr commands,

Modify file attributes
All files and directories in the Linux File System are associated with the read, write, and execution permissions of users, user groups, and other users. In addition, there may be other file and directory-related attributes that are available only for a specific file system type.
Ext2 and ext3 file system files can use some special attributes. You can use the lsattr command to list these attributes. Most attributes are obscure and are not enabled by default. The following example uses lsattr to view partial file attributes:

123456 # lsattr /etc/host*------------- /etc/host.conf------------- /etc/hosts------------- /etc/host.allow------------- /etc/host.deny$ Lsattr-aR/tmp/| less recursively lists attributes of the/tmp directory and its content

The preceding dashes represent 13 configurable ext2/ext3 attributes, which are not set by default. These attributes are described as follows: a (append only), c (Compressed), d (not dumped), I (unchangeable), j (data log), s (safely deleted) t (without tail merging), u (cannot be deleted), A (without updating access time atime), D (synchronous directory update), S (synchronous update) and T (top of the directory hierarchy ). You can use the chattr command to modify the preceding attributes, for example:

12345678 # chattr +i /boot/grub/grub.conf$ chattr +A -R /home/francois/images/*$ chattr +d FC6-livecd.iso$ lsattr /boot/grub/grub.conf /home/francois/images/* FC6-livecd.iso----i-------- /boot/grub/grub.conf-------A----- /home/francois/images/einstein.jpg-------A----- /home/francois/images/goth.jpg------d------ FC6-livecd.iso

As shown above, after the + I option is set, the grub. conf file cannot be changed, that is, the file cannot be deleted, renamed, or modified, or the link cannot be created for it. This prevents arbitrary changes to the grub. conf file. After setting the I attribute, the file cannot be modified by the root user.
In the above example, the-R option is recursively set with the + A option, and the access time (atime record) of all files in the images directory and Its subdirectories will not change. Setting the attribute can save some disk I/O on A laptop or flash drive. If you use the dump command to back up the ext2/ext3 file system, the + d option can block the backup of selected files. In this example, we choose not to back up a large ISO image.
You can use chattr and minus sign (-) to remove attributes, for example:

# Chattr-I/boot/grub. conf
Note that hackers who successfully intrude into computers often replace some system binary files (such as ls or ps) with vulnerable versions so that they cannot be changed. We recommend that you check the attribute set of executable files on an irregular system (such as in/bin,/usr/bin,/sbin, and/usr/sbin.

The file command running above indicates that bash shell provides document files in multiple formats. The file command will view the file content and determine whether the file contains the troff mark (


Address: http://www.itmmd.com/201412/315.html
This article is organized and published by Meng IT personnel. The reprinted article must indicate the source.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.