lsof命令

最近發現LOSF 命令在系統管理方面特別有用,把我搜集的資料總結如下
 

安裝

發個安裝lsof的步驟

Steps to Install lsof on AIX
1) Obtain the fileset. It’s in the AIX 5L V5.3 Expansion Pack which shipped with your AIX system. Supposedly, you can call IBM and they will ship you the CDs if you have support with them. Otherwise, try downloading it from their website. I had to create an IBM login to get the file I needed.

I personally installed this using the CDs, so those are the instructions I’m giving.

2) Insert CD, “AIX Expansion Pack”

3) Run SMIT

AIX# smit

4) Navigate to Install Software

Software Installation and Maintenance > Install and Update Software > Install Software

5) Specify your device as your CD (i.e. /dev/cd0)

6) Scroll to SOFTWARE to install. Press F4 or esc+4.

7) Find lsof.base and lsof.man.en_US. Select these using F7 or esc+7

8) Hit enter a few times and it should install in /usr/sbin/lsof.

9) Test the command as root:

AIX# lsof


1、當在lsof後邊沒有跟任何參數時,該命令將會列出當前系統中被所有進程打開的所有文件
#lsof|nl     #nl命令打印出行號

2、下邊這幾個命令指出打開某文件的進程

#lsof `which httpd`    #那個進程在使用apache的可執行文件
#lsof /etc/passwd      #那個進程在佔用/etc/passwd
#lsof /dev/hda6        #那個進程在佔用hda6
#lsof /dev/cdrom       #那個進程在佔用光驅

3、下邊將會打印出佔用httpd可執行文件的進程的進程號(僅僅是進程號,在編寫shell腳本是有用)
#lsof -t `which httpd`

4、顯示出那些文件被以k打頭的進程名的進程打開,以bash打頭,和以init打頭:
#lsof -c k
#lsof -c bash
#lsof -c init

5、顯示出那些文件被以courier打頭的進程打開,但是並不屬於用戶‘zahn’
#lsof -c courier -u ^zahn

6、顯示被zahn和apache打開的文件
#lsof -u apache,zahn

7、顯示那些文件被pid爲30297的進程打開:
#lsof +p 30297

8、顯示所有在/tmp文件夾中打開的instance和文件的進程。但是symbol文件並不在列
#lsof -D /tmp

9、顯示所有打開的端口
#lsof -i
10、顯示所有打開80端口的進程
#lsof -i :80

11、顯示所有打開的端口和UNIX domain文件:
#lsof -i -U

12、顯示那些進程打開了到www.akadia.com的UDP的123(ntp)端口的鏈接:
#[email protected]:123

13、列出Internet, x.25 (HP-UX), and UNIX domain 文件:
#lsof -i -U

14、列出指定進程打開的IPv4文件:
#lsof -i 4 -a -p 1234  (-a 參數被視爲 AND )

15、列出指定進程打開的IPv4文件:
#lsof -i 6

16、列出使用 /dev/log的文件:
#lsof /dev/log

17、獲取每個進程的PID,命令名。進程每個文件的文件描述符,文件設備號,文件inode :
#lsof –FpcfDi

18、獲取工作目錄的第3個字符是'o' or 'O'的進程:
#lsof -c /^..o.$/i -a -d cwd  (-a 參數被視爲 AND )

19、獲取和指定IP有關的socket 文件:
#[email protected]

20、Unlinked的打開文件:
#lsof +L1

21、查找監聽的socket
#lsof –i
#[email protected]
#[email protected]:ftp-data

22、查找指定進程號或進程名使用的文件
lsof -p <PID>

23、遠程登陸偵測
#lsof /dev/pts/0

24、NFS文件
$ lsof –N

25、指定用戶打開的文件

lsof -u ^root

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章