chattr Command Examples in Linux

The chattr command is used to change the attributes of a file or directory. The below table describes some of the options of the chattr command.

Option Used To
-R Recursiveli list attributes of directories and their contents
-v {version} Set version number of file
+i Make file as immutable
-i Remove immutable attribute

Syntax

The syntax of the chattr command is:

# chattr [-R] [-v {version}] [+-{attributes}] {file/directory names}

chattr Command Examples

1. To change attribute of a file to “append only”:

# chattr +a file.txt

2. To change attribute of a file to “compressed”:

# chattr +c file.txt

3. To change attribute of a file to “no dump”:

# chattr +d file.txt

4. To change attribute of a file to “exten format”:

# chattr +e file.txt

5. To change attribute of a file to “immutable”:

# chattr +i file.txt

6. To change attribute of a file to “data journaling”:

# chattr +j file.txt

7. To change attribute of a file to “secure deletion”:

# chattr +s file.txt

8. To change attribute of a file to “no tail-merging”:

# chattr +t file.txt

9. To change attribute of a file to “undeletable”:

# chattr +u file.txt

10. To change attribute of a file to “no atime updates”:

# chattr +A file.txt

11. To change attribute of a file to “synchronous directory updates”:

# chattr +D file.txt

12. To change attribute of a file to “synchronous updates”:

# chattr +S file.txt

13. To change attribute of a file to “top of directory hierarchy”:

# chattr +T file.txt

14. To set the attributes recursively:

# chattr -R +i file.txt

15. To have verbose output:

# chattr -V

16. To supress most error messages:

# chattr -f