Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Deleting absolutely undeletable files System
I had somehow managed to create a file which simply defied deletion. I was pretty sure I'd created the file, as it was named "testfile" and was in my Documents folder. I'm not sure what I was testing, but the file was simply locked into place. Everything I tried failed to remove this file -- I made sure it wasn't "locked" in the Finder, I tried putting it in another folder first, and I even tried 'sudo chflags nouchg,noschg testfile' in the Terminal. Still, I couldn't even put the file in the trash, and if I tried to delete it as root, I received "Operation not permitted".

I finally killed it by switching to single-user mode and then changing the flags:
% sudo shutdown now               [ends Aqua and enter single-user mode]
% su [become root]
% chflags nouchg,noschg testfile [change the two flags I thought responsible]
% rm testfile [get rid of it!]
% exit [end root]
% exit [restart Aqua]
This did the trick; the file is now history, and no true restart was required (dropping to single-user from Aqua and then exiting back to Aqua is much faster than two restart cycles) ... my 'uptime' even survived intact :-).

Read the rest of the article if you'd like an explanation as to why this had to be done in single-user mode (thanks to Marc D. for providing the addition insight).

Marc D. writes:
In response to another recent thread regarding undeletable files, here's the story (for at least some of these cases):

The key problem is, indeed, the schg flag. If this is set, it will prevent a file from being deleted. I had this problem, and here is what I learned from solving it.

You can set the schg flag as root, in a normal Mac OS X Terminal session. But once set, you CANNOT clear the unless you go into single-user mode. Once in single-user mode, use 'chflags' to turn the schg bit off (as shown above).

Why does it act like this? Well, clearing the schg bit requires that the kernel's 'secure level' be set to 0 or less. In a standard OS X boot, the secure level is set to 1, which restricts certain functions, such as clearing the schg flag. When booted into single-user, the secure level is set to 0, which does allow you to clear to the schg flag.

Some general references on kernel security levels and chflags can be found at: and your kernel security level.

Hope this helps.
  • Currently 4.00 / 5
  You rated: 4 / 5 (3 votes cast)

Deleting absolutely undeletable files | 5 comments | Create New Account
Click here to return to the 'Deleting absolutely undeletable files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
OS 9 is culprit
Authored by: slord on Nov 24, '01 03:44:12PM

I've had this same problem. Turned out I was copying files from OS 9 over to my OS X disk. It would appear that the "LOCK" feature in the info boz for OS 9 is NOT THE SAME as OS X. In fact you cannot see that an OS 9 file is locked. I usually just reboot into OS 9, unlock the file and delete it.

I don't know why it's so hard for Apple to let root delete these damn OS 9 locked files.

[ Reply to This | # ]
OS 9 is culprit
Authored by: agrajack on Nov 24, '01 05:48:14PM

sudo rm -f testfile

[ Reply to This | # ]
Tried that one...
Authored by: robg on Nov 24, '01 06:01:54PM

"Operation not permitted."

I tried every trick I've ever seen for deleting files (short of rebooting in OS 9; that seems like cheating). The file would NOT be deleted.


[ Reply to This | # ]
Different problem...
Authored by: etwoy on Oct 30, '02 04:14:16PM

If a file is locked, you can use "SetFile" from the developer tools to unlock it from the command line...


[ Reply to This | # ]
Deleting absolutely undeletable files
Authored by: ewelch on Feb 15, '06 08:34:28AM

Did not work.

By the way, your instructions don't work either. You forgot the -H flag in the shutdown command. And it doesn't just drop from Aqua, it shuts the computer down. So the two reboots are required.


Ernest Hemingway's writing reminds me of the farting of an old horse. - E.B. White

[ Reply to This | # ]