[20201103]lsof显示link=0的文件.txt
--//有时候一些文件某些进程打开了文件句柄,而使用rm删除是无法回收使用空间的,如果出现这样的情况,查看这些依然打开的文件,
--//我以前的查询方式使用grep过滤。
# lsof | egrep "COMMAND|deleted"
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 8313 root txt REG 104,2 768952 10715145 /bin/bash (deleted)
bash 8351 root txt REG 104,2 768952 10715145 /bin/bash (deleted)
bash 8387 root txt REG 104,2 768952 10715145 /bin/bash (deleted)
rsyslogd 14220 root txt REG 104,2 267608 5603400 /sbin/rsyslogd (deleted)
--//实际上lsof支持显示文件link的计数:
+|-L [l] This option enables ('+') or disables ('-') the listing of file link counts, where they are available - e.g.,
they aren't available for sockets, or most FIFOs and pipes.
When +L is specified without a following number, all link counts will be listed. When -L is specified (the
default), no link counts will be listed.
When +L is followed by a number, only files having a link count less than that number will be listed. (No
number may follow -L.) A specification of the form ''+L1'' will select open files that have been unlinked. A
specification of the form ''+aL1 <file_system>'' will select unlinked open files on the specified file
system.
For other link count comparisons, use field output (-F) and a post-processing script or program.
--//+L numbner,仅仅显示小于number的记录。
# lsof +L 1
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME
bash 8313 root txt REG 104,2 768952 0 10715145 /bin/bash (deleted)
bash 8351 root txt REG 104,2 768952 0 10715145 /bin/bash (deleted)
bash 8387 root txt REG 104,2 768952 0 10715145 /bin/bash (deleted)
rsyslogd 14220 root txt REG 104,2 267608 0 5603400 /sbin/rsyslogd (deleted)
# lsof +L1
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME
bash 8313 root txt REG 104,2 768952 0 10715145 /bin/bash (deleted)
bash 8351 root txt REG 104,2 768952 0 10715145 /bin/bash (deleted)
bash 8387 root txt REG 104,2 768952 0 10715145 /bin/bash (deleted)
rsyslogd 14220 root txt REG 104,2 267608 0 5603400 /sbin/rsyslogd (deleted)
# lsof +aL1
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME
bash 8313 root txt REG 104,2 768952 0 10715145 /bin/bash (deleted)
bash 8351 root txt REG 104,2 768952 0 10715145 /bin/bash (deleted)
bash 8387 root txt REG 104,2 768952 0 10715145 /bin/bash (deleted)
rsyslogd 14220 root txt REG 104,2 267608 0 5603400 /sbin/rsyslogd (deleted)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2731783/ ,如需转载,请注明出处,否则将追究法律责任。