Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Locked files and Mac OS X System
There's an annoying side effect of locking file when it comes to Mac OS X -- there's no fast way to override the state, like option-Empty Trash in OS 9.

Not only does this not exist, but the Finder will report that you do not have "sufficient privileges" to delete the file (which may be correct in a way, but rather misleading since we now have permissions to worry about).

Does anyone know of a quick way to remove file locks from the Terminal or another app? I've tried xFiles 1.0b1, but it doesn't seem to recognize that the files are locked at all.
    •    
  • Currently 5.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[92,211 views]  

Locked files and Mac OS X | 28 comments | Create New Account
Click here to return to the 'Locked files and Mac OS X' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
this can be done form the Terminal
Authored by: integral on Wed, Mar 28 2001 at 4:09PM PST
I've run into this same problem, where I couldn't delete a file because osX thought it was in use. If the file hasn't yet been moved to the trash, try to log into the terminal as root and use the rm command to delete it. Be careful that you're deleting the correct file, as by default rm does not ask for confirmation. You can use tab-completion to get osX to insert the filename for you. ie to delete a file called My File Is Locked, you could do this:

rm "My (then hit the tab key) " (put an endquote in there also)


Make any sense? also, if your file is already in the trash, you can search for it with sherlock, and then drag the icon to the Terminal - it's full path wil pop up, allowing for easy deletion.

Be careful with rm!



[ Reply to This | # ]
re: this can be done form the Terminal
Authored by: namtastic on Wed, Mar 28 2001 at 7:23PM PST
that's not actually the case with locked files.

if the file is locked, then when you try to rm, even as root, it prompts
"override <permissions> for <filename>?"
hitting y for yes returns
"rm: <filename>: Operation not permitted"
and the file stays there.


[ Reply to This | # ]
re: this can be done form the Terminal
Authored by: alanw on Sat, Apr 14 2001 at 1:11AM PDT
It is true that even as root via the Terminal you cannot use the usual UNIX "rm" command to delete locked files. This is disturbing (especially unsettling to one who has done Mac troubleshooting for years and is well acquainted with Murphy's Law--if something can go wrong, it will). Suppose that by whatever cause, malicious or otherwise, you find your disks filled with hundreds or thousands of locked files. There should be some backdoor method (certainly, I agree, not one to be invoked casually) to unlock them in batch fashion (apart from rebooting into Mac OS 9.1; perhaps someday that won't be an option).
Well, after puzzling over this for some time, I finally discovered that backdoor method. You need to have the Developer Tools installed. Open a Terminal window and type (without the quotes)
"/Developer/Tools/SetFile a -l <names of files to unlock>" You can use wildcards. "/Developer/Tools/SetFile a -l *" for example will unlock all files in the current directory. If some are already unlocked, their lock attribute remains unchanged. Experienced UNIX hackers will no doubt be able to use shell scripts or more complicated command combinations to unlock in batch fashion any files anywhere.


[ Reply to This | # ]
re: this can be done form the Terminal
Authored by: alanw on Sat, Apr 14 2001 at 1:19AM PDT
Correction: That should have been "/Developer/Tools/SetFile -a l <names of files>" and
"/Developer/Tools/SetFile -a l *"
I knew I shouldn't have stayed up this late. :-)

[ Reply to This | # ]
re: this can be done form the Terminal
Authored by: sauy7 on Sat, Oct 30 2004 at 6:39AM PDT
Here's a simple bash script to run in a Terminal window

#! /bin/bash
#
# Simple file unlocking utility for Mac OS X
#
ARGS=1
E_BADARGS=65

function recursiveUnlock() {
    pushd $1
    for rdir in `ls -A`; do
        if [ -d "${rdir}" ]; then
            recurse ${rdir}
        else
            /Developer/Tools/SetFile -a l ${rdir}
        fi
    done
    popd
}

if [ $# -ne "$ARGS" ]
then
    echo "Usage: `basename $0` starting-directory"
    exit $E_BADARGS
fi

recursiveUnlock $1
Usage (code saved as an excutable file recursiveUnlock.sh):

$ ./recursiveUnlock.sh /path/to/top-level/dir
unlocks all files in dir, including those in dir's sub-directories

---
sauy7

[ Reply to This | # ]

re: this can be done form the Terminal
Authored by: gwik on Wed, Mar 1 2006 at 9:55AM PST
$ find *the_root_dir* -type d -exec /Developer/Tools/SetFile -a l {} \;

[ Reply to This | # ]
this can be done form the Terminal
Authored by: rodrat on Mon, Dec 9 2002 at 5:39PM PST
To trash a locked file,I found the problem is hidden files. control
click on the folders that won't open and click on reveal to open folder.
Then unlock hidden file with GETINFO!

[ Reply to This | # ]
this can be done form the Terminal
Authored by: rodrat on Mon, Dec 9 2002 at 5:42PM PST
To trash a locked file,I found the problem is hidden files. control
click on the folders that won't open and click on reveal to open folder.
Then unlock hidden file with GETINFO!

[ Reply to This | # ]
this can be done form the Terminal
Authored by: tolba on Mon, Apr 10 2006 at 7:32PM PDT
I have tried almost every suggestion I have seen to delete a particular file. This file is on an external hard drive, it is locked and no matter what I do it will not go away. It is not a virus it is a fractal software program. I will take all the help I can get. Please be gentle I am new at this terminal window thing.

thanks
tolba

[ Reply to This | # ]
Do it the old way
Authored by: yuriwho on Sat, Mar 31 2001 at 1:10AM PST
hit cmnd-I to launch the inspector and un-check the "locked" checkbox for the offending file. I know this is slow but that's the purpose of locking a file...to prevent it from being casually deleted. With OS X we can prevent casual deletion with permissions so this is less of an now and locked files are a now a PITA. I agree, Apple should enable the option-empty trash combo for OS X.

Y

ps. do you know about shift-cmnd-delete then return shortcut in the finder to empty your trash? Better then nothing, but no option overrides are available that I know of

[ Reply to This | # ]
Do it the old way
Authored by: mchoya on Tue, Mar 21 2006 at 2:23PM PST
Thanks! This worked like a charm. I have had this locked file on the desktop for months.

[ Reply to This | # ]
Unlocking files using Terminal
Authored by: vxbush on Tue, May 29 2001 at 5:33PM PDT
I don't mind unlocking files on an OS 9 volume using "Get Info", but I find it really aggrivating to do this for a folder with more than five files. I frequently have thirty or more files that that are all locked, and it gets really annoying.


I used Terminal and did an ls -la, and saw the following:



-rwxrwxrwx 1 vbush notes - 1082304 May 1 12:58 file1*
-rwxrwxrwx 1 vbush notes uchg 105698 Apr 19 14:17 file2*

The first file is not locked; the second file is. Notice the "uchg" entry. How can I go through and remove this from all the files? I can't tell what kind of attribute this is.

--vb

[ Reply to This | # ]
Re: Unlocking files using Terminal
Authored by: blb on Tue, May 29 2001 at 11:41PM PDT
uchg is the 'user immutable' flag (ie, you can't delete it, as you've found). I know of two ways to clear this flag, either use (from a Terminal) the chflags command (see man chflags for info); the other, grab ChangeFileFolderProps to do this with a GUI.

[ Reply to This | # ]
Unlocking files using Terminal
Authored by: ankh on Mon, Dec 9 2002 at 8:53PM PST
I noticed I can select All of a group of files, get information, and it'll let you unlock everything selected. Had no idea it would do that.

Hope it does it tomorrow. Never can seem to predict what X will do, yet.

[ Reply to This | # ]
Unlocking many files
Authored by: absorber on Thu, Dec 13 2001 at 9:42PM PST
I recently had the bad luck of running NAV 7 and it locked about 70 per cent of the files on my hard drive. This creates a real problem when the locked files are preferences or identities and such. I considered trying to write a script to unlock them but have selectively been unlocking them using the Get Info (CMD I). The trick to doing it fast is to sort the files in List View by Kind. Then select ALL the individual files in the list, deselecting any folders you accidentally select. Now press Command I and the Get Info Window will appear. If none of the files are locked the check box in the window will be empty. If all the files are locked the check box will be checked. If there is a mixture of locked and unlocked, a dash will be in the box. Click on the box to change them all to unlocked. (I don't know if there is a limit to the number of files you can open at once, but I have done a bunch.) Open the next folder and repeat...

This is the fastest method I have found. If anyone knows of an easier method or has written a script to go through a whole drive and unlock all the files, I would love to try it. Meanwhile no more Norton for me.



[ Reply to This | # ]
Locked files and Mac OS X
Authored by: stefan724 on Fri, Jan 7 2005 at 4:00PM PST
I found a little freeware program called locker that will handel multiple files. Works good for me.

http://www.vojousoftware.com/products.html

[ Reply to This | # ]
Locked files and Mac OS X
Authored by: tipstuff on Sat, Jan 15 2005 at 8:07AM PST
There is also another way I discovered.
you can take any amount of files and in the stuffit pref just select delete original. then simply make and archive and delete it.
Hope it will work for you too.

[ Reply to This | # ]
Locked files and Mac OS X
Authored by: kcoates55 on Wed, Mar 29 2006 at 9:52AM PST
This is a great little program. I have OS 9 on a separate hard drive so booting into OS 9 didn't work and I'm terrified of the terminal. Thanks for your contribution!

[ Reply to This | # ]
Locked files and Mac OS X
Authored by: renderhead on Fri, Jan 21 2005 at 4:35PM PST
Using other comments in this thread for reference, I managed to put together the following procedure for unlocking every file in a directory and all of its sub-directories. When a file is "locked" by OS X, it is applying what *nix calls a "flag" to the file. In this case, the flag is "uchg", which means that no user, even root, can alter the file in any way until the flag is removed. You can use the command chflags to remove the flag.

The following example should unlock every file in your home directory:

sudo chflags -R nouchg ~/
Here's a breakdown of the command:

sudo will run the chflags command as root (you may be prompted for your root password).

-R will cause the command to affect every file in the directory and all of its subdirectories. Yes, capitalization matters.

nouchg is the syntax for removing the uchg flag. Any flag can be removed by putting "no" in front of it.

You can of course substitute the tilde (~) with whatever directory path you want to affect. To change an individual file, leave out the -R and type the file path instead of a directory path. Normal operators apply, such as $ and *.

[ Reply to This | # ]

For the Trash...
Authored by: renderhead on Fri, Jan 21 2005 at 4:48PM PST
To apply my above hint to items already in the trash, use:
sudo chflags -R nouchg ~/.Trash
To empty the trash entirely, add a simple
rm -f ~/.Trash/*
I'll bet someone who knew their applescript could write up a simple "Force Empty Trash" menu item based on those two commands.

[ Reply to This | # ]
Locked files and Mac OS X
Authored by: johnsawyercjs on Sat, Jan 22 2005 at 2:35AM PST
The utility "BatCHmod" will let you drag any file, folder, or volume to it, and then let you unlock all items inside that item.

[ Reply to This | # ]
Locked files and Mac OS X
Authored by: tribe on Thu, Apr 5 2007 at 8:46AM PDT
Hi,

you can easily unlock multiple files and folders using the terminal. Just follow the instructions :

http://docs.info.apple.com/article.html?artnum=106272

cheers

[ Reply to This | # ]
Locked files and Mac OS X
Authored by: jakecollins on Sat, Jan 12 2008 at 4:30PM PST
Guys, guys, guys.. There is a much easier way using the GUI in 10.4. Read on.

I don't mind using terminal sometimes, but let's face it why not use the GUI if possible?

Normally if you select multiple files and then to command I you'll get a ton of windows coming up and you'll have to individually unlock each file. Here's the magic. Hold down alt and command when you press 'I'. You now only get one window showing multiple file info, meaning one or two clicks to unlock all the files in one go. Another great thing is the mulitple file info window does not even need to be closed. Once you've finished in one folder simply move to the next and select more files.

I think this is what Absorber was trying to explain in his post. He missed out the vital step of using alt and command together though. You also don't need to go to list view, it works in any finder view.

[ Reply to This | # ]
Locked files and Mac OS X
Authored by: jemacd on Sun, May 4 2008 at 10:48AM PDT
How I do it is as (after going through all the terminal scripts and other 'solutions')

If you cannot un-check the 'locked' check box when 'get info' is invoked (or if you can but you STILL have un-deletable files), then open trash and follow the path inside the folder(s) to the end file/folder that has a tiny padlock on the bottom left.

Then, 'get info' for that specific one and un-check the locked box.

Do this for each individual file/folder (yep, its a pain) and you will magically be able to empty the trash.

I think the terminal script way (published in several places, including the max site) didn't work because the route path wasn't specific to the individual lock.

Anyway - hope this helps peeps.

JMac


[ Reply to This | # ]
Locked files and Mac OS X
Authored by: inspired_tmu on Tue, Jan 20 2009 at 1:51PM PST
This was exactly what I was looking for! Thanks!

The command I ended up using:

sudo chflags nouchg <filename>

[ Reply to This | # ]
Locked files and Mac OS X
Authored by: alekksa on Sat, May 2 2009 at 9:12PM PDT
I am using software called FileBuddy. It also have function to search all Locked files and you can remove Locked status from all the files (or just from selected) with a click.

FileBuddy is excelent software and I can't imagine using Mac without it.

[ Reply to This | # ]
Locked files and Mac OS X
Authored by: acampbell on Mon, May 4 2009 at 1:49PM PDT
Files get locked that I never locked, so it has been frustrating. The easiest why I have found (at least with photos, not sure if it applies to all files) is to view it through Adobe Bridge. Select all and right click. If just one of the selected files is locked you'll get an option to "unlock all", if no files are locked that option will not be available.

Hope this helps. If anyone knows how to prevent these files (usually happens with files being shared through a shared folder) from locking please advise.

thanks

[ Reply to This | # ]
Locked files and Mac OS X
Authored by: barfalot on Wed, Dec 9 2009 at 9:17PM PST
Just run the following command from within the root of the directory of files and sub-directorys whenever you have a lot of locked files. It will unlock every one recursively without writing a shell script. Mac OS X and up.


$sudo find . -print -exec Setfile -a l {} \;

[ Reply to This | # ]