This would by necessity be a very platform-specific function, and one which is pretty useless these days, because it only works on ext2 and not on the more modern file systems such as ext3, ReiserFS, XFS, etc. I imagine that these days ext2 is only used on systems that have been in production a long time, or systems which depend on the minimal speed benefit it still enjoys over journaling filesystems. Such systems are unlikely to be handled by someone who is fumble-fingered enough to habitually delete the wrong file, and even then they would normally have backups. If you want to write a Perl wrapper for debugfs, go for it, but I don't imagine it'll get much use.
Anyway, solving this at the filesystem level is the wrong way IMO. If you have users you don't trust to take enough care when deleting, alias the rm command to something that moves files into a temporary directory. IIRC there are some free libraries about which let you do this transparently, so you don't need to mess with shell aliases. And above all, keep backups!
There are ten types of people: those that understand binary and those that don't.
| [reply] [d/l] |
| [reply] |
rm REMOVES files. There is no attention paid to recovery. Yes, you can sometimes forensically recover files that have been removed, but it is extremely unwise to rely on such recovery -- it's more fragile than you might imagine.
The better solution is this:
$ chown root:wheel /bin/rm
$ chmod 0550 /bin/rm
$ echo mv $* $HOME/.rmTrash/ >/usr/local/bin/rm.safe
$ chown root:users /usr/local/bin/rm.safe
$ chmod 0555 /usr/local/bin/rm.safe
$ for dir in /home/*; mkdir $dir/.rmTrash
> echo alias rm=rm.safe >> $dir/.aliases ; done
Then only root and the people in the wheel group can use the "real" rm, the rest will use the "safer" version. If you can't trust people in wheel, then you have bigger problems.
| [reply] [d/l] [select] |
aliasing rm to mv does have its problems. For one thing mv doesn't support -r (as in rm -rf). Another is the trouble of when the user deletes two items of the same name. Also it enables the user to rm whole directories without using any special flags, whereas typical rm doesn't work that way.
On our system (because we had a user delete the etc dir, we decided to get rid of rm) we created a shell script that parsed the cmdline for illegal mv options, and also put each duplicate rm'd item into a unique subdir that was identifiable by a timestamp/date.
| [reply] |
| [reply] |