Managing locked files in OS X
In OS X there are several ways to prevent access to files, including putting them in locked disk images or changing their permissions setting so only select accounts on the system are permitted to read them.
In addition to these options, the OS X Finder supports another method of locking a file. When you open the information window for the file, you can check the Locked check box to prevent the file from being edited, even by people who otherwise have access to it. When this lock is enabled, the file’s icon in the finder will have a small lock appended to its lower-left corner.
This option sets a lock flag for the file that is recognized system-wide and not just by the Finder or by applications that users generally interact with. So not only will applications like TextEdit and Pages not be able to edit the locked file, but command-line tools and other tasks should also be prevented from modifying it.
Not only will the lock prevent most tools from editing the file, but it also supersedes file permissions and extended attribute settings, so not even commands and programs run under the root account will be able to edit it with the lock enabled. This is significant for power users who make use of the Terminal, since if they cannot edit a file even when they try using “sudo,” then the file may be locked. As an extra hurdle for those who use the Terminal, there is no obvious indicator such as the Finder icon that will show you the file is locked–it just will not be editable.
In addition to potential frustrations with locks when managing files in the Terminal, sometimes the Finder itself will provide obstacles when managing locked files. While you should be able to use the Finder’s information window to set and remove file locks, sometimes the Finder will not allow you to do this. In most cases, the Finder will merely prevent the lock from being set in the first place; however, at times the file’s lock setting may be set but will be grayed out so you cannot unlock it.
Luckily, if you do run into problems with a file that cannot be edited, either in the Terminal or in the Finder, you can unlock it by performing the following steps using the Terminal:
- Open the Terminal.
- Type the following command, followed by a single space (do not press enter yet).
sudo chflags nouchg
- Drag the locked file from the Finder to the Terminal window to complete its full folder path.
- Press Enter to run the command, supplying your password when prompted.
When run, this command will undo the lock flag for the file, regardless of whether you own the file. While an enabled lock will prevent the file from being edited, ultimately it is designed to be a temporary hurdle that can be undone by any user who has access to the file.[ Source: https://www.cnet.com/ ]