Linux command Details (19) Modify file properties lsattr, chattr command

Source: Internet
Author: User

Modify file properties
Files and directories in the Linux file system all relate to the read, write, and execute permissions of users, groups of users, and other users. In addition, there may be file and directory-related attributes that are available for other specific file system types.
Ext2 and Ext3 file system files can be selected with some special attributes. Use the lsattr command to list these properties. Most properties are obscure and are not enabled by default. The following example uses Lsattr to view partial file properties:

123456 # lsattr /etc/host* ------------- /etc/host.conf ------------- /etc/hosts ------------- /etc/host.allow ------------- /etc/host.deny $ lsattr -aR /tmp/ | less       递归列出/tmp目录及其内容的属性

The dash above represents 13 ext2/ext3 properties that can be set, which is not set by default. These properties are specified as follows: A (append only), C (compressed), d (no dump), I (non-changing), J (data log), s (safe delete), T (no tail merge), U (not deleted), a (not updated access time atime), D (Synchronous directory update), S (synchronous update) and T (at the top of the directory hierarchy). The above properties can be modified using the Chattr command, as shown in the following 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 you set the +i option, the grub.conf file cannot be changed, that is, you cannot delete, rename, or modify the file, and you cannot create a link for it. This prevents arbitrary changes to the grub.conf file, and after setting the I property, even the root user cannot modify the file.
The-r option in the example above recursively sets the +a option, and thereafter the access time (Atime record) for all files in the images directory and its subdirectories no longer changes. Set the A property to save some disk I/O on your laptop or flash drive. If you use the dump command to back up the Ext2/ext3 file system, the +D option prevents the backup of the selected files. This example chooses not to back up the large-size ISO image.
Use the chattr and minus signs (-) to remove attributes, such as:

# chattr-i/boot/grub/grub.conf
Note hackers who successfully hack into a computer tend to replace some system binaries (such as LS or PS) with a vulnerable version so that they cannot be changed. It is recommended that you check the property set of the executable files of the system (such as the/bin,/usr/bin,/sbin, and/usr/sbin) at irregular intervals.

The file command, which runs above, indicates that the bash shell provides documentation files in multiple formats. The file command looks at the contents of the files to determine if the file contains Troff tags (


Original address: http://www.itmmd.com/201412/315.html
This article by Meng Meng's IT person to organize the release, reprint must indicate the source.

Linux command Details (19) Modify file properties lsattr, chattr command

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.