Home >Operation and Maintenance >Linux Operation and Maintenance >How to recover accidentally deleted files in Linux
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.
#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;
Execute the command "debugfs" and use the system's own recovery tool debugfs to repair;
Open an additional xshell and execute the command "df /home / "Open the partition where the file just deleted is located;
Execute the command "open /dev/mapper/vg_root-lv_root" to view the directory partition;
Execute the command "ls -d /home" to display the directory where the deleted files are located;
Execute the command "logdump -i " to search The block number where the file is located;
Remember the value after the block in the above picture and execute the command "quit" to exit debugfs;
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;
bs is consistent with the offset value in the above figure, and skip is consistent with the block value;
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!