msgbartop
MAC OS X, Linux, Windows and other IT Tips and Tricks
msgbarbottom

29 Jan 16 Recursively delete files securely: shredding

Description:
Every administrator should know that when we delete a file on the hard disk, almost nothing is really deleted. The space used by the files is simply put back on the list of ‘free to use‘ space in the filesystem and will no more appear in the directory listing. This means forensic tools can be used to retrieve these ‘deleted‘ files if the space they were using hasn’t been overwritten by newly written files.

In order to prevent this the best method is to overwrite the files to be deleted many times (10 times should do)before they get deleted. That is the job of the tool ‘shred‘ which is used in this following bash script: rec_shred.sh

Script content: rec_shred.sh
#!/bin/bash
# Purpose: SHREDS files recursively
# Use: rec_shred.sh /dir/to/shred/
if [ $# -ne 1 ]; then
echo "ERROR: The script needs one and only one argument"
exit 1
fi
# Verify if the given path is valid
if [ -d $1 ]; then
cd $1/
# Shred the files
find . -type f | while read file ; do
shred --remove --zero -n 10 $file
done
else
echo "ERROR: The given directory $1 does not exist. Exitting."
exit 2
fi

NOTE:
This script will shred the files only and leave all sub-directories empty for you to verify and delete with the command:
rm -rf /directory/

Happy shredding 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: