LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   INFORMATION!!!!! rm will move deleted data to Trash.........For future recover (https://www.linuxquestions.org/questions/linux-server-73/information-rm-will-move-deleted-data-to-trash-for-future-recover-666613/)

farrukhndm 08-31-2008 06:00 AM

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...

unSpawn 08-31-2008 06:40 AM

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.

ErV 08-31-2008 07:35 AM

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.

farrukhndm 09-01-2008 07:43 AM

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----------------

unSpawn 09-01-2008 12:40 PM

Why limit yourself to a script if you can use something like http://freshmeat.net/projects/libtrash/?

checkmate3001 09-01-2008 12:57 PM

Quote:

Originally Posted by farrukhndm (Post 3266057)
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'?


All times are GMT -5. The time now is 11:31 PM.