Deleting files permanently on FreeBSD with (g)shred

Linux boxes usually include a utility shred that can be used to repeatedly overwrite files on a disk, ensuring that they are irrecoverable.

On FreeBSD, the shred utility is included in the GNU coreutils port.

To install from package,

% pkg install coreutils

or from ports,

% cd /usr/ports/sysutils/coreutils && make install clean && rehash

This port installs the GNU rendition of a selection of familiar *nix tools (cp, dd, pwd, stat, touch, uniq to name but a few). On FreeBSD, these GNU tools are prepended with a ‘g’ (for GNU) to prevent clashes with the native toolset, so shred is known as gshred, GNU stat is known as gstat etc. Likewise, the man pages are invoked with the g- version of the utility name (example, % man guniq).

Once installed, use this utility to permanently delete files.

To permanently remove a single file:

% gshred -f -n 5 -u -z -v <filename>

-f forces the issue, that is, change permissions as necessary to permit writing
-n specifies the number of times the file is to be overwritten, default value is 3  (**see note below)
-u to truncate the file after overwriting
-z overwrite the file with a string of zeroes after deleting in order to mask shredding
-v give verbose output

If you want to delete all files within a directory, cd to the directory and:

% find . -type f -exec gshred -f -n 5 -u -z -v '{}' \; ;

** NB – If your files are located on an SSD, n shouldn’t be set high. It’s possible that extra unnecessary write cycles can contribute to knocking the stuffing out of SSDs.

Be the first to comment

Leave a Reply

Your email address will not be published.


*