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:

Script content:
# Purpose: SHREDS files recursively
# Use: /dir/to/shred/
if [ $# -ne 1 ]; then
echo "ERROR: The script needs one and only one argument"
exit 1
# 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
echo "ERROR: The given directory $1 does not exist. Exitting."
exit 2

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 🙂