ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 使用lsof恢复误删除的文件

使用lsof恢复误删除的文件

Linux操作系统 作者:壹頁書 时间:2014-05-04 12:36:13 0 删除 编辑

红枣店铺:https://item.taobao.com/item.htm?id=525210310056
qq:45446263

1.创建一个文件
[root@linux-5f160 script]# vi test.sh

sleep 3600

2.让这个文件在后台一直执行
[root@linux-5f160 script]#nohup sh ./test.sh > test.log &
3.删除文件 test.sh

[root@localhost script]# rm -rf test.sh

4.通过lsof查看进程以及文件状态
[root@linux-5f160 script]# lsof | grep test
sh        32332      root    1w      REG              253,7           0    6029319 /mysqldata/script/test.log
sh        32332      root    2w      REG              253,7           0    6029319 /mysqldata/script/test.log
sh        32332      root  255r      REG              253,7          11    6029323 /mysqldata/script/test.sh (deleted)
sleep     32333      root    1w      REG              253,7           0    6029319 /mysqldata/script/test.log
sleep     32333      root    2w      REG              253,7           0    6029319 /mysqldata/script/test.log

5.在/proc/进程ID/fd下面,会暂时保留着这个文件
[root@linux-5f160 script]#cd /proc/32332/fd

[root@linux-5f160 fd]# ll
总用量 0
l-wx------ 1 root root 64 4月  29 14:06 0 -> /dev/null
l-wx------ 1 root root 64 4月  29 14:06 1 -> /mysqldata/script/test.log
l-wx------ 1 root root 64 4月  29 14:06 2 -> /mysqldata/script/test.log
lr-x------ 1 root root 64 4月  29 14:06 255 -> /mysqldata/script/test.sh (deleted)
[root@linux-5f160 fd]# more 255
sleep 3600
6.恢复文件
[root@linux-5f160 fd]# cp 255 /mysqldata/script/test.sh

[root@linux-5f160 fd]#cd /mysqldata/script
[root@linux-5f160 script]# pwd
/mysqldata/script
[root@linux-5f160 script]# cat test.sh
sleep 3600
[root@linux-5f160 script]#

红枣店铺:https://item.taobao.com/item.htm?id=525210310056
qq:45446263

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29254281/viewspace-1153391/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2013-10-19

  • 博文量
    620
  • 访问量
    6339934