lsof将恢复的文件显示为已删除

如果我创build一个名为/home/martin/testfile.txt的文件,请使用较less的实用程序打开此文件,删除/home/martin/testfile.txt文件,并从/ proc / 31148下的文件描述符目录中恢复它,其中31148是实用程序的PID 较less ,则lsof | grep testfile.txt lsof | grep testfile.txt仍将lsof | grep testfile.txt显示为已删除:

 martin@potato:~$ echo test > testfile.txt martin@potato:~$ ls -li ~/testfile.txt 247 -rw-r--r-- 1 martin martin 5 24. veebr 05:02 /home/martin/testfile.txt martin@potato:~$ xterm -hold -e "less /home/martin/testfile.txt" & [1] 31145 martin@potato:~$ lsof | grep testfile.txt less 31148 martin 4r REG 8,9 5 247 /home/martin/testfile.txt martin@potato:~$ rm -v /home/martin/testfile.txt removed `/home/martin/testfile.txt' martin@potato:~$ lsof | grep testfile.txt less 31148 martin 4r REG 8,9 5 247 /home/martin/testfile.txt (deleted) martin@potato:~$ cp -v /proc/31148/fd/4 /home/martin/testfile.txt `/proc/31148/fd/4' -> `/home/martin/testfile.txt' martin@potato:~$ ls -li ~/testfile.txt 263 -rw-r--r-- 1 martin martin 5 24. veebr 05:04 /home/martin/testfile.txt martin@potato:~$ cat ~/testfile.txt test martin@potato:~$ lsof | grep testfile.txt less 31148 martin 4r REG 8,9 5 247 /home/martin/testfile.txt (deleted) martin@potato:~$ 

这是因为testfile.txt有一个新的inode号码? 还是有其他一些原因,为什么lsof显示恢复的文件被删除?

是的,他们是两个不同的文件。 通过从/ proc复制( cp )文件,您只需创build一个新的inode文件。 你可以用stat命令testing它 –

[root @ server2 tmp] stat testfile.txt文件:test.txt大小:9块:8 IO块:4096常规文件设备:803h / 2051d Inode: 3684616链接:1访问:(0644 / -rw-r– (0 / root)访问:2013-02-23 19:01:14.000679872 -0800修改:2013-02-23 19:01:14.000679872 -0800更改:2013- 02-23 19:01:14.000679872 -0800

[root @ server2 tmp] stat testfile.txt文件:test.txt大小:9个块:8个IO块:4096个常规文件设备:803h / 2051d Inode: 3684617链接:1访问:(0644 / -rw-r– (0 / root)访问:2013-02-23 19:02:46.422854012 -0800修改:2013-02-23 19:02:44.507799688 -0800更改:2013- 02-23 19:02:44.507799688 -0800