The chattr command is used to change a file attribute in Ubuntu Linux. File attributes are meta-data properties that describe how a file behaves in Linux. It also describes if a file is compressed, deletable or if a file can be changed or modified. The chattr command is included in Ubuntu by default and available based on the file systems being used. One common use of the chattr command is to set the immutable flag on a file which prevents a file from being deleted or renamed. About chattr command: The chattr command is used to change a file attribute in Ubuntu Linux. It is commonly used to make changes to files that they are can’t be deleted or renamed on a file system. Syntax: The syntax is the rule and format of how the chattr command can be used. These syntax options can be reordered, but a straight format must be followed. Below is an example syntax of how to use the chattr command. Another way to use the chattr command The [OPERATOR] section:

  • The operator ‘+’ causes the selected attributes to be added to the existing attributes.

– The operator ‘-‘ causes the selected attributes to be removed from existing attributes.

Options: The command line options are switches or flags that determined how the commands are executed or controlled. They modify the behavior of the commands and are separated by spaces, followed by the commands. Below are some options for the chattr command: Examples: Below are some examples of how to run and use the chattr on Ubuntu Linux. Simply run the chattr command to invoke it. If you run the chattr command but don’t specify an option, it will simply display help information. For example, if you want to make a file immutable, run the commands below: To view attributes of files, run the commands below: It should display a similar line as shown below: To revert the change and remove the immutable attribute, run the commands below: You can also combine multiple attributes with the chattr command. For example, if you want to make a file immutable and also instruct the kernel not to track the last accessed time, run the commands below: For more details about the chattr command, run man chattr: It should display the help page for the chattr command. Conclusion: This post showed you how to use the chattr command in Ubuntu Linux. If you find any error above please use the form below to comment.