Which app is using a folder?

Discussion in 'macOS' started by Dinky2, Jan 30, 2016.

  1. Dinky2 macrumors newbie

    Joined:
    Nov 21, 2010
    #1
    I came across a folder on my iMac that is being used, but I cannot work out which app is using it. Is there a way in OSX where I can see that ?
     
  2. JohnDS macrumors 65816

    Joined:
    Oct 25, 2015
    #2
    Folders aren't usually "used", just the contents. What are you trying to do? Delete it? If it won't delete, reboot while holding down the shift key, then delete it before opening any apps. If it still won't delete, it is likely shared. Right click on it and choose GetInfo to see if the folder is shared. If it is shared you have to unshare it to delete it.
     
  3. Brian33 macrumors 6502a

    Joined:
    Apr 30, 2008
    Location:
    USA (Virginia)
    #3
    Are you familiar with the command line in Terminal.app?

    The "lsof" command can show all open files -- and the Unix origins of OS X mean that the filesystem includes pretty much everything: files, folders, TCP sockets, hardware devices, the black hole of /dev/null, etc.

    To show every open file for your user, along with the responsible command name, enter:

    lsof +fg /

    lsof has a ton of confusing options which I've never taken the time to figure out, so I just use brute force and filter the output through egrep. If you know any part of the folder's name, try this in Terminal.app (pretend the word image is part of the folder's name):

    lsof +fg / | egrep -i "image"

    lsof is the command (type man lsof for more info)
    +fg gives some handy file flags (my notes say that "EVO (event only) on an open file should _not_ prevent eject)"
    the slash (/) is the directory to start looking in...
    the output (there will be a lot) is piped to....
    egrep, which case insensitively (-i) looks for just the lines that have the word image.

    So, replace the word image with part of your folder's name. You'll need the quotes if your folder name has spaces or some other special characters in it. If not, you can leave out the quotes. You won't get any output if it isn't found.

    The problem is, that will only show files open by your user account, and there's a good chance the file is open by some system-level process. To show files open by any user on the system, you have to use "sudo", which will execute the command with "system administrator" privileges (and needs an admin password). Although I assert that the lsof command is safe to use with sudo like this, if you don't really know what you're doing, you should strictly follow a policy of not entering any sudo commands on some posters say-so that it's ok...
     

Share This Page