Linux作業系統上Lsof命令詳解

來源:互聯網
上載者:User

Linux作業系統上Lsof命令詳解 一般root使用者才能執行lsof命令,普通使用者可以看見/usr/sbin/lsof命令,
但是普通使用者執行會顯示“permission denied”
 我總結一下lsof指令的用法:lsof abc.txt 顯示開啟檔案abc.txt的進程lsof -i :22 知道22連接埠現在運行什麼程式lsof -c abc 顯示abc進程現在開啟的檔案lsof -g gid 顯示歸屬gid的進程情況
 lsof +d /usr/local/ 顯示目錄下被進程開啟的檔案lsof +D /usr/local/ 同上,但是會搜尋目錄下的目錄,時間較長lsof -d 4 顯示使用fd為4的進程  www.2cto.com  lsof -i 用以顯示合格進程情況文法: lsof -i[46] [protocol][@hostname|hostaddr][:service|port]46 --> IPv4 or IPv6protocol --> TCP or UDPhostname --> Internet host namehostaddr --> IPv4位置service --> /etc/service中的 service name (可以不只一個)port --> 連接埠號碼 (可以不只一個)
 例子: TCP:25 - TCP and port 25@1.2.3.4 - Internet IPv4 host address 1.2.3.4tcp@ohaha.ks.edu.tw:ftp - TCP protocol hosthaha.ks.edu.tw service name:ftplsof -n 不將IP轉換為hostname,預設是不加上-n參數
 例子: lsof -i tcp@ohaha.ks.edu.tw:ftp -nlsof -p 12 看進程號為12的進程開啟了哪些檔案lsof +|-r [t] 控制lsof不斷重複執行,預設是15s重新整理-r,lsof會永遠不斷的執行,直到收到中斷訊號+r,lsof會一直執行,直到沒有檔案被顯示
 例子:不斷查看目前ftp串連的情況:lsof -i tcp@ohaha.ks.edu.tw:ftp -rlsof -s 列出開啟檔案的大小,如果沒有大小,則留下空白lsof -u username 以UID,列出開啟的檔案  www.2cto.com    作者 san_yun

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.