MacOS Extended Attribute, At sign @ in ls
On MacOS terminal, sometimes
ls will show an at sign @. What does it mean?
That means the file has Extended file attributes.
Here's a quote from
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's Extended Attribute?
- Standard Attributes. For example, creation date, modification date, permission.
- Extended Attributes Stores extra, customizable, small info. For example, author name, file character encoding, short comments, security status.
- 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 and Command Line Tips)
View Extended Attribute with ls
ls -l -@ filename
Show Attribute with 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. (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:
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.
Ask me question on patreon