I’m giving up a server to get recycled as in sold-on-ebay or some other site, but there’s a few sensitive files I want to wipe before giving it up. The rest of the OS can stay, it’s all just open source Linux anyway.
So I just wrote this in 2 minutes so I could kill some things in /etc and /home and be done with it. Short and simple, don’t you think?
#!/bin/sh
# secure rm
if [ `echo $#` -lt "1" ]; then
echo "No file(s) specified for deletion."
exit 1
fi
for file in $@; do
if [ -w $file ] && [ ! -d $file ]; then
dd if=/dev/zero of=./$file bs=1 count=`echo $(stat -c%s "$file")`
echo "$file is now full of zeros."
fi
done
You could take it another step and calculate the data size yourself with xxd, whch counts in hex, and then convert that to base 10. There’s just one speed bump. xxd spits out hex in lowercase, but binary calculator chokes unless you provide uppercase.
echo "ibase=16;`xxd $filename | tail -1 \ sed -e 's/:.*//' -e 's/[a-z]/\U&/g'`" | bc
This will also help automating the carving out of a deleted file from a disk (deleted image recovery) which I explained in a previous post not too long ago.