How can I give files extended attributes in mac os x?
Solution 1
My El Capitan has no setattr
or setxattr
(the latter is the name of a C runtime function: you could make your own utility using that).
OSX provides xattr
, which (noting comments such as Mac OS X Extended Attributes and Xattr) seems fairly recent. A comment in Manually set extended attributes on arbitrary files from 2011 gives a hint about OSX 10.5
You can see some discussion in How do I remove the “extended attributes” on a file in Mac OS X?, as well as a copy (no date) in SS64. In looking for sources, I came across a sourceforge project which may be relevant. The best source of course is the manual page on your machine.
The manual page lists several formats, pointing to this one as the way to set attributes on a file:
xattr -w [-rsx] attr_name attr_value file ...
where the -r
, -s
and -x
options respectively deal with directory-recursion, symbolic links and input of the attribute value using hexadecimal.
Solution 2
It's called xattr
on OS X . You can use setxattr
to set attributes.
Solution 3
In MacOS Monterey, setxattr gives zsh: command not found: setxattr
Instead it is xattr -w <attribute name> <attribute value> file/folder
.
Full manpage is here:
$: xattr
Not enough arguments for option -�. Expected at least 1 but got 0
usage: xattr [-l] [-r] [-s] [-v] [-x] file [file ...]
xattr -p [-l] [-r] [-s] [-v] [-x] attr_name file [file ...]
xattr -w [-r] [-s] [-x] attr_name attr_value file [file ...]
xattr -d [-r] [-s] attr_name file [file ...]
xattr -c [-r] [-s] 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.
The fifth form (-c) deletes (clears) all xattrs.
options:
-h: print this help
-l: print long format (attr_name: attr_value and hex output has offsets and
ascii representation)
-r: act recursively
-s: act on the symbolic link itself rather than what the link points to
-v: also print filename (automatic with -r and with multiple files)
-x: attr_value is represented as a hex string for input and output```
Related videos on Youtube
anonymous
Updated on September 18, 2022Comments
-
anonymous almost 2 years
How can I give files extended attributes in mac os x? Mac os x doesn't have the 'setattr' command.
-
Syclone0044 almost 3 yearsThanks, that xattr sourceforge project compiled perfectly for me on iOS 12.4, arm64, clang 10.0 jailbroken. I had been searching everywhere for a basic xattr cmdline utility like this that would compile, and nothing else worked, despite this project being last updated 13 years ago.