Gangmax Blog

@: MacOS Extended File Attribute

When I list the files in MacOS, it shows results like below:

1
2
3
4
5
6
7
8
9
~/Library/Fonts> ls -la
...
-rw-r--r--@ 1 maxhuang staff 317628 Jan 17 2020 Hack-Bold.ttf
-rw-r--r--@ 1 maxhuang staff 322288 Jan 17 2020 Hack-BoldItalic.ttf
-rw-r--r--@ 1 maxhuang staff 316156 Jan 17 2020 Hack-Italic.ttf
-rw-r--r--@ 1 maxhuang staff 309408 Jan 17 2020 Hack-Regular.ttf
-rw-r--r-- 1 maxhuang staff 32683280 Nov 10 2021 SourceHanSans-VF.otf.ttc
-rw-r--r-- 1 maxhuang staff 56785868 Nov 10 2021 SourceHanSerif-VF.otf.ttc
...

What does the “@” sign here mean? The following answer comes from the post here.

That means the file has Extended file attributes. What is Extended Attribute?

  1. Standard Attributes. For example, creation date, modification date, permission.

  2. Extended Attributes. Stores extra, customizable, small info. For example, author name, file character encoding, short comments, security status.

  3. 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)

Some related commands are listed below:

1
2
3
4
5
6
7
8
# View Extended Attribute with ls.
ls -l -@ <filename>

# Show Attribute with xattr.
xattr <filename>

# Delete All Extended Attribute.
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:

1
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.

In some case, if we want to remove all the extended attributes, such as removing the warnings that “the app is not from verified developer”, we can run the following command(from here):

1
xattr -cr <file_or_dir>

Comments