lsof应用实例分享以及Oracle数据文件删除恢复测试
㈠ lsof 应用实例
① 查找指定端口被哪个程序占用:
[plain]
[root@temp ~]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 10278 root 3u IPv6 37812 0t0 TCP *:http (LISTEN)
httpd 10280 apache 3u IPv6 37812 0t0 TCP *:http (LISTEN)
httpd 10281 apache 3u IPv6 37812 0t0 TCP *:http (LISTEN)
httpd 10282 apache 3u IPv6 37812 0t0 TCP *:http (LISTEN)
httpd 10283 apache 3u IPv6 37812 0t0 TCP *:http (LISTEN)
httpd 10284 apache 3u IPv6 37812 0t0 TCP *:http (LISTEN)
httpd 10285 apache 3u IPv6 37812 0t0 TCP *:http (LISTEN)
httpd 10286 apache 3u IPv6 37812 0t0 TCP *:http (LISTEN)
httpd 10287 apache 3u IPv6 37812 0t0 TCP *:http (LISTEN)
② 查找指定文件正在被谁使用:
[plain]
[root@temp ~]# lsof /u01/app/oracle/oradata/ORCL/datafile/o1_mf_ggs_data_8rq64t53_.dbf
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
oracle 11239 oracle 23uW REG 8,2 83894272 1169914 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_ggs_data_8rq64t53_.dbf
oracle 11241 oracle 29u REG 8,2 83894272 1169914 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_ggs_data_8rq64t53_.dbf
oracle 11245 oracle 21u REG 8,2 83894272 1169914 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_ggs_data_8rq64t53_.dbf
oracle 11251 oracle 22u REG 8,2 83894272 1169914 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_ggs_data_8rq64t53_.dbf
oracle 11260 oracle 19u REG 8,2 83894272 1169914 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_ggs_data_8rq64t53_.dbf
③ 查找某个用户打开的文件
[plain]
[root@temp ~]# lsof -u oracle
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 5601 oracle cwd DIR 8,2 4096 1491645 /home/oracle
bash 5601 oracle rtd DIR 8,2 4096 2 /
bash 5601 oracle txt REG 8,2 735804 1782911 /bin/bash
bash 5601 oracle mem REG 8,2 5436 584246 /usr/lib/gconv/ISO8859-1.so
bash 5601 oracle mem REG 8,2 130860 390859 /lib/ld-2.5.so
bash 5601 oracle mem REG 8,2 1706072 391064 /lib/i686/nosegneg/libc-2.5.so
bash 5601 oracle mem REG 8,2 20668 391065 /lib/libdl-2.5.so
bash 5601 oracle mem REG 8,2 13276 391090 /lib/libtermcap.so.2.0.8
bash 5601 oracle mem REG 8,2 50848 389032 /lib/libnss_files-2.5.so
bash 5601 oracle mem REG 8,2 25462 584323 /usr/lib/gconv/gconv-modules.cache
bash 5601 oracle mem REG 8,2 56449792 491499 /usr/lib/locale/locale-archive
bash 5601 oracle 0u CHR 136,1 0t0 3 /dev/pts/1
.....................
................
④ 查找某个程序现在正打开的文件
[plain]
-c:程序名
-p:pid
[root@temp ~]# lsof -c init
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
init 1 root cwd DIR 8,2 4096 2 /
init 1 root rtd DIR 8,2 4096 2 /
init 1 root txt REG 8,2 38652 1620888 /sbin/init
init 1 root mem REG 8,2 130860 390859 /lib/ld-2.5.so
init 1 root mem REG 8,2 1706072 391064 /lib/i686/nosegneg/libc-2.5.so
init 1 root mem REG 8,2 20668 391065 /lib/libdl-2.5.so
init 1 root mem REG 8,2 245376 391081 /lib/libsepol.so.1
init 1 root mem REG 8,2 93508 391082 /lib/libselinux.so.1
init 1 root 10u FIFO 0,16 0t0 1322 /dev/initctl
⑤ 查找某个用户的所有网络连接
[plain]
[root@temp ~]# lsof -a -u oracle -i
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sqlplus 5631 oracle 7u IPv4 42558 0t0 UDP localhost.localdomain:52493
oracle 11233 oracle 15u IPv4 42442 0t0 UDP localhost.localdomain:62999
oracle 11255 oracle 14u IPv4 42529 0t0 UDP localhost.localdomain:18473
oracle 11255 oracle 15u IPv4 42530 0t0 TCP *:4048 (LISTEN)
oracle 11257 oracle 14u IPv4 42540 0t0 UDP localhost.localdomain:8690
oracle 11260 oracle 22u IPv4 42728 0t0 UDP *:12147
⑥ 查找所有打开的网络连接
[plain]
类似的:
lsof -i tcp
lsof -i udp
lsof -i tcp:80