Sunday, July 22, 2012

Create recyclebin in unix based systems

If we see there is no recyclebin in unix systems like windows..So we can create manually that create a recycle directory and further if we need we can undo the recycled files/directories

I learned this one the hard way.

You can always emulate a recycle bin by doing the following:

mkdir ~/recycle

Open your .bashrc and type:

alias rm="my_rm"

Then open a text editor and paste the following:


Code:
#!/bin/sh
# This is a substitute for rm that moves deleted files to a recycle bin

RECYCLE="$HOME"/recycle
CURRENTDIR=`pwd`

for file in "$CURRENTDIR"/$*
do mv "$file" "$RECYCLE"
done

exit 0Save this file as "my_rm" in one of your PATH directories (/usr/local/bin is an appropriate place for it). Then chmod 700 my_rm, so it can be executed. Basically, you're setting things up so that whenever you say "rm FILE(S)" you actually do "mv FILE(S) ~/recycle". Feel free to modify this at your leisure.

-Sredhar

UPDATE: Now that I think about it, this would not work if you tried to delete a file given by its absolute pathname...hmmm.

UPDATE: Or if you gave any of the other rm command-line parameters...urk. I think I'll shut up now.

No comments: