Linux下利用Lsof恢复误删文件的方法
Linux下利用Lsof恢复误删文件的方法
点评:本文介绍如何在Linux下利用Lsof恢复误删文件
一、将 ls 的手册过滤掉主要控制符后重定向到文件ls.txt 中,并用more查看,CTRL + Z 暂停查看操作
1: [root@localhost script]# man ls |col -b > ls.txt
2: [root@localhost script]# more ls.txt
3: LS(1) User Commands LS(1)
4:
1: [1]+ Stopped more ls.txt
2: [root@localhost script]#
3: [root@localhost script]# jobs
4: [1]+ Stopped more ls.txt
5:
二、假设误删文件 ls.txt
1: [root@localhost script]# rm ls.txt
2: rm:是否删除 一般文件 “ls.txt”? y
三、利用lsof找到进程6511、并拷贝恢复,只能在这个文件被使用或调用的情况下有效
3: [root@localhost script]# lsof |grep ls.txt
4: more 6511 root 3r REG 253,0 7300 1083699 /opt/script/ls.txt (deleted)
5:
1: [root@localhost script]# ls -l /proc/6511/fd/
2: 0 1 2 3
3: [root@localhost script]# ls -l /proc/6511/fd/3
4: lr-x------ 1 root root 64 10-30 21:21 /proc/6511/fd/3 -> /opt/script/ls.txt (deleted)
5:
1: cp /proc/6511/fd/3 ls.txt.saved
评论暂时关闭