Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

What is the relation and the difference between xattr and chattr? I want to know when I set a chattr attribute in Linux what is happening inside the Linux kernel and inode metadata.

share|improve this question
I wrote a long answer on a related question yesterday which might be helpful - unix.stackexchange.com/questions/118840/…. Note that the attr command is intended for XFS filesystems, the equivalent filesystem independent command is setfattr –  Graeme Mar 17 at 11:20

2 Answers 2

up vote 4 down vote accepted

The attributes as handled by lsattr/chattr on Linux and some of which can be stored by quite a few file systems (ext2/3/4, reiserfs, JFS, OCFS2, btrfs, XFS, nilfs2, hfsplus...) and even queried over CIFS/SMB (when with POSIX extensions) are flags. Just bits than can be turned on or off to disable or enable an attribute (like immutable or archive...). How they are stored is file system specific, but generally as a 16/32/64 bit record in the inode.

The full list of flags is found on Linux native filesystems (ext2/3/4, btrfs...) though not all of the flags apply to all of FS, and for other non-native FS, Linux tries to map them to equivalent features in the corresponding file system. For instance the simmutable flag as stored by OSX on HFS+ file systems is mapped to the corresponding immutable flag in Linux chattr. What flag is supported by what file system is hardly documented at all. Often, reading the kernel source code is the only option.

Extended attributes on the other hand, as set with setfattr or attr on Linux store more than flags. They are attached to a file as well, and are key/value pairs that can be (both key and value) arbitrary arrays of bytes (though with limitation of size on some file systems).

The key can be for instance: system.posix_acl_access or user.rsync.%stat. The system namespace is reserved for the system (you wouldn't change the POSIX ACLs with setfattr, but more with setfacl, POSIX ACLs just happen to be stored as extended attributes at least on some file systems), while the user namespace can be used by applications (here rsync uses it for its --fake-super option, to store information about ownership or permissions when you're not superuser).

Again, how they are stored is filesystem specific. See WikiPedia for more information.

share|improve this answer
Do lsattr/chattr work for non ext filesystems? If not how would you change the flags on non ext systems on Linux? Also the attr man page says that it is written for XFS (even though it works for me on ext4). I actually spent a long time looking into this yesterday, good information is hard to come by. Please see - unix.stackexchange.com/questions/118840/… –  Graeme Mar 17 at 11:15
@Graeme, answers to those questions are in my answer. lsattr/chattr are for file flags. Not all flags are supported by all filesystems, for instance, some of them like compression won't work on ext4 but will work on btrfs. –  Stéphane Chazelas Mar 17 at 12:11
If you are interested, I wrote a script to test these flags on a few filesystems and put the results on my answer linked above. I had no success setting/reading any of them on reiserfs. –  Graeme Mar 21 at 21:59

Everything have been stroed in inode.When you change a file, indeed you change its inode.for scripting you have a good command :

stat --format=%a yourfile

You can use %variable and return a useful from inode

But your answer:

xattr is on the MacOS and chattr on linux box.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.