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:
- 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. - 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. - 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.
Using a Document Title Bar
To lock a file using its title bar in a Mac app (such as Preview, Keynote, Pages etc.):
- Hover the mouse over the file name in the title bar.
- Click the downward-heading arrowhead next to it.
- Now click Locked in the sheet that appears.
Using Terminal
To make a file read-only using the Mac Terminal command line:
- Open Terminal in the folder that contains the file or folder you want to lock.
- 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 touchg
, you can also useuchange
anduimmutable
with the same effect.
System locking flags: Exchangeuchg
with a system locking flag so only super-users can remove the lock; useschg
,schange
orsimmutable
.
Example:chflags uchg *.png
will lock all PNG (*.png) files in the current folder. - Press Enter.
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)