File locking has a long tradition in IT – you and the Software that are running independently want to make sure that a file is not modified or deleted as needed or may be in use.
Since macOS is Unix-based, it offers file-level permission flags that control how and who can manipulate a particular file. But macOS has long had a separate way to lock a Finder file.
With this, the operating system prevents them from being changed, deleted or renamed from “Terminal” or other applications. Lock, unlock and status commands are also available via the command line in “Terminal”.
Note that Finder-oriented locking is completely different from setting a file to read-only permission in Finder or through ‘Terminal’, which involves changing Unix permissions.
I recommend that you don’t use read-only status for files and folders you work with in Finder and through apps because Finder doesn’t honor these permissions for files assigned to it in macOS through Unix permissions. .
Lock and unlock using the macOS Big Sur Finder
Turning the lock on and off in Finder is super easy. Just select the file or folder and choose “File> Get Info”. You can also select multiple files or folders and hold the “Option” key.
This opens a single “Get Info” window for multiple items called “Multiple Item Info”. A check box allows you to select or be unchecked.
You can use a script to see if the selected items are in a mixed lock / unlock state, or click to lock all files.
Before the macOS Big Sur version arrived, locked files had a lock image superimposed on their Finder icon. With Big Sur, only this blocking overlay is displayed in the “Get Info” dialog box.
Once the file is locked, it can be moved around in Finder, but it cannot be renamed or edited through apps. It can be deleted, but only if you confirm the operation.
Apple and third-party apps that support locking let you lock and unlock documents from the title bar. Click the down arrow to the right of the file name and check or uncheck the box.
Using ‘Terminal’
If you want to delve into macOS internals via ‘Terminal’, launch ‘Applications> Utilities> Terminal’ and navigate to a folder where you have locked an item. If your file is on the desktop, you can type this to get there:
cd ~ / Office
macOS reveals the locked state with a special flag in the Unix file list command, ls. Enter the following:
ls -lO front_door.jpeg
(This O is a capital letter). You can replace ‘front_door.jpeg’ with ‘*’ to list everything in the directory, use another specific file name, or enter a generic pattern, such as ‘license *’, which matches all files and folders starting with “license”.
The same is true for the example file name in all of the following cases. ‘Terminal’ will show you the term ‘uchg’ as a “flag” for any locked file, as in:
[email protected] 1 gif staff uchg 150293 March 8, 2020 front_door.jpeg
To lock and unlock a file in Finder, you can directly change this ‘uchg’ flag:
- To lock a file: chflags uchg front_door.jpeg
- To unlock a file: chflags nouchg front_door.jpeg
If you want to use yet another method, you can use ‘SetFile’, which allows you to change the attributes of a file:
- To lock a file: SetFile -a L front_door.jpeg (upper case L)
- To unlock a file: SetFile -al front_door.jpeg (lowercase l)
Read all about macOS Big Sur in this article and find out if you need to update your computer to the latest version.
Original article published in igamesnews United States.
.