#! /bin/bash # # A simple shell script for secure and relative fast delete; a replacement for rm, # similar to srm (see "secure rm" on sourceforge.net). # Because of saveral bugs and not implemented features, srm and this script can't # be used to replace rm. # This script overrites the file(s) with random bytes, sets the file length to # zero, renames it and then deletes the empty file. # The bottleneck is /dev/urandom with a speed of about 3 MByte/s. # It does not make sense to execute this script in another partition. # # Successfully tested with undelete tools like Undelete PLUS. # # TODO: Version which works with special signs like newline in the file # name and which converts the file names with their absolute path # because otherwise find can read them as options if they have the same name. # # License: GPL # # rolf dot freitag at email.de 2000, 2007 # Version 2.2, 2010 # for debugging #set -x # Return a random filename (including the path) by appending a random number # and recurse in case of a collision. So this script should only run in the same partition. function gettmpfilename() { #local tmpfile="$1"$RANDOM #tmpfile="$1"$RANDOM tmpfile=$RANDOM if [ -e "$tmpfile" ] then # if file already exists, recurse and try again tmpfile=$(gettmpfilename "$1") fi } # main for file in "$@" do # make the file writable for the user # chmod u+w "$file" typeset -i size=`find "$file" -printf "%s"` || continue # overrite all $size > 0 bytes of the file if [ $size -gt 0 ] then ddrescue --max-size=$size /dev/urandom "$file" # for a version without ddrescue: #dd bs=1 count=$size if=/dev/urandom of="$file" # flush all buffers via sync !!! sync fi # set size to 0; see also "Unix Power Tools" > "$file" # flush all buffers via sync !!! sync # rename gettmpfilename "$file" mv "$file" "$tmpfile" # flush all buffers via sync !!! sync unlink "$tmpfile" # flush all buffers via sync !!! sync done exit 0