Skip to main content

lsof

# 搜索目录
lsof +D /var/lib/k0s/containerd/io.containerd.snapshotter.v1.overlayfs/
# 搜索 Linux 文件
lsof -f -- /run/k0s/konnectivity-server/konnectivity-server.sock

lsof -c ssh -c init

# 判断 roofs 对应磁盘没有太多读写
lsof -a -d "^cwd,^rtd" +D "/"
lsof -a -d "^cwd,^rtd,^mem,^txt" +D "/"
flagfor
-d FD
+D DIR遍历 DIR
+d DIR不遍历
-u USER
-g GROUP
-aAND
-c PROCESS_NAME
-p PID
-t输出 PID
+|-r [t[m<fmt>]]repeat N times
-inetwork
-NNFS
-P不 port -> name
-n不 ip -> hostname
+|-f [cfgGn]path name
-D Ddevice cache file
-x [fl]l - symlink, f - mount
  • ^EXCLUDE
    • -u ^root - exclude root user
    • -p ^init - exclude init process
    • -p 123,^456
  • -i [46][protocol][@hostname|hostaddr][:service|port]
    • -i TCP:22
    • -i TCP:1-1024
    • -i 4 - IPv4
    • -i 6 - IPv6
  • +D DIR -x l - follow symlink
  • +D DIR -x f - follow mount point

FD

FDfor
cwdcurrent working directory
Lnnlibrary references (AIX)
errFD information error (see NAME column)
jldjail directory (FreeBSD)
ltxshared library text (code and data)
Mxxhex memory-mapped type number xx
m86DOS Merge mapped file
memmemory-mapped file
mmapmemory-mapped device
pdparent directory
rtdroot directory
trkernel trace file (OpenBSD)
txtprogram text (code and data)
v86VP/ix mapped file
  • r -> read
  • w -> write
  • u -> read+write
  • -> unknow & no lock
  • - -> unknown & lock

Lock

Lfor
NSolaris NFS lock of unknown type;
rread lock on part of the file;
Rread lock on the entire file;
wwrite lock on part of the file;
Wwrite lock on the entire file;
uread and write lock of any length;
Ulock of unknown type;
xSCO OpenServer Xenix lock on part of the file;
XSCO OpenServer Xenix lock on the entire file;
spaceno lock.
  • TYPE
    • REG - Regular File
    • DIR
    • FIFO
    • CHR