Tuesday, July 7, 2009

File Attributes on ext3 file system

Files and directories in Linux file systems have read, write and execute permissions
associated with user, group, and others. However, there are also other attributes that
can be attached to files and directories that are specific to certain file system types.
For example, most of the present day distributions use the ext3 file system. In ext3 we can set other attributes to files and directories. Let us have a quick look. Run the following command in a terminal.

$ lsattr

------------------- ./Videos
------------------- ./apt.html
------------------- ./screenshot.bmp
------------------- ./Music
------------------- ./Documents
------------------- ./Pictures
------------------- ./examples.desktop
------------------- ./Templates

See the output . The dashes against each file directory represent the various attributes that can be set.

The ext3 has 13 such attributes. They are

a (append only)
c (compressed)
d (no dump),
i (immutable),
j (data journalling),
s (secure deletion), t (no tail-merging),
u (undeletable),
A (no atime updates),
D (synchronous directory updates),
S (synchronous updates), and
T (top of directory hierarchy).

These attributes can be manipulated with chattr command.

Here are some examples:
$ sudo chattr +i screenshot.bmp
$ sudo chattr +A -R examples.desktop

$ lsattr screenshot.bmp

----i-------- screenshot.bmp

As shown in the preceding example, with the +i option set, the screenshot.bmp file
becomes immutable, meaning that it can’t be deleted, renamed, or changed, or have a
link created to it. Here, this prevents any arbitrary changes to the file. (Not even the
root user can change the file until the i attribute is gone.) You can use this to help
protect system files.

To remove an attribute with chatter, use the minus sign (-). For example:

$ sudo chattr -i screenshot.bmp

The man pages of chattr has additional info on various attributes.

No comments: