in reply to Re^2: Secure delete ie shred a file
in thread Secure delete ie shred a file

Here's some untested code for you. The intention is to first figure out how much crap we need to overwrite the file with, then open the file in read/write mode - this avoids clobbering the file and creating a new one which would happen if we just opened the file for writing, and also means that we can get at the beginning of the file unlike if we opened it for appending. Then it just overwrites the file with 'X's. Finally, it closes the file and unlinks it.

This will certainly protect you from "undelete" on DOS (all it will undelete is a file of 'X's) and DOS-a-likes such as Win95, and probably on WinNT and its successors if using the FAT filesystem. My understanding of ext2 leads me to believe that it should also protect you on most Linux systems. But I can't be sure that it will work anywhere else, including on Linux systems using stuff like Reiserfs, and as other people have pointed out, it certainly won't protect you against The Man. And even that paper is now out of date.

my $bytes = -s $filename open(FILE, '+<', $filename); seek(FILE, 0, 0); print FILE "X" x $bytes; close(FILE); unlink $filename;

Replies are listed 'Best First'.
Re^4: Secure delete ie shred a file
by DrHyde (Prior) on Jan 29, 2006 at 16:43 UTC