Difference between revisions of "Lsof"
(Created page with "lsof is a command meaning "list open files", which is used in many Unix-like systems to report a list of all open files and the processes that opened them. This open source ut...") |
|||
Line 19: | Line 19: | ||
One can also list Unix Sockets by using lsof -U. | One can also list Unix Sockets by using lsof -U. | ||
+ | |||
+ | This will show PROGRAM process and where it is fully located. | ||
+ | ps aux |grep -i "PROGRAM" |awk '{print $2}' | xargs -I '{}' lsof -p {} |
Latest revision as of 13:25, 29 January 2020
lsof is a command meaning "list open files", which is used in many Unix-like systems to report a list of all open files and the processes that opened them. This open source utility was developed and supported by Victor A. Abell, the retired Associate Director of the Purdue University Computing Center. It works in and supports several Unix flavors.
Examples
Open files in the system include disk files, named pipes, network sockets and devices opened by all processes. One use for this command is when a disk cannot be unmounted because (unspecified) files are in use. The listing of open files can be consulted (suitably filtered if necessary) to identify the process that is using the files.
lsof /var
To view the port associated with a daemon:
lsof -i -n -P | grep sendmail
From the above one can see that "sendmail" is listening on its standard port of "25".
-i
Lists IP sockets.
-n
Do not resolve hostnames (no DNS).
-P
Do not resolve port names (list port number instead of its name).
One can also list Unix Sockets by using lsof -U.
This will show PROGRAM process and where it is fully located.
ps aux |grep -i "PROGRAM" |awk '{print $2}' | xargs -I '{}' lsof -p {}