Recover the files that were used in the process of mis-deletion

Source: Internet
Author: User

Principle: In the Linux system/proc partition holds the process directory and the name, contains the FD (file descriptor) and its sub-directory (the process opens the file link), if deleted a file, there is also an inode reference:/proc/process number/fd/file descriptor. As long as we know the process PID and file descriptor of the currently open file, FD can use the Lsof tool to list the files opened by the process.
First, the LS manual filter out the main control after the redirect to the file Ls.txt, and more view, CTRL + Z pause the view operation
1: [[email protected] script]# man ls |col-b > Ls.txt
2: [[email protected] script]# more Ls.txt
3:ls (1) User Commands LS (1)
4:
1: [1]+ Stopped more Ls.txt
2: [[email protected] script]#
3: [[email protected] script]# jobs
4: [1]+ Stopped more Ls.txt
5:
Second, assume that the file is mistakenly deleted Ls.txt
1: [[email protected] script]# RM ls.txt
2:RM: Do you want to delete the generic file "Ls.txt"? Y
Third, using lsof to find process 6511, and copy recovery, only if the file is used or invoked in the case of valid
3: [[email protected] script]# lsof |grep ls.txt
4:more 6511 Root 3r REG 253,0 7300 1083699/opt/script/ls.txt (Deleted)
5:
1: [[email protected] script]# ls-l/proc/6511/fd/
2:0 1 2 3
3: [[email protected] script]# ls-l/PROC/6511/FD/3
4:lr-x------1 root root 10-30 21:21/proc/6511/fd/3-/opt/script/ls.txt (Deleted)
5:
1:CP/PROC/6511/FD/3 ls.txt.saved

Recover the files that were used in the process of mis-deletion

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.