How to Securely Erase Files on Linux

To securely wipe (shred) files on a Linux system simply change directories (cd) to the directory you would like to wipe then run:

$>find -type f -execdir shred -u '{}' \;
$>rm -rf *

This is explained as:

1. $>find -type f -execdir shred -u ‘{}’ \;

The find command itself is used to find files matching a certain expression, on a certain path. We have ommited the path argument, so find starts the search from the default current working directory. The next argument to find, -type f, tells find to match only regular files (as we can’t shred directories). The -execdir argument tells find to execute the command following the argument on each file matched (from that file’s parent directory).  The remaining arguments are taken as the command to execute, until a terminating ‘;’ character is encountered.

2. $>rm -rf *

After executing the first command, all files in the directory tree have been securely shredded and removed, and all that is left is a tree of empty directories. Since the directories themselves contain no sensitive information (they are just a list of names and i-node numbers), they can be safely removed with rm. To recursively (-r) remove all the directories without prompt (-f), since I knew all sensitive files to have been securely removed already.