Have you ever wondered which application or system process is using a file. The annoying message usually pops up when you are trying to delete a file or folder within Finder. This little trick, using a Terminal command called lsof, allows you to find which application is using a file, its very useful if you dont know what application is using the file.
To use this command open up Terminal found in Applications Utilites and type lsof followed by a space. Lsof is designed to list open files, exactly what we need. The next step is to drag the file we are interested onto the finder window. This will set the file path automatically into Terminal, and saves us having to type a long string, as well as this it also makes sure that it is correct, especially if the path contains spaces.
When you hit enter, the command will take a couple of moments to do its thing as it works out what is happening. When it is done you will have an output similar to the following:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Finder 118 James 11r REG 14,2 36 1209045 /Users/James/Mac Tricks And Tips is Awesome.txt
This tells us that Finder is currently using the file. In this case Quicklook was open. As a result if you were trying to delete the file you can now go and investigate what is happening and see if there is Quicklook window open, or a Get Info pane in use. If there is an app open, with its name in the place of Finder, you can go an close that app.
If you cant be bothered to go hunting to see which application is open, or you have tried to close an application and it refuses to. You can always close it directly from Terminal. If you notice in the second column there is something called a PID. This is the unique number that only refers to one application. To close the application type the following into Terminal.
kill pid XXX
Where XXX is the PID. You should notice the application closes. If you are trying to delete or move a file or folder it should be accomplished.
This is a useful little command and is one I use frequently when things are not going my way. If you have any questions or comments, please leave one using the form below.
If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed.