How do I see the list of files open (lsof
) in a specific directory and by other users?
I can do lsof +D /path
, but that only shows current user's files.
Any way to see if other users have opened files in a directory?
bashlsof
How do I see the list of files open (lsof
) in a specific directory and by other users?
I can do lsof +D /path
, but that only shows current user's files.
Any way to see if other users have opened files in a directory?
Best Answer
Since I had the similar question recently I wanted to share my findings here too. Also it is assumed that the user is
root
and as mentioned in the other answers.List open files within a specific directory
will show files opened from all users.
Specifying the user
will show all files from the user OR within the specific directory (... AND independet from the user).
This is because of and as stated in
man lsof
:To list open files from the user AND within a specific directory only
It is then possible to list open files which are NOT the user AND within a specific directory.
This approach is also working good for network connections. I.e if interested in all TCP OR UDP connections which are opened by NOT under root running processes
To address the issue with the non root user,
sudo
andsudoers
it will be necessary to Identify thesudo
calling user.List all open files within a specific directory AND opened from the user
otherwise it would show opened files OR within the directory AND indepent from the user.
List all open files within a specific directory NOT opened by the mentioned user