Restore accidentally deleted text files with grep

Source: Internet
Author: User
Using grep to restore accidentally deleted text files as long-term computer users will certainly experience accidental file deletion. files deleted on MacOSX and Windows will be imported to the recycle bin by default. In Linux, if you do not use the alias (alias) to modify the default rm function, rm... using grep to restore accidentally deleted text files as a long-term computer user 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 an alias (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 temporarily. log, 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 file, -The a flag indicates that the/dev/sda1 partition is in the text format (the partition itself is in the binary format ), -B 10-A 100 indicates 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 can find the content we just deleted between a bunch of @: $ 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.
Related Article

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.