Lock and unlock files with chflags uchg

Beyond hiding files, chflags can set the user-immutable (uchg) flag — the command-line equivalent of Finder's Locked checkbox, which protects a file even from the file's owner.

macOSlockchflagsuchgLow risk
Run `chflags uchg important.doc` to lock the file and `chflags nouchg important.doc` to unlock it.

01Command

Command
$ chflags uchg important.doc
chflags nouchg important.doc

02What it does

The uchg flag is enforced by the kernel: while set, the file cannot be modified, renamed, deleted, or have its contents changed, even by the owner, until the flag is cleared. This is stronger than chmod's read-only bits, which the owner can trivially change back, and it survives most accidental edits.

03Risk

RiskLow risk
!Warning: Attempted writes to a locked file fail with 'Operation not permitted'; many apps just show a cryptic error, so unlock first (nouchg) before editing.

04Undo

Undo
$ chflags nouchg important.doc

05Sources

Last verified: 2026-09-17 · Category: Files & Folders