I have a firm supplied laptop that I'm going to return because I'm switching job. I'm having backups and deleting personal data from it, but just to be sure I developed this small app that fills all disk space with random sequences of different length, so that deleted data is actually overwritten. It then removes the files it created. A random number of files is created in order to overwrite unused directory buckets (note: this will likely trash your filesystem). Don't forget to clean up all your files before running it. On Win32 machines, you'd better also clean your browser cache and empty your recycle bin before running it. This is a hack, so no warranty whatsoever - use it at your own risk.
Use: launch the script passing the name of a directory where temporary files will be stored.
If you interrupt it for any reason, don't forget to delete the files it created.
use strict;
my $fp = $ARGV[0] or die "use: cleandisk path\nA path is mandatory";
my $nf = 0;
print "Filling with random data your entire hard disk.\n";
my $randomDataCacheLength = 50000;
my $randomDataCache = load_rdc( $randomDataCacheLength );
my @filesWritten;
my $noError = 1;
while ( $noError ) {
eval {
my $filename = $fp . '/xx___FILLER____' . $nf++ . '.txt';
push @filesWritten, $filename;
open F, ">$filename" or die "Disk Full";
print F substr( $randomDataCache, rand( $randomDataCacheLength
+ ) );
close F;
if ( $nf % 50 == 0 ) {
print "Writing ${nf}th entry\n";
}
};
if ($@) { print "$@\n"; $noError = 0; };
}
print "Now removing random data...\n";
map {unlink $_; } @filesWritten;
sub load_rdc {
my $c_max = shift;
my $s = "";
for ( my $c = 0; $c < $c_max; $c++ ) {
$s .= chr rand( 20 ) + 65;
}
return $s;
}
To have a rough idea of the time it takes, this thing filled up circa 500 mb of empty space on my Pentium II - 450 (IDE) I'm using now in say 4-5 minutes and created 18,700 files.
I'd launch it repeatedly in order to play it extra safe.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.