Change a file or folder’s flags.
Syntax chflags [-fhvx] [-R [-H | -L | -P]] flags file-or-folder ... Options -R Recurse: Change the file flags of file-or-folder hierarchies rooted in the files instead of just the file-or-folder themselves. So if the given folder contains files or sub-folders, apply the change to them all. Beware of unintentionally matching the .. hard link to
the parent directory when using wildcards like ".*". -R -H Follow symbolic links on the command line by default Symbolic links within the tree are not followed. -R -L All symbolic links are followed. -R -P No symbolic links are followed. (default) -f Do not display a diagnostic message if chflags could not modify the flags for file-or-folder, nor modify the exit status to reflect such failures. -h If the file-or-folder is a symbolic link, change the file flags of the link itself rather than the file to which it points. -v Cause chflags to be verbose, showing filenames as the flags are modified. If the -v option is specified more than once, the old and new flags of the file will also be printed, in octal notation. -x Do not cross mount points.
The flags are specified as an octal number or a comma separated list of keywords.
hidden Set the hidden flag [Hide item from GUI]
Keywords and keyword aliases - Owner or Super-user only:
opaque Set the opaque flag nodump Set the nodump flag uappnd, uappend Set the user append-only flag uchg, uchange, uimmutable Set the user immutable flag uunlnk, uunlink Set the user undeletable flag
Keywords and keyword aliases - Super-user only:
arch, archived Set the archived flag sappnd, sappend Set the system append-only flag schg, schange, simmutable Set the system immutable flag sunlnk, sunlink Set the system undeletable flag
The immutable flag makes the file/folder Locked/Protected and is equivalent to locking the file in Finder’s Show Info box.
Putting the letters no before an option causes the flag to be turned off.
For example: uchg Means the file cannot be changed nouchg Means the file can be changed (immutable bit cleared) hidden Will set the hidden flag nohidden Will remove the hidden flag
In early versions of macOS locked/immutable files could not be deleted from the trashcan. In Mac OS X 10.1 and later locked files can easily be deleted by pressing press Shift-Option or Option key combination while emptying the Trash.
Symbolic links do not have flags, so unless the -H or -L option is set, chflags on a symbolic link always succeeds and has no effect. The -H, -L and -P options are ignored unless the -R option is specified. In addition, these options override each other and the command’s actions are determined by the last one specified.
The sappnd and schg flags can only be unset when the system is in single-user mode. chflags(2).
Use ls -lO to see the flags of existing files.
The return status is zero if the mode is successfully changed,and >0 if an error occurs.
Lock the folder "finance" against changes:
$ chflags uchg finance
Unlock the folder named "finance" and allow changes to all the contents:
$ chflags -R nouchg finance
Make the folder ~/Library visible (this was the default setting prior to OS X Lion):
$ chflags nohidden ~/Library
An alternative method to view the library is to use the 'Go' drop down menu in Finder and hold down the option key:
Hide the folder ~/Library from finder:
$ chflags hidden ~/Library
Make the file MyLogs.txt append-only:
$ chflags uappnd MyLogs.txt
Unlock your Documents directory and everything in it:
$ chflags -R nouchg ~/Documents
“Fifteen referees. I want fifteen referees to be at this fight because there ain’t no one man who can keep up with the pace I’m gonna set except me. There’s not a man alive who can whup me. I’m too fast. I’m too smart. I’m too pretty. I should be a postage stamp. That’s the only way I’ll ever get licked” ~ Muhammad Ali
Local man page: chflags - Command line help page on your local machine.
HT1526 - Empty the (locked) trash with chflags.
ln - Make links between files (hard links, symbolic links).
ls - List information about file(s).
setfile - Set attributes of HFS+ files.
xattr - Edit or remove extended file attributes, including 'Where From' website data.