Today Accidently I deleted one of my folder in ubuntu which has contained important files, but I wanted to copy those to another machine by tarring it, while there was another archive / tar with same name, I wanted to delete that .tar but deleted folder resulting deleting very important files.
To recover those files immidiately I used following commands,
$ sudo apt-get install extundelete
Now check where the hard disk is mounted using df -h command, in our case it was at /dev/sda1
$ df -h Filesystem Size Used Avail Use% Mounted on udev 1.9G 12K 1.9G 1% /dev tmpfs 387M 700K 386M 1% /run /dev/sda1 455G 210G 222G 49% /
$ sudo extundelete --restore-directory /home/myuser/path-of-deleted-folder/deleted-folder-name /dev/sda1 [sudo] password for myuser: WARNING: Extended attributes are not restored. WARNING: EXT3_FEATURE_INCOMPAT_RECOVER is set. The partition should be unmounted to undelete any files without further data loss. If the partition is not currently mounted, this message indicates it was improperly unmounted, and you should run fsck before continuing. If you decide to continue, extundelete may overwrite some of the deleted files and make recovering those files impossible. You should unmount the file system and check it with fsck before using extundelete. Would you like to continue? (y/n) y Loading filesystem metadata ... 3695 groups loaded. Loading journal descriptors ... 29653 descriptors loaded. Writing output to directory RECOVERED_FILES/ Searching for recoverable inodes in directory /ho/home/myuser/path-of-deleted-folder/deleted-folder-name ... 1276 recoverable inodes found. Looking through the directory structure for deleted files ... Restored inode 23071241 to file RECOVERED_FILES/home/myuser/path-of-deleted-folder/deleted-folder-name/myfile1.txt Restored inode 23070734 to file RECOVERED_FILES/home/myuser/path-of-deleted-folder/deleted-folder-name/myfile2.csv Restored inode 23071394 to file RECOVERED_FILES/home/myuser/path-of-deleted-folder/deleted-folder-name/myfile.pdf 1266 recoverable inodes still lost.
Now you should have RECOVERED_FILES new folder created in your working directory and it will have all recovered folder and files along with relative path.