Guides/Which app is using a file

How to find which app is using a file on a Mac

Atta 🐬

Founder, Vitals

Published

Quick answer

To find which app has a file open on a Mac, type lsof and a space in Terminal, drag the file into the window and press Return. The first column names the process. For a folder, lsof +D lists everything open inside it. In Activity Monitor, double-click a process and open Open Files and Ports, which helps when you already suspect an app. Quit that app and the file is free. Vitals, an activity monitor and process inspector for the Mac, searches every open file at once: type part of the name in Open Files and the apps holding it are listed.

How to find the app using a file with Terminal

  1. 01 Open Terminal, in Applications → Utilities.
  2. 02 Type lsof and a space, drag the file from Finder into the window, and press Return.
  3. 03 Read the first two columns: the process name and its PID. No output means nothing of yours has the file open.
  4. 04 Run it again with sudo in front to include the processes macOS and other users run.
  5. 05 Quit the app it names. For a process with no window, run kill <PID> with its PID.

The process can be a helper and not an app: QuickLookUIService belongs to Quick Look, and a name ending in Helper belongs to the app named before it.

macOS keeps a file busy while a program has it open, which is why the Trash refuses it, a rename fails or a disk will not eject. The process is easy to find once you know where to look. The table below pairs each message with its usual cause.

File in use: what you see, and the likely cause

What you seeLikely causeWhat to do
“The operation can’t be completed because the item is in use” An app has the file open, or Quick Look is previewing it Close the document or the preview, then try again
The Trash will not empty A file in the Trash is still open in an app Quit the app, or restart and empty the Trash
A file cannot be renamed or moved An app is writing to it Wait for the save or the export to finish
A disk will not eject A file or a folder on it is open See Mac won’t eject a disk
A file is locked Locked is ticked in Get Info, which is not the same as in use Untick Locked in Get Info

Finding it in Activity Monitor

Activity Monitor has no search across files. If you suspect an app, double-click it, open the Open Files and Ports tab and look for the file’s path in the list. The list is long for a busy app, and it covers one process at a time.

Reading lsof’s output

Each line is one open file. COMMAND is the process, PID its number, FD how the file is open, and NAME the path. In FD, a number followed by r means reading, w writing and u both; cwd is the folder the process is working in, and txt the program and the libraries it loaded.

Everything one process has open

To go the other way, from a process to its files, run lsof -p <PID> with its PID. lsof -c Preview lists the files of every process whose name starts with the letters you give.

When the file is in the Trash

Emptying the Trash fails while any file in it is open. Quit the app that had it open. If you cannot tell which, lsof +D ~/.Trash lists what is open there; Terminal may need Full Disk Access to look. Restarting the Mac closes everything, and the Trash empties afterwards.

When nothing has it open

If lsof prints nothing even with sudo, the file is not in use. A file you still cannot change is locked, owned by another user, or on a disk mounted read-only. Get Info shows the Locked box and the permissions.

What Vitals adds

Vitals searches every open file on the Mac by name.

  • Open Files, in the Developer tab: press ⌘F, type part of a file’s name or path, and every app holding a match is listed
  • By app, not by process: a helper is counted under the app it belongs to
  • Each app’s files on a disk, with how many are open for writing
  • Quit the app from the same row, after a confirmation

Good to know

  • Without Full System Metrics, the files of macOS’s own processes are left out, and Vitals says how many.
  • Vitals shows who has a file open. It does not unlock a file or change its permissions.
  • Open Files is in the window, not in the menu bar dropdown.
Get Vitals for $29 $29 for life during the launch, $49 after, paid once, with a 14-day refund. Or $15 for a year of updates.

Questions people ask

How do I see which process is using a file on a Mac?

Run lsof followed by the file’s path in Terminal. The first column is the process and the second its PID.

Why does my Mac say the item is in use?

An app or a preview still has the file open. Close the document, quit the app or close the Quick Look preview, then try again.

How do I delete a file that is in use on a Mac?

Find the app with lsof and quit it, then move the file to the Trash. If nothing lists it, restart the Mac and delete it then.

Does Activity Monitor show open files?

Yes, one process at a time: double-click a process and open Open Files and Ports. It cannot search for a file across all processes.

Does lsof need sudo?

Without sudo it lists only your own processes. With sudo it includes macOS’s own, such as Spotlight’s.

Is there an app that shows which app has a file open?

Vitals does. Type part of the file’s name in its Open Files section and the apps holding it are listed, on any disk.

In the glossary

More guides