How to recover data / folder deleted with rm -rf

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.
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) 
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.

Android Android Commands Android Java Applications Application Libraries Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Core Kernel C Programs Development Environment Setup Documents / Books Errors & Failures File Systems Framebuffer / Display Driver git Go Language Programs Hardware Platforms Home JAVA Programs Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL NDK / Middleware / HAL Network Driver OS Concepts PHP Procfs Filesystem Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply