Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use grep to recover mistakenly deleted text files by linux

Shulou Source: shulou.com Published: 2022-06-01 12:25:48 10月22日 Update

This article mainly explains "how to use grep to recover deleted text files in linux", the explanation in the article is simple and clear, easy to learn and understand, please follow the ideas of Xiaobian slowly, together to study and learn "how to use grep to recover deleted text files in linux"!

First create a temporary text file vpsee.log for testing, and then delete this 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 file you just deleted, you can use grep to search the entire/dev/sda1, the-a flag means to treat the partition/dev/sda1 as text (the partition itself is binary), and the-B 10 -A 100 means to print the first 10 and last 100 lines of the keyword if you find it:

# grep -a -B 10 -A 100 'vpsee.com' /dev/sda1 > tmp.txt Find what we just deleted among the @:

$ vi tmp.txt

...

@$^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@Ç^@^@^@^A^@^@^@^@^@^@^@^@^@^@^@È^K^@^@^@

^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@^Q^@^@^@^C^@^@^@^@^@^@^@^@^@^@^@È^K^@^@×^@

^@^@important log file for vpsee.com

@

@

... Of course, if you delete binary, doc, png/jpg/gif files by mistake, you can use some third-party ext2/ext3 file recovery tools to help recover files, such as TestDisk, PhotoRec, etc.

Thank you for reading, the above is "linux how to use grep to recover deleted text files" content, after the study of this article, I believe that everyone on linux how to use grep to recover deleted text files this problem has a deeper understanding, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Tags: File text content learning binary key keyword form meaning between that is tools ideas situations articles more logos knowledge points third parties Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Redmi macOS Huawei Docker