How to check all opened files in a directory – lsof command

LSOF is a smart linux command-line utility for analysing the information about the files which are opened by various processes. LSOF stands for List of Open Files. This command has a vital role in server Administration. In Linux/Unix, everything is considered as a file such as pipes, sockets, devices etc are treated as files. Thus, by using ‘lsof’ command we will get the information of any opened files. For example, if you are trying to unmound a partition and you are getting the error “files are being used”. Here, you can easly identify the files which are in use by uding the LSOF command.

Here I’m explaining the usage of LSOF command to list all opened file in a directory.

There is a switch “D” associated with LSOF command to do this. See the usage listed below:

# lsof +D path_of_the_directory


[[email protected] ~]# lsof +D /var/log/
rsyslogd   464   root    1w   REG 182,33   139619 131530 /var/log/messages
rsyslogd   464   root    2w   REG 182,33   911817 131531 /var/log/secure
rsyslogd   464   root    4w   REG 182,33   372734 131529 /var/log/maillog
rsyslogd   464   root    5w   REG 182,33     9608 131512 /var/log/cron
httpd      629   root    2w   REG 182,33      743 131526 /var/log/httpd/error_log
httpd      629   root    6w   REG 182,33      170 131524 /var/log/httpd/access_log
httpd      636 apache    2w   REG 182,33      743 131526 /var/log/httpd/error_log
httpd      636 apache    6w   REG 182,33      170 131524 /var/log/httpd/access_log
httpd     1382 apache    2w   REG 182,33      743 131526 /var/log/httpd/error_log
httpd     1382 apache    6w   REG 182,33      170 131524 /var/log/httpd/access_log
lfd      29910   root    5r   REG 182,33   139619 131530 /var/log/messages
lfd      29910   root    6r   REG 182,33   911817 131531 /var/log/secure
lfd      29910   root    7r   REG 182,33      743 131526 /var/log/httpd/error_log

For more information about LSOF, please read this >> 10 lsof command usages with example <<

That’s it!

Also read:

1, 15+ tar command usages with examples – Unix/Linux
2, 10+ commonly using find command switches with example Unix/Linux
3, 20+ Rsync command’s switches and common usages with examples – Unix/Linux

, ,

Post navigation

Arunlal Ashok

Linux Systems Architect at Endurance International Group. I know her (Linux) since many years. Linux lover. Like to play on Linux console. I started this blog to share and discuss Linux thoughts.

Always happy for an open discussion! Write to arun (@) crybit (dot) com. Check about me for more details. About this blog and our strong members, check The team

One thought on “How to check all opened files in a directory – lsof command

Leave a Reply

Your email address will not be published. Required fields are marked *