LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-14-2007, 05:30 AM   #1
akhil.mud
LQ Newbie
 
Registered: Sep 2007
Posts: 17

Rep: Reputation: 0
how to get back deleted files


by mistake i have issued rm -rf command on some off the files in my system, but i requires thoes file urgently, how can i get back thoes files?????
 
Old 12-14-2007, 06:08 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
rf -rf when executed in / by the root used will totally hose your system. If someone tricked you into executing it, go and do something vengeful to them.

The easiest thing to do is restore from backup. You do have a backup right?
 
Old 12-14-2007, 06:18 AM   #3
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 142Reputation: 142
Matthew is fully right.
 
Old 12-14-2007, 06:52 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Don't do anything that would write to the disk. Data is (in principle) recoverable as long as it is not overwritten. There are file recovery utilities available or you can get the disk to a professional recovery service.
 
Old 12-14-2007, 07:14 AM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
He said "some of files", so he must mean that he deleted a subdirectory in his home directory instead of the system.

If you still have a program that has a lock on the files, you can examine /proc/<proc_id>/fd/ of the program accessing them. Maybe if you had the subdirectory open in konqueror and it hasn't been refreshed, you can recover them that way.

For example:
Code:
pidof xmms
9331
jschiwal@hpamd64:~> ls /proc/9331/fd/ -l
total 0
lrwx------ 1 jschiwal jschiwal 64 Dec 14 06:54 0 -> /dev/pts/0
lrwx------ 1 jschiwal jschiwal 64 Dec 14 06:54 1 -> /dev/pts/0
lr-x------ 1 jschiwal jschiwal 64 Dec 14 06:54 10 -> /dev/snd/timer
lrwx------ 1 jschiwal jschiwal 64 Dec 14 06:54 11 -> /dev/snd/pcmC0D0p
lrwx------ 1 jschiwal jschiwal 64 Dec 14 06:54 2 -> /dev/pts/0
lrwx------ 1 jschiwal jschiwal 64 Dec 14 06:54 3 -> socket:[1142217]
lrwx------ 1 jschiwal jschiwal 64 Dec 14 06:54 4 -> socket:[1142219]
lr-x------ 1 jschiwal jschiwal 64 Dec 14 06:54 5 -> pipe:[1142223]
l-wx------ 1 jschiwal jschiwal 64 Dec 14 06:54 6 -> pipe:[1142223]
lrwx------ 1 jschiwal jschiwal 64 Dec 14 06:54 7 -> socket:[1142224]
lrwx------ 1 jschiwal jschiwal 64 Dec 14 06:54 8 -> /dev/snd/controlC0
lr-x------ 1 jschiwal jschiwal 64 Dec 14 06:54 9 -> /mnt/hpmedia/podcasts/Security Now!/SN-122.mp3
If I were to rm the SN-122.mp3 file, I could get it back by copying /proc/9331/fd/9. This method has no chance of success if you reboot.

If these files are very important, you should make an image backup of the filesystem and use that to try to recover the files from. You want to make sure you stop using the filesystem so that you don't overwrite the same location that the older files were in. If you google for it, there may be an "undelete" program for the ext2 filesystem. You can try mounting an ext3 filesystem as an ext2 filesystem. This will fail if the journal isn't empty.

There are file recovery live CD distro's on sourceforge. A lot depends on the type of filesystem these files were on. You didn't mention that. The live CD should use a recent kernel. If you have a newer version of some filesystems, you may not be able to mount them.

Another method is to use forensic tools. For this, you need an understanding of the filesystem and the format of the files. With text files, you can use grep to try to locate where on an image certain words are. Many file types start with certain "magic" bytes that identify them. This is what the "file" command uses to identify a file. It would be possible to use the same database of magic bytes that file uses to identify files on an image. This isn't easy, and even if you can find the beginning of a file, you may need to guess it's length, and hope it wasn't fragmented.

Last edited by jschiwal; 12-14-2007 at 07:15 AM.
 
Old 12-14-2007, 10:32 AM   #6
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 142Reputation: 142
jschiwal, I have a question: I don't know much about filesystems but I know that in the old days, when I still was a Windows'er and had my partitions formatted with FAT32, I used to recover deleted files using programs that were probably scanning the whole HD searching for files marked as "deleted" but with at least a part if their contents still existing.
Now, you were speaking about ext2 & 3 and I don't know how it looks with NTFS, but I know that I wasn't able to find anything like that for JFS and ReiserFS. The same applies to disk defragmenters. Do you have a clue if "undelete" programs for those filesystem actually exists? If they don't exist, why? Is it because JFS and ReiserFS belong to the category of "Journaling filesystems"?
Thanks a lot...
 
Old 12-14-2007, 10:39 PM   #7
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
When using forensic tools like foremost or photorec (part of the testdisk package), the application looks at headers and footers of files regardless of the file system format. Even if partition information has been changed, as long as the free space created when you removed the files is not used again.
Windows file systems use an "even wear" strategy, where it will keep writing files to the oldest contiguous set of clusters using up all free space on a new drive before writing to free space created by deleting files over time.
Some Mac file systems implement this also, but I believe some if not all Linux file systems allocate files differently where you can overwrite an area recently deleted regardless of the time it became free.
As suggested above, make an image of the drive, once you have an image you can continue using the computer without fear of overwriting recoverable data. The best way to dig for data is to make a copy of the image and work on the copy, and you'll always have the original to fall back on for whatever reason. If you don't have a larger drive to store it on for mounting, you can make the image in slices, like 4GB slices that can be stored on a Fat32 file system which has a 4GB file size limit, or 650MB slices that can be stored on many CDs. There are many applications available that can make the image in slices, then mount them for forensic analysis/data recovery just like mounting the drive in the slave position when booting from another drive. Or you can make the slices with a specialized application and mount them with a mounting application.
One of the best applications that does this is ENCASE, there should be a way to mount slices in Linux that I'm not aware of. So far I've only mounted hard drive images in it's entire size, not slices, I have only read about slices.
Foremost is kind of nice as you can easily customize the configuration file, it has some common file extension header, and in some cases, header and footer (file signatures) information.
When you open a file in a hex editor in HEX mode you would see how the structure of the header and or footer signature is derived in the entry for that file's extension in the foremost configuration file. With that knowledge, you can open a file with a "not so common" file extension in a hex editor to find the signature and add an entry in the configuration file for it.
Quote:
The same applies to disk defragmenters.
When files are written contiguous (when all the clusters/blocks are in line one after the other) they are not fragmented. Fragmented data usually does not happen with many file systems until all free space has been written too at least once and there is not much free space on the drive. Because files deleted over time were likely scattered all over the drive, when the system can't find enough contiguous clusters/blocks it writes the files in different areas creating a fragmented file.
De-fragmenting a drive rearranges the placement of many files to store them contiguously so they are not fragmented. This requires overwriting many "free space" clusters/blocks that contain recoverable data. De-fragmenting reduces future file recovery success.
 
Old 12-15-2007, 08:29 AM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Disk defragmenters are useful for Fat32 partition, but they aren't as necessary for even the NTFS filesystem. Files don't get as fragmented on modern filesystems. The Fat filesystem will store a file to the first available free space regardless of the filesize. Also, modern operating systems aren't single user. Other users and services will be writing to the disk so the head will be going to different parts of the drive anyway. There may be disk caching going on as well, allowing the drive to read the entire sector before handling a different file.

Did you say it was an NTFS partition or something else? For some filesystems there may be a undelete utility on your system. Look in your package system for packages like xfsprogs or ntfstools. A package for JFS has a filesystem editor for example.

Here is a undelete project for ext3: http://freshmeat.net/projects/giis
 
Old 12-16-2007, 11:50 AM   #9
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 142Reputation: 142
Thanks jschiwal
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I deleted some files and and want them back carlsonultimate Linux - Newbie 4 09-28-2007 06:28 PM
How to get the deleted contents back. UltraSoul Solaris / OpenSolaris 1 12-07-2006 01:08 AM
LXer: Bring back deleted files with lsof LXer Syndicated Linux News 0 11-16-2006 11:54 PM
Re: Getting back deleted files in ext3fs talpa_sai Linux - Software 1 04-04-2006 03:10 PM
accidentally deleted some files and I don't know what I need to do to get them back Michele Linux - Newbie 2 06-26-2004 05:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration