7

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,106
  • 5
  • 37
  • 58

2 Answers2

19

lsof has switches for doing this.

  • lsof +d 'directory' (will list open files in the folder)
  • lsof +D 'directory' (will list open files recursively)
robinCTS
  • 4,327
  • 4
  • 20
  • 29
5hack
  • 191
  • 1
  • 2
4

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
  • 53,069
  • 19
  • 162
  • 212