LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 05: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, 06:17 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
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, 06:18 AM   #3
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

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 06:40 AM.
 
Old 12-22-2010, 08:38 AM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
And your new rm script will be overwritten by the real rm once your package manager updates coreutils.
 
Old 12-22-2010, 09:53 AM   #5
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Rep: Reputation: 234Reputation: 234Reputation: 234
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, 11:29 AM   #6
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

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, 12: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, 12:54 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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, 05:08 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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, 03:09 PM   #10
Ajit Gunge
Member
 
Registered: Jan 2008
Location: Pune
Distribution: RHEL,fedora
Posts: 253

Original Poster
Blog Entries: 1

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, 12:37 AM   #11
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Rep: Reputation: 167Reputation: 167
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



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 09:08 AM
Need help to recover Deleted file - (file was saved in doc) Pravab Ubuntu 2 08-17-2008 10:57 AM
Deleted File jasbhatti Linux - Newbie 7 05-03-2008 09:59 PM
Deleted file klmn1 Linux - Software 2 12-12-2003 06:04 AM
DLoaded a file that cannot be deleted.Please Help Me yuism Linux - Security 8 11-24-2002 02:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:13 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