[20201103]lsof顯示link=0的檔案.txt

lfree發表於2020-11-03

[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部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2731783/,如需轉載,請註明出處,否則將追究法律責任。

相關文章