Use lsof to recover rm-rf deleted files

Source: Internet
Author: User

In the Linux system using rm-rf Delete files, in fact, the file is only removed from the disk, the file content or in the background of the system to wait for recycling, you can use the system process number to test the file, the content will not be changed.


1. Delete a file

[email protected] logs]# ll Access.log
-rw-r--r--1 root root 11723908 June 16:02 Access.log
[Email protected] logs]# RM-RF Access.log


2. View files in the background process
[[email protected] 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      9 w   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)
[[email protected] logs]#

3. Copy the file from the process to disk

[Email protected] logs]# cp/proc/12953/fd/9 . #12953是进程号, 9 is a file descriptor
[Email protected] logs]# Du-sh 9
12M 9
[email protected] logs]# Cat 9 #文件内容看到了


This article is from the "Days Together" blog, please be sure to keep this source http://tongcheng.blog.51cto.com/6214144/1789173

Use lsof to recover rm-rf deleted files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.