摘要:Linux好用網管指令之一:lsof(List Open Files)
簡介
lsof (List Open Files):可列出被程序開啟的檔案,可以說是非常實用的監控、查找、診斷工具之一
應用
01. lsof

02. lsof -g :列出『gid』

03. lsof +L :列出打開文件的連接數。查找打開,但不能連接的文件,一個程序打開一個文件,然後將其設為
『unlinked』狀態,則此文件資源仍能被程序使用,但其訪問路徑已被刪除了,因此,使用『ls』不能將其列出,
只有當程序結束時,才能釋放佔用的資源。
註:『lsof +L1』:指定連接數的上限

04. lsof /bin/bash:查看誰在使用某個文件,ex. bash

05. lsof /dev/tty1:查看某個目錄的文件訊息

06. lsof +d /var/log:列出目錄下被程序開啟的文件

07. lsof +D /var/log:列出目錄下被程序開啟的文件,含底下的目錄

08. lsof -u ghoseliang:列出某個user打開的文件訊息

09. lsof -u ^ghoseliang:列出除了某user外所打開的文件訊息

10. lsof -c freshclam:列出某個程序打開的文件訊息

11. lsof -p 13:列出某PID所打開的文件訊息

12. lsof -p 13,14,15:列出多個PID所對應的文件訊息

13. lsof -i [46]:列出網路連線訊息,『4』為IPv4,『6』為IPv6

14. lsof -i tcp:列出『TCP』的網路連線訊息

15. lsof -i udp:列出『UDP』的網路連線訊息

16. lsof -i :22:列出『Port:22』的連線訊息

17. lsof -i tcp:25:列出『TCP Port:25』的連線訊息

18. lsof -c sshd -a -d txt:列出 COMMAND為『sshd』,而文件描述類型為『txt』的文件訊息

19. lsof -r :不斷重複執行,每15秒更新一次

20. lsof +r :不斷重複執行,直到沒有檔案被列出

參考來源
01. http://linux.vbird.org/linux_basic/0440processcontrol.php#lsof
02. http://idobest.pixnet.net/blog/post/22040642-%5B%E8%BD%89%E8%B2%BC%5D-%E5%A5%BD%E7%94%A8%E7%9A%84%E7%B6%B2%E7%AE%A1%E6%8C%87%E4%BB%A4-lsof
03. http://www.cnblogs.com/peida/archive/2013/02/26/2932972.html
04. http://blog.longwin.com.tw/2012/05/lsof-port-network-2012/
05. http://shinchuan1.blogspot.tw/2014/02/lsof-list-open-files.html
06. http://tech.ccidnet.com/art/305/20070829/1194715_1.html
07. https://app.shopback.com/RBANl9P3Ysb
備註
已將簡易用法編進:【筆記整理】CentOS常用指令整理( I ~ L )