How to Lock a File on a Mac

How to Lock a File on a Mac

Want to make sure you won’t delete or change an important document, or one you’ve set up as a template perhaps? Find out here how to lock a file on a Mac using Finder and Terminal so it is read-only.

First, More Than Skin-Deep

The four familiar faces carved into Mount Rushmore’s massive front should have been all hollow.

For Gutzon Borglum, their artistic maker, had plans to carve a “Hall of Records” into the mountain. The gigantic room would hold documents and records of import to the United States’ history, such as the declaration of independence or the constitution.

The plan was as soon abandoned as it had been begun, and only a tunnel behind Lincoln’s head remains. It contains enamel panels that describe the mountain monument’s own story.

Lamentably, fulfilling its function as a time capsule, the tunnel is not publicly accessible; in any event, its documents and panels would be read-only:

How to Lock a File on a Mac

Using Finder

Time needed: 2 minutes

To lock a file on a Mac and protect it from changes or deletion using Finder:

  1. Click on the file you want to lock with the right mouse button.

    Finding: You can use Finder’s search field to locate the file or files you want to mark read-only, of course.
    More than one: You can select multiple files and mark them locked in Finder; for a larger number of files, locking them using Terminal is much more efficient; see below.
    Folders: You can also highlight and lock folders; see below for what that accomplishes.

  2. Select Get Info from the content menu that has appeared.

    Using the menu: You can also select File | Get Info from the menu with the files highlighted.
    macOS keyboard shortcut: The key combination for opening the information window is Command I.
    Open the info sheet for the file you want to use as a template in Finder

  3. Check Locked to mark the file read-only.

    Multiple files and windows: With more than one file selected, individual Info windows will open for all the files, and you will have to check Locked in each window.
    Templates: Locking is very useful for files you use a templates, of course.
    Unlocking: To make the file writable again, uncheck Locked.
    Locking a file in Mac Finder and marking it read-only

Using a Document Title Bar

To lock a file using its title bar in a Mac app (such as Preview, Keynote, Pages etc.):

  1. Hover the mouse over the file name in the title bar.
  2. Click the downward-heading arrowhead next to it.
  3. Now click Locked in the sheet that appears.
    Lock a document using its macOS title bar

Using Terminal

To make a file read-only using the Mac Terminal command line:

  1. Open Terminal in the folder that contains the file or folder you want to lock.
  2. Type chflags uchg <filename>.
    Filename: Replace <filename> with the file, files, folder or folders you want to lock; you can use shell wildcards, of course.
    Equivalent flags: In addition to uchg, you can also use uchange and uimmutable with the same effect.
    System locking flags: Exchange uchg with a system locking flag so only super-users can remove the lock; use schg, schange or simmutable.
    Example: chflags uchg *.png will lock all PNG (*.png) files in the current folder.
  3. Press Enter.
    Locking files using chflags on the Mac Terminal

This is equivalent to locking the file or folder. You can unlock a file locked in Terminal using the Finder dialog and vice versa.

Unlocking: To remove the lock, use chflags nouchg <filename>.

Remove Writing Permission (for Read-Only Files)

Independently from locking files, you can also remove writing permission for a file using classic Unix modes, of course:

  • Use chmod -w <filename> to remove writing permissions for all.
  • Use chmod o-w <filename> to make the file read-only for others (but leave it writable for the user and others in their group).

Only for Terminal: Note that these permissions only apply to command-line applications. They are not reflected and not editable in Finder.
Writeable again: To add writing permissions again, use chmod +w <filename>.

How to Lock a File on a Mac: FAQ

What happens when I try to delete a locked file?

If you try to delete a locked file or folder, macOS Finder will alert you but still allow moving the file to the Trash with confirmation.

When you empty the Trash, the locked files will be permanently deleted with all other files in it.

Can I override a file lock for writing, e.g., in Vim?

No.

If a file is marked locked in Finder or has the uchg flag (or a similar flag) set, you cannot force writing to the file, for example using a text editor such as Vim.

Can I also lock files in iCloud Drive?

Yes.

Locking files using Finder and chflags works on iCloud Drive just like it does on a local drive.

Can I also lock a folder?

Yes.

If you mark a folder locked using Finder or Terminal, the consequences are:

  • You cannot delete files from the folder.
  • You cannot add new files to the folder.
  • You cannot delete the folder.
  • You cannot move the folder
  • You can edit files in the folder that are not themselves locked.
  • You can copy the folder.

(How to lock a file on a Mac tested with macOS Sonoma 14.5; first published June 2024)

Home » Mac Tips and Resources » How to Lock a File on a Mac