Show which process is using a file

Show which process is using a file

Have you had the case that you could not clear your trash because one of the files was still in use? Most time it’s a .dmg file which is still mounted but a few days ago it was a .pdf file.

To find out which file is in use by which process you can use the lsof command. If you run that command there will be a lot of files and processes. So to filter it just use grep.

lsof | grep name_of_my_file.pdf