File locking has an extended custom in computing: you or independently working software program desires to ensure that a file isn’t modified or deleted when it’s wanted or in use. As a result of macOS is Unix primarily based, it presents file-level permissions flags that management how a file may be manipulated and by whom.
However macOS has lengthy had a separate approach to lock a file from the Finder that additionally prevents it from being modified, deleted, or rename from the Terminal or different apps. Lock, unlock, and standing instructions are additionally out there by way of the command line in Terminal.
(Observe that Finder-oriented locking is solely completely different from setting a file to read-only permission both within the Finder or by way of the Terminal, which includes altering Unix permissions. I like to recommend not utilizing read-only standing for recordsdata and folder you’re employed with within the Finder and by way of apps, because the Finder doesn’t honor these permissions for recordsdata which are assigned to you in macOS by way of Unix permissions, which usually contains every thing in your house listing.)
Lock and unlock by way of the Finder in macOS Massive Sur
Turning the lock on and off within the Finder is extremely easy. Choose one file or folder and select File > Get Data; or choose a number of recordsdata or folders and maintain down Choice whereas selecting File > Present Inpector—the Choice key opens a single Get Data window for the a number of objects known as A number of Objects Data. A Locked checkbox may be chosen or deselected. It reveals a – (sprint) if the objects chosen are in a combined state of being locked and unlocked; clicking will lock all the recordsdata.

macOS used to indicate an overlaid lock icon as at left in Mojave; in Massive Sur, at proper, it not offers this indicator within the Finder.
Previous to Massive Sur, locked recordsdata would have a lock picture overlaid on its icon within the Finder. Massive Sur solely reveals that lock overlay within the Get Data dialog field.

Massive Sur prompts you to verify eradicating a locked file.
As soon as the file is locked, it may be moved round within the Finder, however not renamed or modified by way of apps. It may be deleted, however provided that you affirm the operation.
Apple’s apps and people of third events that assist the conference additionally allow you to lock and unlock paperwork from the titlebar: click on the downward-pointing arrow to the best of the file identify after which choose or deselect the Locked checkbox.

Pages and different apps allow you to lock and unlock paperwork from the titlebar.
Utilizing the Terminal
If you happen to wish to poke at macOS’s internals by way of Terminal, launch Functions > Utilities > Terminal and navigate to a folder that you just’ve locked an merchandise in. In case your file is on the Desktop, you may kind this to get there:
cd ~/Desktop
macOS reveals the lock standing with a particular flag on the Unix file-listing command, ls
. Enter this:
ls -lO front_door.jpeg
(That’s a capital letter O there.) You’ll be able to change front_door.jpeg
with *
to record every thing within the listing, use one other particular filename or enter a wildcard sample, like license*
, which matches all recordsdata and folders beginning with “license”. The identical is true for the file identify instance in all of the beneath instances.
Terminal will present you the time period uchg
as a “flag” for any locked file, as in:
[email protected] 1 gif workers uchg 150293 Mar 8 2020 front_door.jpeg
To lock and unlock a file within the Finder, you may instantly modify that uchg
flag:
- To lock a file:
chflags uchg front_door.jpeg
- To unlock a file:
chflags nouchg front_door.jpeg
In order for you yet one more technique, you should utilize SetFile, which helps you to change attributes on a file:
- To lock a file:
SetFile -a L front_door.jpeg
(capital L) - To unlock a file:
SetFile -a l front_door.jpeg
(lowercase l)
This Mac 911 article is in response to a query submitted by Macworld reader Beverly.
Ask Mac 911
We’ve compiled an inventory of the questions we get requested most incessantly together with solutions and hyperlinks to columns: learn our tremendous FAQ to see in case your query is roofed. If not, we’re all the time on the lookout for new issues to unravel! E-mail yours to [email protected] together with display captures as applicable, and whether or not you need your full identify used. Not each query shall be answered, we don’t reply to electronic mail, and we can’t present direct troubleshooting recommendation.