LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-20-2010, 06:29 AM   #1
Ajit Gunge
Member
 
Registered: Jan 2008
Location: Pune
Distribution: RHEL,fedora
Posts: 253
Blog Entries: 1

Rep: Reputation: 21
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
 
Old 12-20-2010, 07:17 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
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.
 
Old 12-22-2010, 07:18 AM   #3
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by Ajit Gunge View Post
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.

Last edited by divyashree; 12-22-2010 at 07:40 AM.
 
Old 12-22-2010, 09:38 AM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
And your new rm script will be overwritten by the real rm once your package manager updates coreutils.
 
Old 12-22-2010, 10:53 AM   #5
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware, Mint
Posts: 1,252

Rep: Reputation: 205Reputation: 205Reputation: 205
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
}
 
Old 12-22-2010, 12:29 PM   #6
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by MTK358 View Post
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 
 
Old 12-22-2010, 01:33 PM   #7
ghaad
LQ Newbie
 
Registered: Dec 2010
Location: Czech Republic, EU
Distribution: ArchLinux
Posts: 1

Rep: Reputation: 0
@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.
 
Old 12-22-2010, 01:54 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Quote:
Originally Posted by divyashree View Post
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.
 
Old 12-22-2010, 06:08 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Quote:
Originally Posted by Snark1994 View Post
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.
 
1 members found this post helpful.
Old 01-05-2011, 04:09 PM   #10
Ajit Gunge
Member
 
Registered: Jan 2008
Location: Pune
Distribution: RHEL,fedora
Posts: 253
Blog Entries: 1

Original Poster
Rep: Reputation: 21
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.
 
Old 01-06-2011, 01:37 AM   #11
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware32-stable, Debian32 stable, LFS 7.1
Posts: 385

Rep: Reputation: 44
Quote:
Originally Posted by unSpawn View Post
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleted log file - how to get back via file descriptor and keep alive? prollocks Linux - General 1 05-29-2009 10:08 AM
Need help to recover Deleted file - (file was saved in doc) Pravab Ubuntu 2 08-17-2008 11:57 AM
Deleted File jasbhatti Linux - Newbie 7 05-03-2008 10:59 PM
Deleted file klmn1 Linux - Software 2 12-12-2003 07:04 AM
DLoaded a file that cannot be deleted.Please Help Me yuism Linux - Security 8 11-24-2002 03:34 PM


All times are GMT -5. The time now is 10:18 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration