> For the complete documentation index, see [llms.txt](https://wxg.gitbook.io/linux/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wxg.gitbook.io/linux/file-recover.md).

# file recover

log an exciting experience of file recover

Today 26/Dec should be remembered, and be taken as an lesson. After finishing the main work of a python project, i decide to write a \`clean.sh\` shell script to delete some tmp files of the project. And i noticed there's a pycache directory, and may be the project will look nicer if i delete it. So i add a line in \`clean.sh\`, \`rm -r python \_\_pycache\_\_\`, and just run it. Then tragic happens and my python directory is gone, in which i have stored all of my python source files.

Till then i notice that i should have added \`rm -r python/\_\_pycache\_\_\`. It is such a strike since i have be working the project for a whole day, so i begin an excited way to try to recover the lost directory.

After goole and baidu how to recover from \`rm -r\` operations, i found some tools.

## ext3grep

I have first tried this tool, but it logs a problem. I have searched the problem and understand that the partition should be unmounted so as to operate, while my disk partition happens to be mounted '/' directory, which is apparently not impossible to be unmounted. So this tool is just useless.

```bash
$sudo apt-get install ext3grep
$ext3grep --help
```

## extundelete

This is a similar tool just like ext3grep. Also i get a problem like the ext3grep, but this program does not break out like ext3grep, so it remains hope still. The problem asks 'Yes/No', i dare not to go on operation at first, for the reason that i have searched the problem it output, and some other people says 'No' is the right choice.

But after all other operations have failed, i have no choice but to keep extundelete as a try. And the files did come back, but... half of them. I still feels happy for the important ones have come back, lucky i could only say.

```bash
$sudo apt-get install extundelete
$extundelete --help
```

## Remembers

Although this time such a tragic did not cause much troubles anyway, it is still necessary to take this as a lesson and remember the several following things:

* backup important files
* keep a copy of the project on github
* take careful and take careful before RM something, especially a directory.
