To write-protect a file from the command line on Apple OS X, you can use the chflags
command with the uchg
option. This will set the user immutable flag on the file, which will prevent it from being modified or deleted by any user, including the root user.
To write-protect a file using the chflags
command, you can run the following command, replacing /path/to/file
with the actual path to the file:
chflags uchg /path/to/file
This will set the user immutable flag on the file, which will prevent it from being modified or deleted.
To remove the write-protection from the file, you can use the chflags
command with the nouchg
option. For example, to remove the write-protection from the file, you can run the following command:
chflags nouchg /path/to/file
This will remove the user immutable flag from the file, allowing it to be modified or deleted again.
By using the chflags
command with the uchg
and nouchg
options, you can easily write-protect and remove write-protection from files on Apple OS X from the command line. This can be useful for preventing accidental changes to important files.