usage of lsof

what is lsof?

lsof can list all information of opened files, the opened files can be

1.ordiary file

2.dictionary

3.network file and system file

4.device file

5.(function)share library

6.pipeline

7.symbol link

8.network socket

how to use lsof

1. check who is using this file

lsof /filepath/file

2. check opened files incluce files in subdictionary in a specific dictionary.

lsof +D /filepath/filepath2/

3. check opened files in a specific dictionary.

lsof | grep ‘/filepath/filepath2/’

4. list information of opened files by a specific user.

lsof -u username

5. list information of opened files by a specific program.

lsof -c oracle

you can also type “lsof | grep orale”, but obviously “lsof -c oracle” is more simple.

6. list information of opened files by multiple program.

lsof -c mysql -c apache

7. list information of opened files by a specific user and a specific program.

lsof -u test -c mysql

8. list information of opened files by all users exclude a certain user.

lsof -u ^root

9. list information of opened files by a process number.

lsof -p 1

10. list information of opened files by multiple process number.

lsof -p 123,456,789

11. list information of opened files by all process numbers exclude a specific process number.

lsof -p ^1

12 . list all network connection

lsof -i

13. list all tcp information of network connection.

lsof -i tcp

14. list all udp information of network connection.

lsof -i udp

15. list who is using a specific port

lsof -i :3306

16. list who is using a specific udp port.

lsof -i udp:55

specific tcp port

lsof -i tcp:80

Leave a Reply