2012/02/04

The Labs.Com Admin Lab UndoRM
Last update 2002/07/12

The Labs - Design & Functionality For The Net

Undoable RM Command for UNIX

  1. Introduction
  2. Download
  3. Usage & Installation
UndoRM
1. Introduction
UNIX is a very powerful environment, but it lacked of something fundamental, undo-able 'rm' (remove) of files. Ok, every prof. system-admin makes daily backups within a business environment, and most files should be recoverable.

But wouldn't it be more handy to just undo the last few rm's you did instead looking up on which backup your files can be found (in case of incremental backups)?

All graphical oriented desktop-environments have it, the trash-can, why not having the same on UNIX too, here it is.

So far Christophe Blaess <ccb@club-internet.fr> wrote this small but extremely useful package, we host here this source-code.

UndoRM
2. Download

undo_rm.tar.gz ($MyVersion: 0.001 - Tue Aug 24 15:20:10 EDT 1999 - kiwi$)

UndoRM
3. Usage & Installation

(Originally written by Christophe Blaess <ccb@club-internet.fr>)

This is a shell script for Bash, called 'rm_secure'. I use it as frontal for the rm command. It stores the deleted files in an archive in the user's directory. A command-line option allows the user to view the content of this archive, and another option permits the restoration of the deleted files.

For example :

 $ ls -l 
 $ ls -l 
 $ rm --viewtrash 
 -rw-r--r--  1 ccb   users    22 May 26 10:35 1996 important_file 
 -rw-r--r--  1 ccb   users    23 May 26 10:35 1996 not_important 
  
 $ rm --restore important_file 
 $ ls -l 
 -rw-r--r--  1 ccb   users    22 May 26 10:35 important_file 
  
 $ rm --viewtrash 
 -rw-r--r--  1 ccb   users    23 May 26 10:35 1996 not_important 
  
 $ rm --emptytrash 
 $ rm --viewtrash 

Okay, it slows down a few the rm command. But it may also save hours of work lost due to a keystroke error...

There is the script 'rm_secure', place it in /usr/bin or /usr/local/bin then insert a line:

   alias rm='/usr/local/bin/rm_secure' 

in /etc/profile, so this script will be called by Bash in the place of the true rm command.

You can use the '--nosecure' or '-n' option to delete a file without archiving it. This is useful when you decide to erase huge amount of files in recursive directories (for example a package you have tested but find uninteresting).

I use a cron job to deleted the archived files every day (running as root job).

 00 04 * * *    /usr/local/bin/empty_trash 

There is the 'empty_trash' script, maybe you can prefer something like :

   trap '/bin/rm ~/.rm_saved.tar.gz EXIT 

in /etc/profile, which erase the archive each time the user exits the shell. (I've not fully tested this)

Obviously this tips doesn't secure the deletion of files or directories by a file-manager, but I find it quite usefull, especially when doing administrative jobs as root ('rm tmp/ *' in place of 'rm tmp/*' ...)

                                                                                                                                   

SymMount Admin LabDNSTool

Hipocrisy of the finest: "I agree that no single company can create all the hardware and software. Openness is central because it's the foundation of choice."
-- Steve Balmer (Microsoft) blaming Apple regarding iPhone, February 18, 2009

Last update 2002/07/12

All Rights Reserved - (C) 1997 - 2009 by The Labs.Com

Top of Page

The Labs.Com