Recovering Deleted Text Files in a *nix Environment!
Posted by: ipp in Technology, tags: Linux, OS X, Recovery, Ubuntu
Oh no! You just deleted a configuration file by accident by accident and need to recover it. Well if your in a *nix environment(os x, linux, etc) there still is hope! This is because when you delete a file it only deletes it from the Table of Contents, but the actual data still exists. You should be the root user to perform any task here!
- First you will need to know what device your file was located, to find this open up a terminal and issue the command: mount | column -t | grep dev
- The first column is the device, and the third is the folder. It only list the parent folder.
- Now we will use grep to scan the device for the file. Issue the command grep –binary-files=text -B5 -A20 “line of the file” device. The -B5 means show 5 lines before the line found. -A20 means show 20 lines after(change this depending on a guess of approx how many lines your file is). and for the line of file you will need to recall a piece of the file word by word (works best with the first line)
Example(test it out!):
I am going to create(then delete) a text file on the device: /dev/sda1 with the contents of:
Dear Ipp,
Thank you for making the wonderful tutorial on recovering lost files! It saved me from recreating a lost config file which may of took a lot of time to recreate!
Sincerely,
A fan of tutorialninjas!
I will now use the command grep -i –binary-files=text -B5 -A20 “dear ipp” /dev/sda1 (notice: i added the -i flag to make it not case-sensitive). After it searched the partition can take a while if it is a large partition it returned:
&& $(MAKE) $(AM_MAKEFLAGS) dvi \
&& $(MAKE) $(AM_MAKEFLAGS) check \
&& $(MAKE) $(AM_MAKEFLAGS) install \
&& $(MAKE) $(AM_MAKEFLAGS) installcheck \
&& $(MAKE) $(AM_MAKEFLAGS) uninstall \
&& (test `find $$dc_install_baseDear Ipp,
Thank you for making the wonderful tutorial on recovering lost files! It saved me from recreating a lost config file which may of took a lot of time to recreate
Sincerely,
A fan of tutorialninjas!
<IfModule mod_php5.c>
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps
</IfModule>
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
Notice i ddi get a lot of “garbage” but i highlighted in bold what actually was the file!
If you are on a windows machine and need to recover something you can probably boot up into “Knoppix” via a cd and do it from there, but I have not tested this method. However there are programs out there to recover lost files on a windows machine, just have to search!
Entries (RSS)