English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux chattr Command

Linux Command大全

The Linux chattr command is used to change file attributes.

This command can change the files stored in ext2File or directory attributes on the file system, these attributes have the following8There are modes:

  • a: Make the file or directory available only for appending.
  • b: Do not update the last access time of the file or directory.
  • c: Store the file or directory after compression.
  • d: Exclude the file or directory from the dump operation.
  • i: Do not arbitrarily modify the file or directory.
  • s: Confidentially delete the file or directory.
  • S: Update the file or directory immediately.
  • u: Prevent accidental deletion.
  • Syntax

    chattr [-RV][-v<version number>][+/-/=<attribute>][file or directory...]

    Parameters

      -R Recursive processing, process all files and subdirectories in the specified directory.

      -v<version number> Set the version of the file or directory.

      -V Display the execution process of the command.

      +<attribute> Open the specified attribute of the file or directory.

      -<attribute> Close the specified attribute of the file or directory.

      =<attribute> Specify the specified attribute of the file or directory.

    Online Examples

    Use the chattr command to prevent a critical file in the system from being modified:

    chattr +i /etc/resolv.conf
    
    lsattr /etc/resolv.conf

    It will display the following attributes:

    ----i-------- /etc/resolv.conf

    Let a file only append data inside it, but not delete, suitable for various log files:

    chattr +a /var/log/messages
    

    Linux Command大全