Protect files with the Locked or Immutable flag
The Locked or Immutable flag is one of the most underused and readily accessible features in macOS. It can help you avoid deleting important files, and as I’ll show later can form the basis of your own lightweight version management system. However, this all depends on you keeping it well clear of iCloud Drive, which unaccountably can’t cope with it.
Use
You’ll already be aware that you can lock files in the Finder’s Get Info dialog.
You can also lock an open file inside an app. Click on the down arrow to the right of its name in the title bar to see this pane, then click on the padlock to lock that file.
Sequoia and older versions of macOS show a Locked checkbox rather than a padlock.
In Terminal, use the chflags command in the formchflags uchg filename
to set the user Immutable flag, the same thing as the Finder lock, and usechflags nouchg filename
to unlock it.
Terminal also supports a second flag schg for the system immutable flag, which can only be set or cleared by the super-user, so isn’t recommended for general use. You can check these flags using ls -lO, and full details of this and other flags are given in man chflags.
Effect
When locked or immutable, you can still delete a file by dragging it to the Trash, but when you do so, the Finder warns you of the presence of the flag.
If you press ahead, you get no second chance when you empty the trash, though, as the locked file will then be deleted immediately.
Retention
The Immutable flag is stored in the file’s attributes, in the bsd_flags value in the file’s inode. It’s therefore generally preserved in local file operations, including
- moving the file within a volume,
- duplicating or copying the file within a volume,
- copying the file to a different local volume,
except with iCloud Drive.
iCloud Drive
iCloud Drive (through the FileProvider framework) doesn’t preserve the Immutable flag as you would have expected, given that it’s a file attribute rather than an extended attribute. Copying an immutable file to an iCloud Drive folder unlocks the file immediately. As if to compensate for this deviant behaviour, the file will be copied to iCloud Drive rather than moved, so leaving the locked original where it is. This is even more confusing as this behaviour is propagated to all other files being moved at the same time. If you move ten files, one of which is locked, all ten are copied rather than moved; if none are locked, then the group is moved rather than copied. This is so bizarre that it can only be a bug.
If you lock the file when it’s in iCloud Drive, the lock isn’t synced through iCloud, so that file isn’t locked on other Macs sharing the same iCloud Drive folder, although it still behaves as expected on the Mac that copied it to iCloud Drive, and will trigger a warning if moved to the Trash, but only on that Mac. Those other Macs can delete that file without any warning of it being locked, indeed they can’t even see that it’s locked on the other Mac.
Locked files in iCloud Drive when operating in non-replicating mode (with Optimise Mac Storage enabled) can’t be evicted from local storage, as that results in the error Unable to Remove Download, Resource busy. They can, though, be pinned locally with the Keep Downloaded setting.
FileProvider doesn’t yet appear to cope with locked files in any consistent way. Given how long Macs have used BSD flags in their file systems, that’s an extraordinary shortcoming.
Versioning with locking
You can use locking and clone files in a lightweight versioning system that achieves good space economy. To do this:
- Save the first version of the document, lock it using its titlebar, and close the window.
- In the Finder, duplicate that locked first version, unlock the duplicate and edit its name appropriately.
- Open that new version of the document (a clone file), edit it until you want to save a new version, then return to 1 above, and repeat.
Note that using Save As to create a new version doesn’t result in a clone file, and the only alternative to protecting old versions is to make them read-only, as does Versatility.
Documentation
Apple’s accountman chflags

















