用 chflags uchg 锁定与解锁文件
除了隐藏文件,chflags 还能设置用户不可变更(uchg)标志——相当于访达"已锁定"复选框的命令行版本,连文件所有者都无法改动文件。
运行 `chflags uchg important.doc` 锁定文件,运行 `chflags nouchg important.doc` 解锁。
01命令
命令
$ chflags uchg important.doc
chflags nouchg important.doc02作用说明
uchg 标志由内核强制执行:设置后文件无法被修改、重命名、删除或改变内容,连所有者也不行,直到标志被清除。这比 chmod 的只读位更强——所有者可以随意把只读位改回来,而 uchg 能挡住大多数误编辑。
03风险
!注意: 向锁定文件写入会报"Operation not permitted";许多应用只会显示含糊的错误,编辑前请先用 nouchg 解锁。
04撤销
撤销
$ chflags nouchg important.doc05来源
- chflags — change file flags on macOS依据: Documents the uchg (user immutable) flag and its negation nouchg.
最后验证: 2026-09-17 · 分类: 文件与文件夹