accidental deletion of home
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!
Solution 1:
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?