How to lock files and folders in macOS?
Does your Mac save important data? Want to lock a file on your Mac so you don't accidentally edit or delete it? Here's how to do this using the Finder or Terminal.
Reasons to Lock Files and Folders in macOS
The main reason to lock files and folders in macOS is to avoid accidentally changing or deleting important items. The usefulness of this feature depends on how you and others use your device.
Here's how the feature works: Locking a document or other editable item means you can open the file and read the content, but macOS prevents you from making any changes. Additionally, locking an entire folder applies the setting to everything within it, protecting all contained items from accidental changes.
If you try to delete a locked file, macOS prompts you for confirmation before moving the item to the Trash.
Lock and unlock files and folders in macOS using the Finder
The fastest and easiest way to lock a file or folder in macOS is through the Finder.
Control-click the item you want to lock.
Select "Show Info".
- Tick the "Locked" box.
Locking will now protect the item from changes until you undo the process. To unlock the file, simply remove the tick from the Locked box in the Get Info window. Locked items always show a small padlock on their icon in the Finder, which makes identification easy.
Lock and unlock files and folders in macOS using Terminal
First, to check the lock status of an item, follow these steps:
- Start Terminal.
- Enter the following terminal command, replacing "file path" with the location of your project (for example, ~/downloads/document.rtf):
ls -lO "file path"
- Tap Enter.
The UCHG flag lets you know if the item is locked. If uchg appears in the output, the lock is in place. If uchg is not present, the item is unlocked.
How do I lock a project using the terminal?
To lock a file or folder using Terminal, follow these steps:
Start Terminal.
Enter the following terminal command, replacing "file path" with the location of your project (for example, ~/downloads/document.rtf):
chflags uchg "file path"
- Tap Enter.
The file should now be locked in the same way as using the Finder method.
How to unlock items using the terminal?
To unlock a file or folder using Terminal, follow these steps:
Start Terminal.
Enter the following terminal command, replacing "file path" with the location of your project (for example, ~/downloads/document.rtf|):
chflags nouchg "file path"
- Tap Enter.
Adding a simple "no" command to the uchg flag macOS sets the item's state to unlocked.
Using the Finder is the easiest solution when locking and unlocking items in macOS. If you want to add a little more complexity to your task, you can use the terminal.
Locking is not a method of encryption, nor does it prevent others from accessing your files. A locked item can simply be unlocked to make any changes. If you're looking for extra password protection for your data, you'll want to explore some of the encryption options available in macOS.
MacOS問題解答