Mac OS X Extended Attributes and Xattr; What's the -rw-rw-r--@ Sign Mean?

, ,

This article explains Mac OS X's Extended Attributes and the command line utility xattr.

In OS X ( OS X 10.6) when you do ls -l, sometimes you see the @ sign. Example:

-rw-rw-r--@  1 _www    admin  1046505 Nov 10  2007 collection.jpg

That means the file has Extended file attributes, and you can use the command xattr.

What's Extended Attribute?

Summary:

How to use Command Line for extended Attribute

Use “ls -l@ filename”

Apple also made some changes to “ls”. When you do a ls -l on a file, if the file has extended attributes, it'll display a “@” sign. You can also use ls -l -@ filename to show extended attributes. Example:

-rw-rw-r--@  1 _www    admin  1046505 Nov 10  2007 collection.jpg

Here's a quote from man ls:

If the file or directory has extended attributes, the permissions field printed by the -l option is followed by a '@' character. Otherwise, if the file or directory has extended security information (such as an access control list), the permissions field printed by the -l option is followed by a '+' character.

Use xattr

There's no man page for xattr, but xattr -h gives a usage summary:

usage: xattr [-l] [-r] [-v] [-x] file [file ...]
       xattr -p [-l] [-r] [-v] [-x] attr_name file [file ...]
       xattr -w [-r] [-v] [-x] attr_name attr_value file [file ...]
       xattr -d [-r] [-v] attr_name file [file ...]

The first form lists the names of all xattrs on the given file(s).
The second form (-p) prints the value of the xattr attr_name.
The third form (-w) sets the value of the xattr attr_name to the string attr_value.
The fourth form (-d) deletes the xattr attr_name.

options:
  -h: print this help
  -r: act recursively
  -l: print long format (attr_name: attr_value and hex output has offsets and
      ascii representation)
  -v: also print filename (automatic with -r and with multiple files)
  -x: attr_value is represented as a hex string for input and output
vmm:vmm xahlee$

What to Put in Extended Attribute?

Extended Attributes are name/value pairs. The names are Unicode characters of less than 128 bytes. (they are probably encoded in utf-8 or utf-16) The values can be text or binary, recommended to be less than 4 kibibit.

There's no standardize structure for names. Anyone can add a attribute named for example “xyz” to a particular file. Apple recommends the use of reverse DNS naming scheme to prevent name clash. This is the same scheme adopted by Java. Example:

com.apple.FinderInfo

If you have a domain name, such as “example.com” then your attribute name for file of author can be “com.example.author”. If you don't have a domain name, just make sure the name is not likely used by others.

blog comments powered by Disqus