How to Securely Wipe Free Disk Space in Ubuntu Using the sfill Command

Why Securely Wipe Free Disk Space?

When you delete a file in Ubuntu (or any modern operating system), the file’s contents are not immediately removed from the physical storage drive. Instead, the operating system simply removes the pointer to the file and marks the space it occupied as “free” and available for new data. Until new data overwrites those specific blocks, the original file data remains on the drive and can potentially be recovered using forensic software. If you are preparing to sell a computer, dispose of a hard drive, or simply want to ensure sensitive deleted files are permanently destroyed, you must securely wipe the free space.

Installing the secure-delete Package

To securely wipe free space, we will use a tool called sfill, which is part of the secure-delete package. This utility overwrites the free space on your partition with random data and zeros, making recovery virtually impossible.

  1. Open your Terminal application.
  2. Update your package lists to ensure you install the latest version:
  3. sudo apt update
  4. Install the secure-delete package by running the following command:
    sudo apt install secure-delete
  5. Enter your password when prompted and press Y to confirm the installation.

How to Use sfill to Wipe Free Space

The sfill command requires you to specify the mount point of the partition you want to wipe. Most commonly, you will want to wipe the root partition (/).

Warning: The wiping process can take a significant amount of time depending on the size of the free space and the speed of your drive. It is recommended to close unnecessary applications while this runs.

  1. To begin a secure wipe of the root partition, use the following command:
    sudo sfill /
  2. If you want to wipe a different partition, replace / with the appropriate mount point, such as /home or /media/external_drive.

Understanding sfill Options for Faster Wiping

By default, sfill uses an extremely secure 38-pass wiping method. While this guarantees data destruction, it is incredibly slow and generally unnecessary for modern drives. You can use flags to speed up the process.

  • -l (Lowercase L): This option reduces the security to two passes (one pass of random data, one pass of zeros). This is significantly faster and still highly secure for most users. Command: sudo sfill -l /
  • -ll (Double Lowercase L): This reduces the security to a single pass of random data. Command: sudo sfill -ll /
  • -z: This tells sfill to wipe the free space with zeros instead of random data on the final pass. Command: sudo sfill -lz /
  • -v: This enables verbose mode, providing you with progress updates in the terminal so you know the command is actively working. Command: sudo sfill -lv /

Important Considerations for SSDs

If your computer uses a Solid State Drive (SSD), you should exercise extreme caution when using tools like sfill. SSDs use wear-leveling algorithms, and excessively overwriting free space can prematurely degrade the drive’s lifespan. Furthermore, modern SSDs often have built-in TRIM commands that automatically clear deleted blocks, making tools like sfill largely redundant. Only use sfill on an SSD if you are preparing to dispose of it and cannot use the manufacturer’s secure erase utility.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.