As a long-term computer user, you will certainly experience accidental file deletion. files deleted on Mac OS X and Windows will be added to the "recycle bin" by default ". In Linux, if you do not use the alias) to modify the default rm function, the rm file will be lost. Fortunately, in normal file deletion operations, linux does not immediately clear the block content of the file, but only releases the inode and data block occupied by the file, the rm process on Linux is actually the process of setting the corresponding identifiers in inode bitmap and data block bitmap to idle state, and does not involve real data, this is why deleting large files in Linux is so fast, because the disks occupied by large files are not cleared at all. Therefore, if we can find the inode corresponding to the file and find the corresponding data block, we may recover the deleted file from the disk, many file/Disk Recovery Tools do this.
In general, you can copy and restore binary files, library files, and other files from other Linux systems after deletion. This is not very important. If you have deleted your script or configuration file by mistake, you will get it. Mistaken deletion of such things often occurs on VPSee. The last time at the beginning of this year, screen was used for multiple ssh requests to different servers, A certain configuration file was deleted during the pre-and post-switch process. Later, it was found that the deleted file was correct. Unfortunately, it was on an incorrect server, I should have deleted file.txt on server A. The result is that file.txt is deleted on server B. Multiple screens and ssh have fainted, and the host name is not properly configured, multiple machines use localhost, which is not conducive to identifying the current environment. What if I accidentally deleted a text file when I used Linux?
Create a text file vpsee. log for testing, and then delete the file:
$ echo "important log file for vpsee.com" > vpsee.log
$ cat vpsee.log
important log file for vpsee.com
$ rm vpsee.log
If you can remember a keyword in the deleted file, you can use grep to search for the entire/dev/sda1, -The a flag indicates that the/dev/sda1 partition is regarded as a text partition and is in binary format ), -B 10-A 100 means that if the keyword is found, the content of the first 10 rows and the last 100 rows will be printed:
# grep -a -B 10 -A 100 'vpsee.com' /dev/sda1 > tmp.txt
Find the content we just deleted between a bunch:
$ vi tmp.txt...@$^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@?^@^@^@^A^@^@^@^@^@^@^@^@^@^@^@è^K^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@^Q^@^@^@^C^@^@^@^@^@^@^@^@^@^@^@è^K^@^@×^@^@^@important log file for vpsee.com@@...
Of course, if files such as binary files, doc files, png files, jpg files, and gif files are accidentally deleted, you can use some third-party ext2/ext3 file restoration tools to help restore files, such as TestDisk and PhotoRec.