Does your Mac hold important data? Do others use your device? Are you prone to accidentally altering or deleting critical files? In any case, locking down your most valuable files can help prevent data loss and future frustration.

In macOS, you can use Finder and Terminal to lock files and folders to protect the most important ones. Let’s take a look at file locking in more detail and discuss how each method works.

Reasons for Locking Files and Folders in macOS

The main reason for locking files and folders in macOS is to avoid accidentally altering or deleting important items. The usefulness of the feature will depend on how you and others use your device.

If you share your user account with other people, locking your most valuable items may be beneficial. Even if you’re a solo user, accidents do happen, and any extra layer of protection against data loss is worth the effort.

Related: Tips for Managing Files or Folders in Finder on Your Mac

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 will prevent you from making any changes. Additionally, locking an entire folder applies the setting to everything within it, protecting all contained items from accidental alteration.

If you try to delete a locked file, macOS will prompt you to confirm before moving the item to the Trash.

Lock and Unlock Files and Folders in macOS Using Finder

The quickest and easiest way to lock a file or folder in macOS is through Finder. The process goes like this:

  1. Control-click the items you want to lock.
  2. Choose Get Info.
  3. Tick the Locked box.
Get Info window for a folder showing the locked box as ticked.

That’s all it takes. Locking will now protect the item from changes until you reverse the process. To unlock the file, simply remove the tick from the Locked box in the Get Info window. Locked items always display a small padlock on their icon in Finder, which makes identification easy.

Lock and Unlock Files and Folders in macOS Using Terminal

If you prefer to do things the hard way, you can use command lines to lock and unlock items. Although rarely required for simple tasks in macOS, Terminal is a great tool to learn for when complex issues arise. First, to check the lock status of an item, follow these steps:

  1. Launch Terminal.
  2. Enter the Terminal command below, replacing [file path] with the location of the item (for example, ~/downloads/document.rtf):
    ls -lO [file path]
  3. Press Return.
Terminal showing output after checking locked status on a file.

The uchg flag lets you know whether or not the item is locked. If uchg appears in the output, a lock is in place. If uchg isn’t present, the item is unlocked.

How to Lock an Item Using Terminal

To lock a file or folder using Terminal, follow these steps:

  1. Launch Terminal
  2. Enter the below Terminal command, replacing [file path] with the location of the item (for example, ~/downloads/document.rtf):
    chflags uchg [file path]
  3. Press Return.
Terminal showing lock file command.

The file should now be locked in the same way it would if you’d used the Finder method.

How to Unlock an Item Using Terminal

To unlock a file or folder using Terminal, follow these steps:

  1. Launch Terminal.
  2. Enter the below Terminal command, replacing [file path] with the location of the item (for example, ~/downloads/document.rtf|):
    chflags nouchg [file path]
  3. Press Return.
Terminal showing unlock file command.

As you can see, adding a simple “no” to the uchg flag orders macOS to set the item’s state to unlocked.

Locking Is Just One Method of Protection

When it comes to locking and unlocking items in macOS, using Finder is by far the simplest solution. You can, however, utilize Terminal if you prefer to add a little complexity to the task.

Locking isn’t a method of encryption, nor does it prevent others from accessing your files. A locked item simply requires unlocking before you can make any changes. If you’re seeking additional password protection for your data, you’ll need to explore some of the encryption options available in macOS.