chattr

>Usage

chattr is a command used to change the attributes of files and directories in Linux.

File attributes determine how the file can be accessed and manipulated by users and the system. It is mainly used to make files immutable or append-only to prevent accidental modification.

>Synopsis

$ sudo chattr +i file.txt [option] [option]

>Options

+i (immutable)

Makes a file immutable, meaning it cannot be modified, deleted, or renamed, even by the root user.

Example 1:

Dots

-zsh

> sudo chattr +i file.txt


-i (remove immutable)

Removes the immutable attribute, allowing the file to be modified again.

Example 2:

Dots

-zsh

> sudo chattr -i file.txt


+a (append-only)

Makes the file append-only, so data can be added, but not deleted or modified.

Example 3:

Dots

-zsh

> sudo chattr +a log.txt


-a (remove append-only)

Removes the append-only attribute, allowing full access to the file.

Example 4:

Dots

-zsh

> sudo chattr -a log.txt


+S (synchronous)

Forces the file to be written synchronously, ensuring data is written to disk before being returned to the user.

Example 5:

Dots

-zsh

> sudo chattr +S importantfile.txt


+u (undeletable)

Marks the file as undeletable, meaning it cannot be deleted even by the root user.

Example 6:

Dots

-zsh

> sudo chattr +u importantfile.txt


-u (remove undeletable)

Removes the undeletable attribute, allowing the file to be deleted again.

Example 7:

Dots

-zsh

> sudo chattr -u importantfile.txt


lsattr (list attributes)

Displays the attributes of files or directories.

Example 8:

Dots

-zsh

> lsattr file.txt


>Quiz

Progress: Question ? out of ?

Question Title

Page written by Dusan Pavlovic