MacOS Extended Attribute, At sign @ in ls

By Xah Lee. Date: . Last updated: .

On MacOS terminal, sometimes the command ls will show an at sign @. What does it mean?

macOS xattr 2017 10585
Example of @ showing in ls.

That means the file has Extended file attributes.

Here is 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.

What is Extended Attribute?

Summary:

View Extended Attribute with ls

ls -l -@ filename

macOS xattr 2017 98483
ls -l -@ filename
show extended attribute

Show Attribute with xattr

xattr filename

macOS xattr 2017 86781
xattr filename
show extended attributes.

To see how to use xattr, do

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$

Delete All Extended Attribute

To deletes all extended attributes:

xattr -c filename

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.