Lsof command
-> Lsof meaning List Open Files, is used to find out which files
are open by which process.
-> With the help of this command we can easily identify the files
which are in use.
-> lsof
-> it shows COMMAN, PID, USER, FD, TYPE etc
-> FD stands for file descriptor and may seen some of the values
are.
a) cwd means current working directory
b) rtd root directory
c) txt program text (code and data)
d) mem memory-mapped file
e) Lnn library references (AIX)
f) err FD information error (see Name column)
g) jld jail directory (Free BSD)
h) ltx shared library text (code and data)
i) mxx hex-memory mapped type number xx
j) m86 Dos merge mapped file
k) mmap memory mapped device
l) pd parent directory
m) tr kernel trace file
n) v86 Vp/ix mapped file
-> Type of files and it’s identification
a) DIR – Directory
b) REG – Regular file
c) CHR – Character special file
d) FIFO – first in first out
2) List user specific opened files
-> lsof -u shoaib
3) Finding Processes running on Specific Port
-> lsof -i TCP:22
4) List only ipv4 and ipv6 open file
-> lsof -i 4
-> lsof -i 6
5) List open files of TCP Port ranges 1-1024
-> lsof -i TCP:1-1024
6) Exclude user with ^
-> lsof -i -u^root
7) search by pid
-> lsof -p 1
8) kill all activity of a particular user
-> kill -9 `lsof -t -u techmint`
Getting help
-> lsof -? / -h
-> lsof -v
COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF
NODE NAME
-> List all open files by a particular process:
-> lsof -c Mysql
-> List parent process Ids: There is a large no of process running
in a system