[Gllug] 'safe' deletion of files

Ashley Evans ashley at seamlessrecruitment.com
Wed Aug 11 08:01:38 UTC 2004


t.clarke wrote:

>David Damerell <damerell at chiark.greenend.org.uk> wrote:-
>
>  
>
>>The real answer to this one is that by all means one should have a
>>non-permanent deletion command, but it absolutely should not be called
>>"rm". Then when users get used to it, it will just not work on other
>>systems.
>>    
>>
>
>As a matter of interest, I knocked-up something to use on our Unix system,
>specifically to deal with the problem of files being deleted and then
>the user (sometimes me!) discovering later that the file might be useful after
>all !
>It isn't perfect, but seems to do the job reasonably efficiently.
>An extract from the source is appended below. It should compile on linux - if
>anyone might find it useful just email me.
>Tim
>
>
>
>
>
>--
>/*
>'Remove Safely' program.
>Instead of simply deleting the file(s), the program attempts to rename them
>into a '.trash' directory on the same filesystem, or failing that attempts
>to copy them to a default /var/.trash' directory and then delete.
>Ideally, there needs to be a .trash directory on each mounted filesystem,
>to avoid unecessary copying. However, if disc space is at a premium,
>the lack of a .trash directory on that filesystem will cause immediate
>copying and deleting, thus freeing space on that filesystem.
>The program determines the filesystem .trash directory to use simply by
>attempting rename operations at the root level and 'working down', up to
>a level of 4 directories.   If you have filesystems mounted at a lower level,
>then simply increase the defined value DIRLIMIT appropriately.
>If a file being 'deleted' already has a copy of an earlier version within
>the destination .trash directory, it is appended with ~A and the rename
>operation tried again, up to '~Z'.  Thus up to 26 versions of the saved file
>may exist within the .trash directory before 'deletion' will fail.
>It is probably a good strategy to periodically irrevocably delete (using rm)
>the files building up within the .trash directories, or move them to a 'master
>archive' fiesystem !
>The files contained within the .trash directories are given filenames
>equivalent to their original full pathnames, but with '/' replaced by '\'.
>Thus file '/usr/tmp/abc' would (assuming directory /.trash exists) be renamed
>as '/.trash/usr\tmp\abc'.
>The /var/.trash directory can of course be a symbolic link to another
>directory on another filesystem, since it is only copied-to.
>
>NOTE:  if symbolic links are specified, it is the link that is renamed, not the
>the underlying file. However, if the link cannot be renamed (across filesystems)
>it is simply deleted as the underlying file still exists and there is no point
>in copying the data.
>
>Multiple files can be 'deleted', eg:  rms  a b c   or  rms * .
>Directories CANNOT be 'deleted'.
>*/
>
>
>********************************************************************************
>This E-Mail and any files transmitted  with it, are confidential
>and intended solely for the use of the individual or entity to
>whom they are addressed. If you have received this message
>in error please notify the sender and delete the message.
>
>  
>
Why not add secure deleting to regular 'rm', have rm and rms* to do 
pretend delete and real delete respectively.

*not sure if rms or rs would be better.

Ashley
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list