Mathematics, philosophy, code, travel and everything in between. More about me…

I write about

English | Czech
Choose your language. I write in English, but I translate many of my articles to Czech as well. Zvolte si jazyk. Píšu anglicky, ale řadu svých článků překládám i do češtiny.

Setting Data on Fire

It’s not a secret that files are not really deleted when you tell the operating system to remove them. References to the files are removed but the data stays and can be sometimes retrieved. This can save your life when you delete something you shouldn’t have. Sometimes, however, you need to deal with data that must not see the light of the day ever again.

Whenever I need to securely wipe out a few files, shred is my good friend. It takes one or more files and overwrites them several times, leaving no trace of the original data (exceptions apply, see the manual page).

I was missing one feature in this tool – the -r, or --recursive option. You cannot run shred against a whole tree of directories and let it do its job. Because I sometimes need to do just this, I have written a convenient script called deurere (the Latin for “to burn down”).

# deurere, tr - to burn down
# Usage: deurere [--force] directory

if [ "$1" = '--force' ]; then

if [ ! -d "$1" ]; then
	echo $0: No input directory.
	exit 1

if [ $force != 1 ]; then
	echo -n "Are you sure you want to destroy '$1'? "
	read reply

	if [ "$reply" != 'yes' ]; then
		echo 'Aborted.'
		exit 2

find $1 -type f | xargs --no-run-if-empty shred --remove && rm -rf $1

Usage is straightforward:

$ ls -F
victim1/  victim2/  victim3/
$ deurere victim1
Are you sure you want to destroy 'victim1'? yes
$ deurere --force victim2
$ deurere victim3
Are you sure you want to destroy 'victim3'? no

To avoid fatal mistakes the user is required to confirm the destruction by typing the whole word “yes”. This test can be skipped by specifying the --force argument.

July 16, MMVIII — shell, Linux.