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/ COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME 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 <<