Name
xattr — stdin stdout - file -- opt --help --version
Synopsis
xattr [-[cdpw]] [options]attributes[files]
Files in OS X can have not only “normal” attributes, such as
read, write, and execute permission, but also extended
attributes, which can be any file metadata you dream up.
Extended attributes are created and manipulated with the xattr command. For example, let’s define an
attribute called com.example.color,
assign it the value blue, and apply it to the file myfile:[13]
➜touch myfileCreate an empty file ➜xattr -w com.example.color blue myfile
Now list the file and look for the @ symbol in the output, indicating that
extended attributes are present:
➜ ls -l@ myfile
-rw-r--r--@ 1 smith staff 0 Mar 26 22:19 myfileand display its extended attribute values with xattr:
➜ xattr -l myfile
com.example.color: blueor just one attribute alone, by name:
➜ xattr -p com.example.color myfile
blueYou can delete one attribute with -d:
➜ xattr -d com.example.color myfileor all of them with -c:
➜ xattr -c myfileWhile you can amuse yourself all day by creating and viewing
attributes, their practical use is for Macintosh applications to store
important data about files. For instance, the Finder maintains an
extended attribute named com.apple.FinderInfo, displayed here in
hexadecimal:
➜ xattr -l letter.docx
00000000 57 58 42 4E 4D 53 57 44 00 ...Useful options
| Display both the name and value of attributes, not just one or the other. |
| Recursively operate on all files in a directory. |
| Do not follow ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access