Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I noticed that sometimes Mail.app locks files. The lock itself allows for files to be moved to Trash, but doesn't allow Trash to be emptied. (Perhaps Trash should be renamed Thrash in this case)

Is there a way (via a terminal command or an app) to see which app locks the file and/or unlock the file without quitting the app?

share|improve this question
    
+1 for Thrash.. –  Dan Ray Aug 17 '11 at 12:42
    
Haha! You got me. ;) –  Michal M Aug 17 '11 at 13:04

3 Answers 3

up vote 8 down vote accepted

As Rabarberski says, lsof can be used to find any process that has the file open. Note that you need to run the program as root, i.e., using sudo, and that you can give the pathname to the file you're interested in as an argument, so there is no need for the grep invocation in the hint that Rabarberski points to. Also, if a process holds a lock on the file, you're supposed to be able to see that from the FD column in the lsof output. See the manual page for the details. (When I run sudo lsof on my machine, I see no locked files, so I won't guarantee that this works right on the Mac. sudo is after all a generic unix program, and conceivably some features don't work on OSX.)

You cannot unlock a file without killing the process that holds the lock. But you can remove it with rm from the command line.

share|improve this answer
    
Just noted a silly misprint: Where it says “sudo is after all …” it was lsof I had intended to mention. Not going to edit it – it's too minor to warrant a bump to the front page. –  Harald Hanche-Olsen Oct 30 at 15:44

Apparently the lsof ("list of open files") terminal command can be used to do that: http://hints.macworld.com/article.php?story=20040121001144687

share|improve this answer

As others pointed out, lsof does the trick. To make the task even simpler, I suggest the (free) app "What's keeping me" (URL: http://www.hamsoftengineering.com/products/wkm/wkm.html) which is basically a frontend for lsof and has a few time-saving options.

share|improve this answer
1  
Link doesn't seem to work so here's alternative location: macupdate.com/app/mac/27807/what/'s-keeping-me? –  Michal M Aug 17 '11 at 13:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.