accidental deletion of home
Unfortunately, and in general, this is not reversible. Files are moved to trash only when you are deleting them using the graphical user interface. The purpose of the command line is to be powerful, but with great power comes great responsibility :-)
EDIT: as one of the commentators rightly noted, it is advisable to boot the liveCD and use extundelete from there. That way, the actual system is not touched.
Before you read the rest of this answer, please read this article.
However, there is an undelete utility (not guaranteed to work, however) that you can try.
First, check that you have an ext3 or ext4 file system (run this command from a terminal):
mount
You should see several lines, among them something like that:
/dev/sda6 on /home type ext4 (rw)
(if your home is on a separate partition) or
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
(if your home is on the root partition). If you have any doubts, post the whole output of the mount command here.
Next, install extundelete, either using Ubuntu software center of from the command line:
sudo apt-get install extundelete
The bad news is, from here on it gets more complicated. Additionally, you will be working from command line as root, having the power of completely destroying your system, so please take care of what you type.
First, you should not run extundelete on a mounted partition, and you need to know on which device your home sits. If your home is on separate partition (say, /dev/sda6, as you see in the above example), boot your Ubuntu in safe mode. Press shift during the boot process, and when a menu comes up, select recovery mode and then "drop to root command prompt".
Then, you need to remount the root filesystem writeable:
mount -o rw,remount /
Then, run
extundelete /dev/sda6 --restore-all
The files that can still be saved will be restored, and extundelete will show you where it did store them.
Unfortunately, from my experience, extundelete runs as often as it doesn't. Often you get "segmentation fault". In which case, you will have to download the source and build it yourself, which should fix the problem.
For the future, please remember the old saying: there are two kinds of people; those who do proper backups and those who will. Making backups with Ubuntu is easy, so why not do it?
Related videos on Youtube
Shagun Sodhani
Updated on September 18, 2022Comments
-
Shagun Sodhani over 1 year
I by mistake excecuted this command:
sudo sh
And then:
rm -r ~
I closed the terminal but still many files are gone and they are not in trash. I haven't executed any command since then so can I some how revert my previous command? Someone, please help!
-
Jazz over 11 yearsIf you have you been doing backups with the backup program Ubuntu provides, it can restore the home directory files for you.
-
Eliah Kagan over 11 yearsIf you need to recover lost data, it's imperative that you immediately shut down the newly installed system and not use it. You can run from a live CD provided that swap is disabled. See the guidelines here. Hopefully someone will post an answer with helpful information soon (or maybe we can close this as a duplicate of another question that has good answers about how to recover deleted files). For now, that link should help you some.
-
-
Eliah Kagan over 11 yearsFile recovery utilities including
extundelete
should be run from a different system from the one in which the deleted files existed. Following these directions, as you have written them, could result in the deleted files being overwritten by the files created when theextundelete
package is downloaded and installed, as well as by files created or modified during the normal course of the system running idly. The OP should runextundelete
from a live CD. -
Shagun Sodhani over 11 yearsSeems it would help me @January :)
-
Shagun Sodhani over 11 yearsI couldnt recover much but still thnxs :)