"Linux command-File management class" Chattr command and Lsattr command

Source: Internet
Author: User

chattr command

Command function: Change file properties.
Command syntax: chattr [parameter] [+/-/=< property;] [file or directory ...]

This directive alters the properties of files or directories stored on ext2, ext3, Ext4, XFS, Ubifs, ReiserFS, JFS file systems, which have the following 8 modes:

    • A: Make the file or directory available for additional use only.
    • 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: Do not alter the file or directory arbitrarily.
    • S: Privacy delete files or directories.
    • S: Update files or directories instantly.
    • U: Remove outside of prevention.

With the three operator +/-/=, you can add and delete attributes to a file or directory.

Command parameters:

    • -R recursively handles all files and subdirectories under the specified directory.
    • -v< version number > set file or directory version.
    • -V Displays the instruction execution process.
    • +< Properties > Open the Item property of the file or directory.
    • -< Properties > Close the Item property of the file or directory.
    • The =< property > Specifies the Item property of the file or directory.

This command can only be performed by Superuser root.

Example:

1. Limit a file to append only the contents of the file, not modify and delete the file (this scenario is suitable for the log file), and output the instruction execution process

If you modify this file now, an error will occur:

When modifying a file, an error occurred and the following command could be used to append the contents of the file:

By >> implementation of the file appended,> is to overwrite the contents of the file.

2. The settings file must not be arbitrarily changed by adding the attribute I

After adding the attribute I, and then adding content to the file, a permission error occurs, so that even the root user cannot modify the file.

lsattr command

Command function: Displays the file properties, after the chattr command is exhausted, you can use the lsattr command to view the file properties

Such as:

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Linux command-File management class" Chattr command and Lsattr 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.