Programming Tutorials

chflags in Mac OS X

By: Strauss K in macos Tutorials on 2011-02-03  

The chflags command in Mac OS X is used to change the file or directory flags. File flags are the attributes that can be set on a file or directory to modify its behavior or state. The chflags command can be used to set or unset the file flags.

The syntax of the chflags command is as follows:

chflags [ -R [-H | -L | -P]] flags file...

Here, the options are:

  • -R: Recursively change the flags of all files and directories in the specified directory hierarchy.
  • -H: If a command-line argument is a symbolic link to a directory, recursively change the flags of the directory the symbolic link refers to.
  • -L: If a command-line argument is a symbolic link, change the flags of the symbolic link itself rather than the file or directory it refers to.
  • -P: Do not follow symbolic links; instead, change the flags of the symbolic link itself.

The flags are a series of one or more letters, which represent the file or directory flags. Some commonly used flags are:

  • arch: Set the archived flag.
  • hidden: Set the hidden flag.
  • nohidden: Unset the hidden flag.
  • sappnd: Set the system append-only flag.
  • noappnd: Unset the system append-only flag.
  • uchg: Set the user immutable flag.
  • nouchg: Unset the user immutable flag.
  • hidden: Set the hidden flag.

Here are some examples of how to use the chflags command:

Set the hidden flag on a file:

chflags hidden myfile.txt

Unset the hidden flag on a file:

chflags nohidden myfile.txt

Set the immutable flag on a file:

chflags uchg myfile.txt

Unset the immutable flag on a file:

chflags nouchg myfile.txt

Recursively set the hidden flag on all files in a directory

chflags -R hidden mydirectory





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in macos )

Latest Articles (in macos)