Using Linux extended attributes


The Linux EXT2/EXT3 file systems comes with support for extended attributes. Extended attributes can be used to enforce administrative policies beyond standard permissions on individual files, which allows things like compression, secure deletion, no atime updates, file immutability, etc. to be controlled on a per file basis. Each extended attribute has a unique character associated to it, and the current set of supported attributes are described in the following table (you can also view these in the chattr(1) man page):

a - Append only
c - Compress file
d - Exclude from dump
i - Make the file immutable
j - Journal file data
s - Securely delete file
u - When a file is deleted, save it's contents
A - Don't update the files atime
S - When a file is written, it is written to disk synchronously

To check if one of the extended attributes has been assigned to a file, the lsattr command can be run without any arguments to see if extended attributes are assigned to files in the current directory, or with a file name or regular expression to check if those files contain extended attributes:

$ lsattr foo

------------- foo

To set an extended attribute, the chattr command can be run with a file name, or a regular expression to indicate the files the attributes should be applied to:

$ chattr +cs foo

$ lsattr foo

s-------c---- foo

Extended attributes are super useful, but unfortunately a few attributes like secure delete and compression are not yet supported w/o additional kernel patches ( hopefully this will be one of the items added in ext4 and a future kernel release!). If you would like to use compression now, Solaris 10 and ZFS is the way to go.

This article was posted by Matty on 2007-01-03 21:38:00 -0400 -0400