Skip to content

What is chflags MacOS command?

The MacOS chflags command allows users to modify file flags for improved security and control over file access and permissions.

Terminal window
chflags [options] [parameters] file
OptionDescription
-RRecursively set flags
-vExplain what is being done
-hOperate on a symlink
-archSet architecture hint
ParameterDescription
flagsA comma-separated list of flags to set
fileThe file(s) to which the flags will be set
Terminal window
chflags hidden myfile.txt

This command hides the file “myfile.txt” in Finder.

Terminal window
chflags uchg important_document.doc

Sets the “uchg” flag on the file “important_document.doc” to prevent it from being deleted or modified.

Terminal window
chflags nohidden hiddenfile.txt

Reveals the hidden file “hiddenfile.txt” in Finder by removing the hidden flag.

Terminal window
chflags schg important_file.txt

Locks the file “important_file.txt” to prevent any changes or deletions.

Terminal window
chflags nouchg myfile.doc

Removes the “uchg” flag from the file “myfile.doc” to restore default permissions.

To use the chflags command in bash, execute the following command:

Terminal window
chflags -R hidden /path/to/directory

What is the purpose of the chflags command in MacOS?

Section titled “What is the purpose of the chflags command in MacOS?”

The chflags command in MacOS is used to change file flags or file attributes such as hidden, immutable, archived, and more.

How can I make a file immutable using chflags?

Section titled “How can I make a file immutable using chflags?”

To make a file immutable using chflags, run the following command:

Terminal window
chflags uchg /path/to/file

How do I recursively remove the hidden flag from a directory with chflags?

Section titled “How do I recursively remove the hidden flag from a directory with chflags?”

You can recursively remove the hidden flag from a directory using the chflags command with the “nohidden” option as shown below:

Terminal window
chflags -R nohidden /path/to/directory

What does the “uchg” flag do in the chflags command?

Section titled “What does the “uchg” flag do in the chflags command?”

The “uchg” flag in the chflags command sets the user immutable flag, which prevents the file or directory from being modified or deleted even by the superuser (root).

How can I list the flags set on a file using chflags?

Section titled “How can I list the flags set on a file using chflags?”

To list the flags set on a file using chflags, you can use the following command:

Terminal window
ls -lO /path/to/file

Can chflags be used to hide files in MacOS?

Section titled “Can chflags be used to hide files in MacOS?”

Yes, the chflags command can be used to hide files in MacOS by setting the hidden flag on the desired file or directory.

How do I clear all flags from a file with chflags?

Section titled “How do I clear all flags from a file with chflags?”

To clear all flags from a file using chflags, you can run the following command:

Terminal window
chflags 0 /path/to/file
  1. Set or clear various attributes of files or directories such as immutable, archived, hidden, nodump, sappend, schg, simmutable, sunlnk, uappend, uchg, uimmutable, and urestricted.
  2. Allow files or directories to be inaccessible or undeletable by certain users.
  3. Manage file and directory permissions and access control.
  4. Provide additional security and protection for sensitive files or directories.
  5. Prevent accidental deletion or modification of critical system files.