1.Dd Nov 29, 2010
2.Dt XATTR 1
3.Os
4.Sh NAME
5.Nm xattr
6.Nd display and manipulate extended attributes
7.Sh SYNOPSIS
8.Nm
9.Op Fl lrsvx
10.Ar file ...
11.Nm
12.Fl p
13.Op Fl lrsvx
14.Ar attr_name
15.Ar file ...
16.Nm
17.Fl w
18.Op Fl rsx
19.Ar attr_name attr_value
20.Ar file ...
21.Nm
22.Fl d
23.Op Fl rsv
24.Ar attr_name
25.Ar file ...
26.Nm
27.Fl c
28.Op Fl rsv
29.Ar file ...
30.Nm
31.Fl h | -help
32.Sh DESCRIPTION
33The
34.Nm
35command can be used to display, modify or remove the extended attributes
36of one or more files, including directories and symbolic links.
37Extended attributes are arbitrary metadata stored with a file, but separate
38from the filesystem attributes (such as modification time or file size).
39The metadata is often a null-terminated UTF-8 string, but can also be arbitrary
40binary data.
41.Pp
42One or more files may be specified on the command line.
43For the first two forms of the command, when there are more than one file,
44the file name is displayed along with the actual results.
45When only one file is specified, the display of the file name is usually
46suppressed (unless the
47.Fl v
48option described below, is also specified).
49.Pp
50In the first form of the command (without any other mode option specified),
51the names of all extended attributes are listed.
52Attribute names can also be displayed using
53.Dq Li ls -l@ .
54.Pp
55In the second form, using the
56.Fl p
57option
58.Pq Dq print ,
59the value associated with the given attribute name is displayed.
60Attribute values are usually displayed as strings.
61However, if nils are detected
62in the data, the value is displayed in a hexadecimal representation.
63.Pp
64The third form, with the
65.Fl w
66option
67.Pq Dq write ,
68causes the given attribute name to be assigned the given value.
69.Pp
70The fourth form, with the
71.Fl d
72option
73.Pq Dq delete ,
74causes the given attribute name (and associated value), to be removed.
75.Pp
76In the fifth form, with the
77.Fl c
78option
79.Pq Dq clear ,
80causes all attributes (including their associated values), to be removed.
81.Pp
82Finally, the last form, with either the
83.Fl h
84or
85.Fl -help
86option, displays a short help message and exits immediately.
87.Sh OPTIONS
88.Bl -tag -width XX
89.It Fl l
90By default, the first two command forms either displays just the attribute
91names or values, respectively.
92The
93.Fl l
94option causes both the attribute names and corresponding values to be displayed.
95For hexadecimal display of values,
96the output is preceeded with the hexadecimal offset values and
97followed by ASCII display, enclosed by
98.Dq | .
99.It Fl r
100If a file argument is a directory, act as if the entire contents of the
101directory recursively were also specified (so that every file in the directory
102tree is acted upon).
103.It Fl s
104If a file argument is a symbolic link, act on the symbolic link itself, rather
105than the file that the symbolic link points at.
106.It Fl v
107Force the the file name to be displayed, even for a single file.
108.It Fl x
109Force the attribute value to be displayed in the hexadecimal representation.
110.Pp
111The
112.Fl w
113option normally assumes the input attribute value is a string.
114Specifying the
115.Fl x
116option causes
117.Nm
118to expect the input in hexadecimal (whitespace is ignored).
119The
120.Xr xxd 1
121command can be used to create hexadecimal representations from exising
122binary data, to pass to
123.Nm .
124.El
125.Sh EXIT STATUS
126The
127.Nm
128command exits with zero status on success.
129On error, non-zero is returned, and an error message is printed to the standard
130error.
131For system call errors, both the error code and error string are printed (see
132.Xr getxattr 2 ,
133.Xr listxattr 2 ,
134.Xr removexattr 2
135and
136.Xr setxattr 2
137for a complete list of possible error codes).
138.Pp
139Some attribute data may have a fixed length that is enforced by the system.
140For example,
141.Bd -literal -offset indent
142% xattr -w com.apple.FinderInfo 0 foo
143xattr: [Errno 34] Result too large: 'foo'
144.Ed
145.Pp
146The
147.Li com.apple.FinderInfo
148attribute must be 32 bytes in length.
149.Sh EXAMPLES
150This example copies the
151.Li com.apple.FinderInfo
152attribute from the
153.Li /usr
154directory to the
155.Li MyDir
156directory:
157.Bd -literal -offset indent
158% xattr -px com.apple.FinderInfo /usr
15900 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00
16000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
161% xattr -l MyDir
162% xattr -wx com.apple.FinderInfo \\
163  "`xattr -px com.apple.FinderInfo /usr`" MyDir
164% xattr -l MyDir
165com.apple.FinderInfo:
16600000000  00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00  |........@.......|
16700000010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
16800000020
169.Ed
170.Sh SEE ALSO
171.Xr ls 1 ,
172.Xr xxd 1 ,
173.Xr getxattr 2 ,  
174.Xr listxattr 2 ,  
175.Xr removexattr 2 ,  
176.Xr setxattr 2
177