LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-31-2008, 06:00 AM   #1
farrukhndm
Member
 
Registered: Mar 2008
Location: Pakistan
Distribution: Fedora,Centos,RHEL
Posts: 75

Rep: Reputation: 15
Smile INFORMATION!!!!! rm will move deleted data to Trash.........For future recover


As far as how to make stuff go to the trash instead of deleted, run this as root:
Code:

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

Now copy this script and save it as /usr/bin/rm:
Code:

#!/bin/bash

mkdir ~/.Trash &> /dev/null

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



---------------------------------------------------
This will, instead of deleting files, move them to the .Trash directory in your home directory, and you can delete them for real later.


If there are any comments aor any other soltion to get rid of accidently deleted file,please disucess here...
 
Old 08-31-2008, 06:40 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590
Note that 'rm' can also be "/bin/rm", you don't use error detection ("&&") or switch termination (try moving a file called "--help"), backgrounding commands like that could lead to problems when a system is under a high load, you don't use force (should you?) and a while loop like that slows things down. All in all it's a nice try but unfortunately comes nowhere near for instance syscall-intercepting methods like say LD_PRELOAD'ed thrashcan solutions offer.
 
Old 08-31-2008, 07:35 AM   #3
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
It doesn't support rm command-line switches, so it's not a good idea to use that.
Code:
OPTIONS
       Remove (unlink) the FILE(s).

       -f, --force
              ignore nonexistent files, never prompt

       -i     prompt before every removal

       -I     prompt once before removing  more  than  three  files,  or  when
              removing  recursively.  Less intrusive than -i, while still giv-
              ing protection against most mistakes

       --interactive[=WHEN]
              prompt according to WHEN: never,  once  (-I),  or  always  (-i).
              Without WHEN, prompt always

       --one-file-system
              when  removing  a hierarchy recursively, skip any directory that
              is on a file system different from  that  of  the  corresponding
              command line argument

       --no-preserve-root
              do not treat `/' specially

       --preserve-root
              do not remove `/' (default)

       -r, -R, --recursive
              remove directories and their contents recursively

       -v, --verbose
              explain what is being done

       --help display this help and exit

       --version
              output version information and exit
Another problem is that identically named files will overwrite each other in trash directory, so files STILL will be deleted accidentally.
 
Old 09-01-2008, 07:43 AM   #4
farrukhndm
Member
 
Registered: Mar 2008
Location: Pakistan
Distribution: Fedora,Centos,RHEL
Posts: 75

Original Poster
Rep: Reputation: 15
how to get rid of rm -rf if accidenlty used

Please discuess if any of you have the right script that will make getrid of rm -rf comamnd if accidently used.

Waiting----------------
 
Old 09-01-2008, 12:40 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590
Why limit yourself to a script if you can use something like http://freshmeat.net/projects/libtrash/?
 
Old 09-01-2008, 12:57 PM   #6
checkmate3001
Member
 
Registered: Sep 2007
Location: Folsom, California
Distribution: Ubuntu, Mint, Debian, Suse
Posts: 307

Rep: Reputation: 32
Quote:
Originally Posted by farrukhndm View Post
Please discuess if any of you have the right script that will make getrid of rm -rf comamnd if accidently used.

Waiting----------------
I recommend being *VERY* careful when using that command. Don't get rid of it... just don't use it unless you are absolutely *SURE* that is what you want to do.

I have an alias that is rm='rm -i' but that does nothing if you throw in the rm -rf.

Can you alias a command like rm -rf='rm -rfi'?
 
  


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
how to recover home data, got deleted with the profile manishgarg21 Linux - Newbie 5 05-28-2008 07:16 AM
Move to trash works beautifully, but empty trash .. different story. kd5eax Mandriva 2 12-04-2007 02:52 PM
Reiserfsck stops when rebuilding tree at 50% - trying to recover deleted data vangelis Linux - Software 6 10-23-2006 12:34 PM
need to recover data in a deleted inode wilsonsamm Linux - General 6 08-30-2006 11:34 AM
Software to help me recover 'Deleted' FAT32 Partition Data? flamesrock Linux - Software 8 07-26-2005 10:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:24 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration