Article Title: Use grep to restore the content of the deleted file. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
In Unix/Linux, the most dangerous command is probably the rm command. Every time you use this command under root, I have to stare at the command line for a few minutes before I can press Enter. Previously, I saw my colleague use the rm command -- rm {$ App_Dir}/* in the script }/*. Because the script does not judge whether the variable $ App_Dir is null, the result is that during a root operation, the entire operating system will disappear. Fortunately, it is only a development machine. Since then, we have never dared to use the rm command again.
Here is a tip for you to use to restore data in some rm files. We know that the rm command does not actually delete the file content physically, but does not recycle the inode of the file. In fact, the file content is still on the hard disk. Therefore, if you delete some important program configuration files, we can use the grep command to restore them. The following is a recovery example:
Grep-a-B 50-A 60 'some string in the file'/dev/sda1> results.txt
Note:
What is the-a meaning of grep? Binary-files = text, that is, the binary file is used as a text file.
The options of-B and-A are the first few lines and the last few lines of the string.
/Dev/sda1, which is a hard disk device,
> Results.txt: redirects the result to the results.txt file.
If you are lucky, you can see the recovered content. This is exactly the simple Unix philosophy-all devices are files.
Of course, I suggest you replace the rm command of the root user with alias with another script, which will help you put the deleted file to