How to use the Linux lsof command

1.What is the lsof command?
+This is the Linux command to show files opened by a user, a process
+In some old Linux version, we need to be root account to use the command

2.Example of Using Command
2.1 List all of opened files
$>lsof
$>lsof | head

2.2 List all opened files opened by a process
$>lsof -p 112233
Example 112233 as the process number

2.3 List all opened files opened by a user
$>lsof -u alice
Example alice is a user name

2.4 List all opened files for a directory
$>lsof +d ‘/home/sample’
Note: it just lists all files in the dir sample only, not recursive to sub folders

$>lsof +D ‘/home/sample’
Note: it just lists all files in the dir sample only, and recursive to ALL sub folders

2.5 List all opened files for a directory by a process

$>lsof -p TOMCAT_PID | grep /home/sample

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.