xref: /freebsd/bin/chflags/chflags.1 (revision 64038db825d64fb4827fc8ee264ea0fa1a046d82)
1.\"-
2.\" Copyright (c) 1989, 1990, 1993, 1994
3.\"	The Regents of the University of California.  All rights reserved.
4.\"
5.\" This code is derived from software contributed to Berkeley by
6.\" the Institute of Electrical and Electronics Engineers, Inc.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.Dd July 9, 2026
33.Dt CHFLAGS 1
34.Os
35.Sh NAME
36.Nm chflags
37.Nd change file flags
38.Sh SYNOPSIS
39.Nm
40.Op Fl fhvx
41.Oo
42.Fl R
43.Op Fl H | Fl L | Fl P
44.Oc
45.Ar flags
46.Ar
47.Sh DESCRIPTION
48The
49.Nm
50utility modifies the file flags of the listed files
51as specified by the
52.Ar flags
53operand.
54.Pp
55The options are as follows:
56.Bl -tag -width indent
57.It Fl f
58Do not display a diagnostic message if
59.Nm
60could not modify the flags for
61.Va file ,
62nor modify the exit status to reflect such failures.
63.It Fl H
64If the
65.Fl R
66option is specified, symbolic links on the command line are followed
67and hence unaffected by the command.
68(Symbolic links encountered during traversal are not followed.)
69.It Fl h
70If the
71.Ar file
72is a symbolic link,
73change the file flags of the link itself rather than the file to which it points.
74.It Fl L
75If the
76.Fl R
77option is specified, all symbolic links are followed.
78.It Fl P
79If the
80.Fl R
81option is specified, no symbolic links are followed.
82This is the default.
83.It Fl R
84Change the file flags of the file hierarchies rooted in the files,
85instead of just the files themselves.
86Beware of unintentionally matching the
87.Dq Pa ".."
88hard link to the parent directory when using wildcards like
89.Dq Li ".*" .
90.It Fl v
91Cause
92.Nm
93to be verbose, showing filenames as the flags are modified.
94If the
95.Fl v
96option is specified more than once, the old and new flags of the file
97will also be printed, in octal notation.
98.It Fl x
99Do not cross mount points.
100.El
101.Pp
102The flags are specified as an octal number or a comma separated list
103of keywords.
104The following keywords are currently defined:
105.Bl -tag -offset indent -width ".Cm opaque"
106.It Cm arch , archived
107set the archived flag (super-user only)
108.It Cm nodump
109set the nodump flag (owner or super-user only)
110.It Cm opaque
111set the opaque flag (owner or super-user only)
112.It Cm sappnd , sappend
113set the system append-only flag (super-user only)
114.It Cm schg , schange , simmutable
115set the system immutable flag (super-user only)
116.It Cm snapshot
117set the snapshot flag (filesystems do not allow changing this flag)
118.It Cm sunlnk , sunlink
119set the system undeletable flag (super-user only)
120.It Cm uappnd , uappend
121set the user append-only flag (owner or super-user only)
122.It Cm uarch , uarchive
123set the archive flag (owner or super-user only)
124.It Cm uchg , uchange , uimmutable
125set the user immutable flag (owner or super-user only)
126.It Cm udontcache , dontcache
127set the dont cache flag (owner or super-user only)
128.It Cm uhidden , hidden
129set the hidden file attribute (owner or super-user only)
130.It Cm uoffline , offline
131set the offline file attribute (owner or super-user only)
132.It Cm urdonly , rdonly , readonly
133set the DOS, Windows and CIFS readonly flag (owner or super-user only)
134.It Cm usparse , sparse
135set the sparse file attribute (owner or super-user only)
136.It Cm usystem , system
137set the DOS, Windows and CIFS system flag (owner or super-user only)
138.It Cm ureparse , reparse
139set the Windows reparse point file attribute (owner or super-user only)
140.It Cm uunlnk , uunlink
141set the user undeletable flag (owner or super-user only)
142.El
143.Pp
144Putting the letters
145.Dq Ar no
146before or removing the letters
147.Dq Ar no
148from a keyword causes the flag to be cleared.
149For example:
150.Pp
151.Bl -tag -offset indent -width "nouchg" -compact
152.It Cm nouchg
153clear the user immutable flag (owner or super-user only)
154.It Cm dump
155clear the nodump flag (owner or super-user only)
156.El
157.Pp
158A few of the octal values include:
159.Bl -tag -offset indent -width ".Li 10"
160.It Li 0
161Clear all file flags.
162.It Li 1
163Translates to the
164.Cm nodump
165keyword.
166.It Li 2
167Translates to the
168.Cm uchg
169keyword.
170.It Li 3
171Translates to the
172.Cm uchg , nodump
173keywords.
174.It Li 4
175Translates to the
176.Cm uappnd
177keyword.
178.It Li 10
179Translates to the
180.Cm opaque
181keyword.
182.It Li 20
183translates to the
184.Cm uunlnk
185keyword.
186.El
187.Pp
188Other combinations of keywords may be placed by using
189the octets assigned; however, these are the most notable.
190.Pp
191Unless the
192.Fl H ,
193.Fl L ,
194or
195.Fl h
196options are given,
197.Nm
198on a symbolic link always succeeds and has no effect.
199The
200.Fl H ,
201.Fl L
202and
203.Fl P
204options are ignored unless the
205.Fl R
206option is specified.
207In addition, these options override each other and the
208command's actions are determined by the last one specified.
209.Pp
210You can use "ls -lo" to see the flags of existing files.
211.Pp
212Note that the ability to change certain flags is dependent
213on the current kernel
214.Va securelevel
215setting.
216See
217.Xr security 7
218for more information on this setting.
219.Pp
220If
221.Nm
222receives a
223.Dv SIGINFO
224signal (see the
225.Cm status
226argument for
227.Xr stty 1 ) ,
228then the current filename as well as the old and new flags are displayed.
229.Sh EXIT STATUS
230.Ex -std
231.Sh EXAMPLES
232Recursively clear all flags on files and directories contained within the
233.Fa foobar
234directory hierarchy:
235.Dl Nm Fl R Ar 0 Ar foobar
236.Sh SEE ALSO
237.Xr ls 1 ,
238.Xr chflags 2 ,
239.Xr stat 2 ,
240.Xr fts 3 ,
241.Xr security 7 ,
242.Xr symlink 7
243.Sh HISTORY
244The
245.Nm
246command first appeared in
247.Bx 4.4 .
248.Sh BUGS
249Only a limited number of utilities are
250.Nm
251aware.
252Some of these tools include
253.Xr ls 1 ,
254.Xr cp 1 ,
255.Xr find 1 ,
256.Xr install 1 ,
257.Xr dump 8 ,
258and
259.Xr restore 8 .
260In particular a tool which is not currently
261.Nm
262aware is the
263.Xr pax 1
264utility.
265