Operating System - HP-UX
1834269 Members
96019 Online
110066 Solutions
New Discussion

Creating a Recycle Bin for Unix

 
SOLVED
Go to solution
Lynn_25
New Member

Creating a Recycle Bin for Unix

I'm just wondering if anyone might have an idea on how to create a shell script that will allow unix users to have the luxury of a "recycle bin"?
8 REPLIES 8
Bill Hassell
Honored Contributor

Re: Creating a Recycle Bin for Unix

You can create a wrapper script for the rm command that moves the requested files and directories to another directory. Be very careful to hide the real rm and remember what it is so that root can actually remove something. This could get real complicated unless you have a spare disk that can hold hundreds of megs of data. Recovering files and directories could get tricky.

However, the solution is backups. If you keep regular backups, then missing files and directories can be restored. I would always alias the rm, mv and cp commands to include the -i option to prevent mistakes:

alias rm='/usr/bin/rm -i'
alias mv='/usr/bin/mv -i'
alias cp='/usr/bin/cp -i'

NOTE: Users (and root) can override the -i option with -f.


Bill Hassell, sysadmin
Lynn_25
New Member

Re: Creating a Recycle Bin for Unix

Thanks for getting back to me, but I don't think that's going to help me... My goal is to create a script that will move files that have been deleted to another file, then confirmation that delete is the option the user wants.
Steven E. Protter
Exalted Contributor

Re: Creating a Recycle Bin for Unix

Then you mistated your question.

Bill's proposal will create a recyling bin which you will need to reveiw.

rmcheck

echo "are you sure you want to delete?Y/N"
read a
if [ "$a" = "Y" ]
then
rm $1
fi

Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Mark Grant
Honored Contributor

Re: Creating a Recycle Bin for Unix

Lynn,

Apart from the wrapper script idea above,which only applies to the "rm" command, you can't do this. Any application that calls the standard C library "unlink" call (the one that does deleting) will delete your file. Unless you change this, which you can't on hpux, the recycle bin idea doesn't work.

Sorry.
Never preceed any demonstration with anything more predictive than "watch this"
dirk dierickx
Honored Contributor

Re: Creating a Recycle Bin for Unix

also worth noting might be that the gnu file utils have can have a confirmation dialog for every file you want to delete. (it is called an interactive mode) when rm is called with the '-i' option it will ask the user if he is sure if he wants to delete the file or not.

to enforce this upon every user you could make an alias of rm that calls 'rm -i'.
Kent Ostby
Honored Contributor
Solution

Re: Creating a Recycle Bin for Unix

Lynn --

While clearly not as clean as the overall solution you are looking for on unix, I often keep around directories which I name such wonderful names as: keep_until_september_01_2004.

I can then search for all of my "keep_until" directories with a script and get rid of the old ones.

I put things like scripts that I'm writing to post out to the ITRC in directories such as these.

I also do the same thing with Mail folders. I always have one that is dated six months from now for all of those kinds of emails that you might need in the next couple of weeks but will never need after that.

Every time a new month rolls around, I delete the (for instance keep-030104), move the a-090104 to keep-090104 and create an a-100104 folder (the a- I use to put it at the top of my mail folders).

Helps keep the junk down.

Best regards,

Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Alzhy
Honored Contributor

Re: Creating a Recycle Bin for Unix

I assume the target environment is such that "UNIX users" will work on a purely shell (aka Terminal, shell or Text) environment - then the suggestions should work.

IF, your "Unix users" are working in a purely GUI environment (ie. KDE, Gnome,etc.).. AND they are using the GUI's file manager , etc. then each environment already has a "Recyle Bin" like scheme..
Hakuna Matata.
Lynn_25
New Member

Re: Creating a Recycle Bin for Unix

Yes, the users will be using scrictly a terminal environment. I think with the suggestions I've received I should be able to make something work.

Thanks