使用lsof恢复rm -rf删除后的文件
2016-06-14 16:48
357 查看
在Linux系统中使用rm -rf删除文件后,其实文件只是从磁盘中移除,文件内容还是在系统后台等待回收,此时可以使用系统进程号将文件考贝出来,内容不会有更改。
1.删除一个文件
[root@iZ62f427er8Z logs]# ll access.log
-rw-r--r-- 1 root root 11723908 Jun 14 16:02 access.log
[root@iZ62f427er8Z logs]# rm -rf access.log
2.查看文件在后台的进程
[root@iZ62f427er8Z logs]# lsof | grep delete | grep access
nginx 1212 root 9u REG 202,1 11723908 274125 /usr/local/nginx-1.4.7/logs/access.log (deleted)
nginx 12953 www 9w REG 202,1 11723908 274125 /usr/local/nginx-1.4.7/logs/access.log (deleted)
nginx 12954 www 9w REG 202,1 11723908 274125 /usr/local/nginx-1.4.7/logs/access.log (deleted)
[root@iZ62f427er8Z logs]#
3.将文件从进程中复制到磁盘上
[root@iZ62f427er8Z logs]# cp /proc/12953/fd/9 . #12953是进程号,9是文件描述符
[root@iZ62f427er8Z logs]# du -sh 9
12M 9
[root@iZ62f427er8Z logs]# cat 9 #文件内容看到了
本文出自 “一起走过的日子” 博客,请务必保留此出处http://tongcheng.blog.51cto.com/6214144/1789173
1.删除一个文件
[root@iZ62f427er8Z logs]# ll access.log
-rw-r--r-- 1 root root 11723908 Jun 14 16:02 access.log
[root@iZ62f427er8Z logs]# rm -rf access.log
2.查看文件在后台的进程
[root@iZ62f427er8Z logs]# lsof | grep delete | grep access
nginx 1212 root 9u REG 202,1 11723908 274125 /usr/local/nginx-1.4.7/logs/access.log (deleted)
nginx 12953 www 9w REG 202,1 11723908 274125 /usr/local/nginx-1.4.7/logs/access.log (deleted)
nginx 12954 www 9w REG 202,1 11723908 274125 /usr/local/nginx-1.4.7/logs/access.log (deleted)
[root@iZ62f427er8Z logs]#
3.将文件从进程中复制到磁盘上
[root@iZ62f427er8Z logs]# cp /proc/12953/fd/9 . #12953是进程号,9是文件描述符
[root@iZ62f427er8Z logs]# du -sh 9
12M 9
[root@iZ62f427er8Z logs]# cat 9 #文件内容看到了
本文出自 “一起走过的日子” 博客,请务必保留此出处http://tongcheng.blog.51cto.com/6214144/1789173
相关文章推荐
- 如何使用Dockerfile构建镜像
- suse zypper源
- STM32F769I-DISCO探索板简介
- Android图片下载缓存库picasso解析
- 百度推送始终跳转不到指定页面
- io、nio、 aio
- 重置Oracle SEQUENCE值 的存储过程
- UVa 10055 - Hashmat the Brave Warrior
- activiti教程(一)eclipse或者myEclipse安装Activiti designer插件
- 如何打jar包和运行jar包
- audio元素和video元素在ios和andriod中无法自动播放
- Windows下Python安装lxml
- Android Loader异步装载
- 文字在div中水平和垂直居中的的css样式
- PNP三极管作为开关管如何使用(集电极接 负载)
- 简单区分UIResponder与UIControl
- [疯狂Java]正则表达式:Pattern、Matcher、String对正则表达式的支持
- Ubuntu14.04安装JDK与配置环境变量
- Spring 学习笔记
- 嵌入式C语言位运算之清位置位