FreeBSD: Permanently Delete / Remove Files With Shred

I‘m going to upgrade my FreeBSD 7.x server hard disks and going to send back the original 73GB hard disk to my vendor. I wanted to make sure that no one should able to use my personal data from old hard disk, especially files stored in /home/you/projects directory. I know how to use sDelete under MS-Windows to delete a file permanently. How do I permanently erase files under FreeBSD operating systems?

You need to install the Free Software Foundation’s core utilities ports located at /usr/ports/sysutils/coreutils directory. This ports comes with gshred command which overwrite the specified FILE(s) repeatedly, in order to make it harder for even very expensive hardware probing to recover the data.

Upgrade Ports Collections

Use your favorite tool or the following commands to get updated ports tree:
# portsnap fetch update

Install coreutils

Type the following command:
# cd /usr/ports/sysutils/coreutils
# make install clea
# rehash

How Do I Delete File Permanently?

Simply type the following command:
# gshred -f -v -z -u /path/to/file

How Do I Delete All Files Permanently From Specific Directory?

You need to use the find command as follows:
# find . -type f -exec gshred -f -v -z -u '{}' \; ;

  • -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 mode i.e. show progress

You can boot from Linux Live CD nuke disk:
# dd if=/dev/zero of=/dev/sda && dd if=/dev/urandom of=/dev/sda
Or from FreeBSD itself you can type:
dd if=/dev/null of=/dev/ad4s2 bs=8m

Erase Full Disk

Darik’s Boot and Nuke CD is highly recommended for permanently erasing full hard disk. You can grab it here.

See Also:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • kubrick Jun 25, 2010 @ 6:44

    I use a similar tool in my Debian box for delete permanently files.
    This tool is called “wipe”.
    You can install it from the repositories.
    I dont know if this tool is available in FreeBSD.

    Best regards.

    • befrenze Jan 14, 2012 @ 16:29

      Yes there is wipe:
      # cd /usr/ports/security/wipe/
      and then
      # make install

      // Benedikt

  • Vadim Ippolitov Oct 2, 2013 @ 4:24

    >dd if=/dev/null of=/dev/ad4s2 bs=8m

    it should be /dev/zero instead:

    dd if=/dev/zero of=/dev/ad4s2 bs=8m

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum