12

I know I can use lsof to list open files, and I know I can use find to find files by inode within a given directory.

But how can I effectively combine these two programs to list all open files which are open within a given directory? Or is there a better way to answer this question?

spraff
  • 2,458

2 Answers2

37

lsof has switches for doing this:

  • lsof +d '/path/to/directory' (will list open files in the folder)
  • lsof +D '/path/to/directory' (will list open files recursively)
AntonioK
  • 472
5hack
  • 471
5

Easy. Just pipe the output of the lsof command into grep for further processing like this:

sudo lsof | grep /path/of/directory/you/care/about
Giacomo1968
  • 58,727