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?

That means the file has Extended file attributes.

macOS xattr 2017 10585
Example of @ showing in ls.

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?

Extended Attributes stores customizable, small, info. e.g. author name, file character encoding, short comments, security status. Any arbitrary info can be stored as extended attribute.

Note: Resource Fork. Widely used before Mac OS X , can be considered as a more elaborate extended attribute system, and may also hold main data of the file. [see Mac OS X Resource Fork Tips]

View Extended Attribute with ls

ls -l -@ filename

macOS xattr 2017 98483
sample output of extended attribute by ls

Show Attribute with xattr

xattr filename

macOS xattr 2017 86781
sample output of extended attribute by xattr.

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. The values can be text or binary, recommended to be less than 4 kibibit. [see Unicode: Character Set, Encoding, UTF-8, Codepoint]

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.