Home >Operation and Maintenance >Linux Operation and Maintenance >How to recover accidentally deleted files in Linux

How to recover accidentally deleted files in Linux

WBOY
WBOYOriginal
2021-12-31 15:15:3016990browse

Method: 1. Use the "debugfs" command to find the offset value and block value of the accidentally deleted file; 2. Use "dd if=source file of=target file bs=offset value count=1 skip=block value ” command to restore the file.

How to recover accidentally deleted files in Linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to recover accidentally deleted files in Linux

The example is as follows:

Execute the command "cd /home" to enter Server root directory home;

Execute the command "touch demo.txt" to create a presentation;

Execute the command "rm -rf demo.txt" to delete the file;

How to recover accidentally deleted files in Linux

Execute the command "debugfs" and use the system's own recovery tool debugfs to repair;

How to recover accidentally deleted files in Linux

Open an additional xshell and execute the command "df /home / "Open the partition where the file just deleted is located;

How to recover accidentally deleted files in Linux

Execute the command "open /dev/mapper/vg_root-lv_root" to view the directory partition;

How to recover accidentally deleted files in Linux

Execute the command "ls -d /home" to display the directory where the deleted files are located;

How to recover accidentally deleted files in Linux

Execute the command "logdump -i " to search The block number where the file is located;

How to recover accidentally deleted files in Linux

Remember the value after the block in the above picture and execute the command "quit" to exit debugfs;

How to recover accidentally deleted files in Linux

Execute the command "dd if=/dev/mapper/vg_root-lv_root of=/home/demo.txt bs=640 count=1 skip=1089" to resume file operations;

How to recover accidentally deleted files in Linux

bs is consistent with the offset value in the above figure, and skip is consistent with the block value;

How to recover accidentally deleted files in Linux

Execute the command "ls" and you can see that the file demo.txt has been deleted and re-created. Got it back and the recovery was successful.

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of How to recover accidentally deleted files in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn