kulls has asked for the wisdom of the Perl Monks concerning the following question:

I heard many of them said that once you did 'rm' then it is not possible to get it back ?

But, Here they can achieved through the debugfs command in Linux.
Shall we have any perl script that will do 'undelete' using this command ? .
If anyone tried with these command please help me.
- kulls

Replies are listed 'Best First'.
Re: [OT] undo rm command ??
by tirwhan (Abbot) on Jan 30, 2006 at 10:52 UTC

    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.
Re: [OT] undo rm command ??
by rnahi (Curate) on Jan 30, 2006 at 11:20 UTC
Re: [OT] undo rm command ??
by radiantmatrix (Parson) on Jan 30, 2006 at 20:44 UTC

    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.

    <-radiant.matrix->
    A collection of thoughts and links from the minds of geeks
    The Code that can be seen is not the true Code
    I haven't found a problem yet that can't be solved by a well-placed trebuchet

      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.

Re: [OT] undo rm command ??
by diotalevi (Canon) on Jan 30, 2006 at 15:40 UTC