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 September 12, 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.Op Fl -dereference-links-unsafely 42.Oo 43.Fl R 44.Op Fl H | Fl L | Fl P 45.Oc 46.Ar flags 47.Ar 48.Sh DESCRIPTION 49The 50.Nm 51utility modifies the file flags of the listed files 52as specified by the 53.Ar flags 54operand. 55.Pp 56The options are as follows: 57.Bl -tag -width indent 58.It Fl f 59Do not display a diagnostic message if 60.Nm 61could not modify the flags for 62.Va file , 63nor modify the exit status to reflect such failures. 64.It Fl H 65If the 66.Fl R 67option is specified, symbolic links on the command line are followed 68and hence unaffected by the command. 69(Symbolic links encountered during traversal are not followed.) 70.It Fl h 71If the 72.Ar file 73is a symbolic link, 74change the file flags of the link itself 75rather than the file to which it points. 76.It Fl L 77If the 78.Fl R 79option is specified, symbolic links are followed. 80A symbolic link encountered during the traversal that points outside 81the file hierarchy being traversed is not followed unless the 82.Fl -dereference-links-unsafely 83option is also given; 84see the description of that option below. 85A symbolic link named directly on the command line is followed unless 86.Fl h 87is specified. 88.It Fl P 89If the 90.Fl R 91option is specified, no symbolic links are followed. 92This is the default. 93.It Fl R 94Change the file flags of the file hierarchies rooted in the files, 95instead of just the files themselves. 96Beware of unintentionally matching the 97.Dq Pa ".." 98hard link to the parent directory when using wildcards like 99.Dq Li ".*" . 100.It Fl v 101Cause 102.Nm 103to be verbose, showing filenames as the flags are modified. 104If the 105.Fl v 106option is specified more than once, the old and new flags of the file 107will also be printed, in octal notation. 108.It Fl x 109Do not cross mount points. 110.It Fl -dereference-links-unsafely 111By default, 112.Nm 113runs its traversal inside a 114.Xr capsicum 4 115sandbox, which prevents it from following a symbolic link whose 116target lies outside the file hierarchy named on the command line. 117This option disables the sandbox so that such symbolic links are 118followed, restoring historical behavior. 119It is only meaningful together with 120.Fl L 121or the default logical behavior, and should be used with caution, 122as it allows a crafted symbolic link to redirect 123.Nm 124at files outside the intended hierarchy. 125.El 126.Pp 127The flags are specified as an octal number or a comma separated list 128of keywords. 129The following keywords are currently defined: 130.Bl -tag -offset indent -width ".Cm opaque" 131.It Cm arch , archived 132set the archived flag (super-user only) 133.It Cm nocache, noucache 134set the nocache flag (owner or super-user only) 135.It Cm nodump 136set the nodump flag (owner or super-user only) 137.It Cm opaque 138set the opaque flag (owner or super-user only) 139.It Cm sappnd , sappend 140set the system append-only flag (super-user only) 141.It Cm schg , schange , simmutable 142set the system immutable flag (super-user only) 143.It Cm snapshot 144set the snapshot flag (filesystems do not allow changing this flag) 145.It Cm sunlnk , sunlink 146set the system undeletable flag (super-user only) 147.It Cm uappnd , uappend 148set the user append-only flag (owner or super-user only) 149.It Cm uarch , uarchive 150set the archive flag (owner or super-user only) 151.It Cm uchg , uchange , uimmutable 152set the user immutable flag (owner or super-user only) 153.It Cm uhidden , hidden 154set the hidden file attribute (owner or super-user only) 155.It Cm uoffline , offline 156set the offline file attribute (owner or super-user only) 157.It Cm urdonly , rdonly , readonly 158set the DOS, Windows and CIFS readonly flag (owner or super-user only) 159.It Cm usparse , sparse 160set the sparse file attribute (owner or super-user only) 161.It Cm usystem , system 162set the DOS, Windows and CIFS system flag (owner or super-user only) 163.It Cm ureparse , reparse 164set the Windows reparse point file attribute (owner or super-user only) 165.It Cm uunlnk , uunlink 166set the user undeletable flag (owner or super-user only) 167.El 168.Pp 169Putting the letters 170.Dq Ar no 171before or removing the letters 172.Dq Ar no 173from a keyword causes the flag to be cleared. 174For example: 175.Pp 176.Bl -tag -offset indent -width "nouchg" -compact 177.It Cm nouchg 178clear the user immutable flag (owner or super-user only) 179.It Cm dump 180clear the nodump flag (owner or super-user only) 181.El 182.Pp 183A few of the octal values include: 184.Bl -tag -offset indent -width ".Li 10" 185.It Li 0 186Clear all file flags. 187.It Li 1 188Translates to the 189.Cm nodump 190keyword. 191.It Li 2 192Translates to the 193.Cm uchg 194keyword. 195.It Li 3 196Translates to the 197.Cm uchg , nodump 198keywords. 199.It Li 4 200Translates to the 201.Cm uappnd 202keyword. 203.It Li 10 204Translates to the 205.Cm opaque 206keyword. 207.It Li 20 208translates to the 209.Cm uunlnk 210keyword. 211.El 212.Pp 213Other combinations of keywords may be placed by using 214the octets assigned; however, these are the most notable. 215.Pp 216Unless the 217.Fl H , 218.Fl L , 219or 220.Fl h 221options are given, 222.Nm 223on a symbolic link always succeeds and has no effect. 224The 225.Fl H , 226.Fl L 227and 228.Fl P 229options are ignored unless the 230.Fl R 231option is specified. 232In addition, these options override each other and the 233command's actions are determined by the last one specified. 234.Pp 235You can use "ls -lo" to see the flags of existing files. 236.Pp 237Note that the ability to change certain flags is dependent 238on the current kernel 239.Va securelevel 240setting. 241See 242.Xr security 7 243for more information on this setting. 244.Pp 245If 246.Nm 247receives a 248.Dv SIGINFO 249signal (see the 250.Cm status 251argument for 252.Xr stty 1 ) , 253then the current filename as well as the old and new flags are displayed. 254.Sh EXIT STATUS 255.Ex -std 256.Sh EXAMPLES 257Recursively clear all flags on files and directories contained within the 258.Fa foobar 259directory hierarchy: 260.Dl Nm Fl R Ar 0 Ar foobar 261.Sh SEE ALSO 262.Xr ls 1 , 263.Xr chflags 2 , 264.Xr stat 2 , 265.Xr fts 3 , 266.Xr security 7 , 267.Xr symlink 7 268.Sh HISTORY 269The 270.Nm 271command first appeared in 272.Bx 4.4 . 273.Sh BUGS 274Only a limited number of utilities are 275.Nm 276aware. 277Some of these tools include 278.Xr ls 1 , 279.Xr cp 1 , 280.Xr find 1 , 281.Xr install 1 , 282.Xr dump 8 , 283and 284.Xr restore 8 . 285In particular a tool which is not currently 286.Nm 287aware is the 288.Xr pax 1 289utility. 290