Linux lsattr command details how to use Linux lsattr command

Source: Internet
Author: User

You can use chattr to modify the attributes of a file or directory and run the lsattr command to query its attributes.

Syntax

Lsattr [-adlRvV] [file or directory...]

Parameters:

  • -A displays all files and directories, including the additional built-in characters starting with ".", the current directory "." and the upper Directory "..".
  • -D display, directory name, rather than its content.
  • -L this parameter does not work currently.
  • -R recursive processing: All files and subdirectories in the specified directory are processed together.
  • -V: displays the file or directory version.
  • -V displays the version information.

Instance

1. Use the chattr command to prevent the modification of a key file in the system:

# Chattr + I/etc/resolv. conf

Then run mv/etc/resolv. conf and other commands to operate on the file. Operation not permitted is obtained.

When editing the file, vim prompts the W10: Warning: Changing a readonly file error. To modify this file, remove the I attribute:

Chattr-I/etc/resolv. conf

Use the lsattr command to display the file attributes:

# Lsattr/etc/resolv. conf

Output result:

---- I --------/etc/resolv. conf

2. Allow a file to only append data to it, but not delete it. It is applicable to various log files:

# Chattr + a/var/log/messages

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.