If you're running a HDD in your machine, just securely erase the files you don't want them to access before handing the system over. If you're running an SSD, this may be pointless! ...
shred -uzn3 <path to your file>
or if you have a folder full of files you want to shred (this will dig into all subdirectories as well):
find <path to your folder> -type f -exec shred -uzn3 '{}' \;
Breakdown of the switches used:
- -u: truncate and remove file after overwriting
- -z: add a final overwrite with zeros to hide shredding
- -n 3: overwrite 3 times
The only way to prevent similar data recovery for files that were previously deleted would be to overwrite all of your empty disk space. If you want to do that, try the script below. Beware that this could take a long time if you have lots of free space. Also, this may not work as intended with an SSD! Place this script in your home directory and run it.
#!/bin/bash
# desc: When run, this script fills the partition on which it resides with random or
# zero-filled files. Once filled all of the files generated are removed. Thus any
# existing date in the free space is overwritten.
# WARNING: because of wear-leveling techniques used by SSDs this may not work
# as expected with SSDs and some data may remain recoverable.
useRandom=0 #using random data is MUCH slower!
[ $useRandom -eq 1 ] && readDev=/dev/urandom || readDev=/dev/zero
prefix="wipe"
# if we started and killed the script before, pick up where we left off
i=$(ls -l ${prefix}_*.filler 2> /dev/null | wc -l) || i=0
echo "Filling this filesystem. This could take a while ..."
# start an infinite loop writing 2G files to disk
while :
do
# write (another) 2G file; break loop when no space is left
dd if=$readDev of=${prefix}_$i.filler bs=4M count=512 > /dev/null 2>&1 || break
let $[i++]
# calculate values for displaying progress
completed=$(ls -l ${prefix}_*.filler | awk '{print $5}' | paste -sd+ | bc)
free=$(df -PB1 . | tail -n1 | awk '{print $4}')
percent=$(echo "scale=2; 100 / (1 + $free / $completed)" | bc)
# show progress
echo "Progress: $(numfmt --to si <<< "$completed") (${percent}%)"
done
# when no space is left, print out the 100% progress indicator and remove the zero-filled files
echo "Progress: $(ls -l ${prefix}_*.filler | awk '{print $5}' | paste -sd+ | bc | numfmt --to si) (100.00%)"
echo "Finished filling partition! Cleaning up."
rm ${prefix}_*.filler
exit