How To Use lsof Command With Exmaple Redhat Linux

lsof  list of Open files. It will list the information about file opened by process.
the file may be directory,character or block file,symbolic link,Internet socket,Linux Red hat Fedora Network Administration Command.
#lsof -i TCP >> List by Particular Protocol
COMMAND     PID   USER   FD   TYPE  DEVICE SIZE NODE NAME
portmap    1009    rpc    4u  IPv4    2718       TCP *:sunrpc (LISTEN)
rpc.statd  1040   root    7u  IPv4    2929       TCP *:798 (LISTEN)
list of open TCP with http service files.
#lsof -i TCP:80 >> Particular Port Number
COMMAND   PID   USER   FD   TYPE DEVICE SIZE NODE NAME
httpd    1174   root    3u  IPv6   3546       TCP *:http (LISTEN)
httpd   16907 apache    3u  IPv6   3546       TCP *:http (LISTEN)
httpd   16908 apache    3u  IPv6   3546       TCP *:http (LISTEN)
#lsof -c http >> List of open file by the particular service
httpd   16933 apache    8w   REG    8,1   51516  951159 /var/log/httpd/access_log
httpd   16933 apache    9r   CHR    1,9             561 /dev/urandom
httpd   16933 apache   10r  0000   0,11       0 1169912 eventpoll
#lsof -u nagios >> List of open file by using the particular user.
COMMAND  PID   USER   FD   TYPE             DEVICE    SIZE   NODE NAME
nagios  1319 nagios  cwd    DIR                8,1    4096      2 /
nagios  1319 nagios  rtd    DIR                8,1    4096      2 /
nagios  1319 nagios  txt    REG                8,1  616496 463465 usr/local/nagios/bin/nagios
nagios  1319 nagios  mem    REG                8,1   23736 737291 /lib64/libnss_dns-2.5.so
#lsof -p 16933 >> list of open file by particular process id
httpd   16933 apache    7w   REG    8,1    4819  951160 /var/log/httpd/error_log
httpd   16933 apache    8w   REG    8,1   51633  951159 /var/log/httpd/access_log
#lsof -i :25 >> Find who is using the port number
COMMAND  PID USER   FD   TYPE DEVICE SIZE NODE NAME
exim    1132 exim    6u  IPv6   3421       TCP [::1]:smtp (LISTEN)
#lsof -U >> list out the socket files
nagios    1319    nagios    3u  unix 0xffff88001cb08ec0         3917 socket
dnsmasq   1343    nobody   10u  unix 0xffff88001cb08c00         3980 socket
#lsof  -d 2 >> list the file with description
#lsof -d mem >> list with memory mapped files
#lsof -t -i TCP:80 >> list out process id for particular resource.Linux Red hat Fedora Network Administration Command.

Related post