October 15, 2018

How to Install shred to Permanently Delete Files on FreeBSD

FreeBSD Logo

With the Unix command shred you can securely delete files and devices by overwriting the specified files repeatedly. Recovering them after shred has deleted the files and devices is extremely difficult and needs specialised hardware. The GNU Core Utilities holds the gshred command and can be installed from the FreeBSD ports tree.

Root access is required to edit the following files and to execute commands. Log in as root (su) or simply prepend sudo to all commands that require root privileges.

Install coreutils

First you need to install the core utilities ports which holds the gshred command.

cd /usr/ports/sysutils/coreutils
make install clean; rehash

Delete a file permanently

The following command is an example to permanently delete the file access.log. Here are the options we are using:

  • -f : Change permissions to allow writing if necessary
  • -z : Add a final overwrite with zeros to hide shredding
  • -u : Truncate and remove file after overwriting
  • -v : Verbose, show progress
gshred -f -z -u -v /var/log/nginx/access.log

Delete all files from a specific directory permanently

Permanently delete all files of the current directory with the following command:

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

Speak Your Mind