LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Getting a deleted file (https://www.linuxquestions.org/questions/linux-newbie-8/getting-a-deleted-file-851338/)

Ajit Gunge 12-20-2010 05:29 AM

Getting a deleted file
 
I have run a rm command on one of my files.This file was actually a file named .MR_ASSESS.swp and later when I opened a file MR_ASSESS I cannot find all my data that was there in the .MR_ASSESS.swp file is there any way that I can get this data.
Please help.Any input with this regard is apprciated.

Ajit

Snark1994 12-20-2010 06:17 AM

Try foremost or testdisk (both recommended in this thread - I haven't actually tried them myself). Like it says in the thread, you will only be able to recover it if you haven't subsequently overwritten the actual data in the file.

divyashree 12-22-2010 06:18 AM

Quote:

Originally Posted by Ajit Gunge (Post 4197538)
I have run a rm command on one of my files.This file was actually a file named .MR_ASSESS.swp and later when I opened a file MR_ASSESS I cannot find all my data that was there in the .MR_ASSESS.swp file is there any way that I can get this data.
Please help.Any input with this regard is apprciated.

Ajit

You can do one thing, while running rm , you can mv files to trash , so you can recover them from trash or delete the m forever from trash.

This will rename the normal rm file.
PHP Code:

mv /usr/bin/rm /usr/bin/rm.bak 

Now create another rm file as /bin/rm

PHP Code:

#!/bin/bash

mkdir ~/.Trash &> /dev/null

while [ ! -"$1" ]; do
    
mv "$1" ~/.Trash/
    
shift
done 

This is if .Trash doesnot exist in your home or comment the 1st line

give it 755 permission.

Now rm will send files to trash and you can recover them or permanently remove them.

MTK358 12-22-2010 08:38 AM

And your new rm script will be overwritten by the real rm once your package manager updates coreutils.

w1k0 12-22-2010 09:53 AM

So better than write a script is to write the function and put it in both ~/.bashrc and ~/.bash_profile:

Code:

function rm {
if [ ! -d ~/.Trash ]
then
    mkdir ~/.Trash
fi
while [ ! -z "$1" ]; do
    mv "$1" ~/.Trash/
    shift
done
}


divyashree 12-22-2010 11:29 AM

Quote:

Originally Posted by MTK358 (Post 4200086)
And your new rm script will be overwritten by the real rm once your package manager updates coreutils.

Yes a line like this can be added to the script

PHP Code:

if [ -/bin/rm 
 
then
 mv 
/bin/rm /bin/rm.bak
 fi 


ghaad 12-22-2010 12:33 PM

@MTK358: Actually this script can be placed into ~/bin
Just create ~/bin, put the script into this directory, change its permissions
Code:

chmod +x ~/bin/rm
and then add the following code into ~/.bashrc
Code:

PATH=/home/xxxxx/bin:$PATH:
(xxxxx should be replaced by user home directory). This way it doesn't matter if you upgrade your coreutils.

unSpawn 12-22-2010 12:54 PM

Quote:

Originally Posted by divyashree (Post 4199966)
you can mv files to trash

Anyone who still offers scripted rm kludges as a "solution" over libtrash is invited to expand his or her horizon and have a look at this post.

unSpawn 12-22-2010 05:08 PM

Quote:

Originally Posted by Snark1994 (Post 4197577)
Try foremost or testdisk (both recommended in this thread - I haven't actually tried them myself). Like it says in the thread, you will only be able to recover it if you haven't subsequently overwritten the actual data in the file.

The thread you mention is quite old (2006 / 2007) and seems to hold only crap "advice" in the first few posts (where things should matter): "this requires some other technique that I don't know.", turning the 'rm' command into some weak scripted kludge (see this) and debugfs (only works semi-successfully with non-journalling file systems). Besides foremost or testdisk are not the applications to look for. The first thing to do is actually do nothing except make a bit copy backup with 'dd' or equivalent and store it somewhere safe and (only mount) read-only. First tool to use would be testdisks companion app 'photorec' as it's a file carver (testdisk can access files it primarily is a disk partition scan and repair tool and the signature database for foremost doesn't rival that of photorec). * If you're not familiar with recovery processes it would be good to do some research (we've got quite a few recovery threads) before posting as it'll save the OP time.

Ajit Gunge 01-05-2011 03:09 PM

Thanks for all your suggestions.SO i think recovery procedures are the only ways that I can use.Are there any preventive measures that I can use.Also all you people keep refering to thrash folder How do I go about creating this folder and setting my rm command such that every time an rm command is run it outputs it to thrash first.

Andy Alt 01-06-2011 12:37 AM

Quote:

Originally Posted by unSpawn (Post 4200353)
Anyone who still offers scripted rm kludges as a "solution" over libtrash is invited to expand his or her horizon and have a look at this post.

I was pretty pleased to see my sf project mentioned. Thank you, unSpawn.

I've done some work on the rmw script mentioned in the post linked above. It's less "weak" now. :)

ReMove to Waste
http://sourceforge.net/projects/rmw/

It has a few easy methods of restoring, and can also, if Desktop Trash is enabled, ReMove files so they'll show up in the Trash on KDE, GNOME, or Xfce (for even easier restoration). I haven't tested other GUI environments yet.

It still needs some work, but good enough for beta testing, IMO.


All times are GMT -5. The time now is 01:05 AM.