How to Completely Delete a File in Linux

Linux File Delete Featured

We saw how you can fully erase the contents of your hard disk in the past, but what happens if all you want is to delete one, two or a dozen files? Isn’t there a way to entirely remove them from your computer, beyond recovery, without having to nuke your whole HDD? The answer to this question is not only a resounding yes but also followed by a more than one! Let’s see some of the most popular solutions for complete file deletion in Linux.

Note: Ignore with SSDs

Most solid-state drives on the market today support TRIM for managing their free space, a feature in their firmware that reallocates their contents. Combined with the journaling file systems in Linux, like Ext3/4 and Reiser FS, the deletion beyond recovery of individual files can’t be guaranteed. The only solution in those cases is, unfortunately, is a full nuke of all contents in an SSD.

Bypass the trash

We saw in detail how you can pull this off in the past, but it’s worth another brief mention: if you wish, you can bypass the trash folder. This way, your deleted files won’t linger in the trash and will be marked fully gone. It won’t make their recovery impossible, but it is a step up from having them accessible.

Linux File Delete Dolphin

To do that in a distro like Kubuntu with KDE, run its default file manager, Dolphin. Click on “Control -> Preferences -> Trash” to reach the related preferences. There isn’t an option to fully disable the trash, but you can use a neat trick that covers most bases: enable the Size limit and reduce it to the smallest value.

Linux File Delete Dolphin Trash Limit

On our disk, this translated to 205.09 KiB. Dolphin will erase the contents of the trash when they exceed that value, and that would probably happen every other hour with typical desktop use. Other file managers like Nautilus or Nemo have options for you to bypass the trash completely.

Nemo Delete Bypass Trash Options

Using shred

If you’re running some variant of Ubuntu, shred is probably already a part of it. You can start using it immediately to fully erase any sensitive files you want to send to oblivion. How?

If you wanted to obliterate “deleteme.jpg,” you could use:

From the options …

  • u tells shred to first remove the file before overwriting it.
  • v displays verbose information.
  • z fills the space that was taken by the data with zeros to further reduce any chance of recovery.
  • -n 2 translates to three deletion passes – shred does one pass by default, and with “-n,” you can specify how many additional passes you require over that for extra security. The general consensus is that three passes should be more than enough for most people.
Linux File Delete Shred

To eliminate multiple files or the contents of a folder, you can use wildcards like:

In the first case, “?” would be a wildcard for a single character, and shred would delete files named “delete_those_images_01.jpg” and “delete_those_images_02.jpg,” for example.

In the second case, shred would wipe out all files in the directory Pictures, no matter their name or type.

Using wipe

Wipe is another excellent alternative. Search for it in the software center of your distribution and install it from there or use:

Linux File Delete Wipe Install

Its use is almost as simple as shred’s, if not simpler. To erase any file or directory or use wipe, use:

This can become annoying since, by default, wipe uses too many time-consuming passes for extra security. Plus, it will request confirmation for the deletion.

Linux File Delete Wipe Flags

Use the f flag to get rid of the confirmation and r to recurse into subdirectories. c tells wipe to chmod if necessary (when a file or directory has no write permissions set), and q allows you to reduce the number of passes for a quicker deletion. When using q, notice that it’s lowercase. It can be followed by a capital “Q” specifying the number of passes you demand. For example, the previously simple command, with those tweaks applied, would change to:

Using Secure Delete

SRM is one of the tools in the Secure Delete suite of tools that specializes in secure removal of data from your HDD. It’s held by many as the best tool for this job.

To install the full Secure Delete suite on Ubuntu and compatible distributions, use:

Linux File Delete Secure Delete Installation

Afterward, you’ll be able to annihilate any file with:

Linux File Delete Srm In Action

You’ll probably want to use the z flag, that overwrites your file’s contents with zeros for extra security and v to get verbose information about the process. If dealing with directories and subdirectories, also include the r flag for recursive mode. If the 38 rewrites are too much for you, you can decrease the time required – as well as the security – by utilizing the l flag to reduce the number of passes to “only” two. This would turn the previous command to:

The GUI way: using Bleachbit

If you have an aversion to the command line, Bleachbit is one of the best solutions for securely erasing your data. By default, the tool specializes in discovering and disposing “redundant files” that keep taking up space long after you’ve needed them. But it also incorporates the usually forgotten ability to manually “shred” any file beyond recovery.

Linux File Delete Bleachbit Install

You can install it on your Ubuntu-compatible distribution through its software center or by using:

Click on “Edit -> Preferences” and enable the option “Overwrite contents of files to prevent recovery” for enhanced security.

Linux File Delete Bleachbit Overwrite Contents

Go back to its main interface, click on “File -> Shred,” and from the requester that pops up, choose the files you wish to beam to nothingness. Click “Delete” and re-assure Bleachbit that you’re sure of what you’re trying to do.

Linux File Delete Bleachbit Shred

You should always keep in mind that our use of journaling file systems, and the fact we don’t know how each HDD’s firmware “manages,” for lack of a better term, its contents, means that the best solution is wiping out the full HDD – or even better, physically destroying the device.

3 comments

  1. You can bypass Trash by right clicking on the file name and selecting “Delete” from the menu. Of course, as with any delete, this only deletes the pointers to the file, not the data itself.

  2. While I love and use bleach bit, I wish it gave you the ability to set how many times you overwrite a file. Some files need more secure overwriting than others.

  3. Upon rereading the article I notice that the title says “in Linux” but all the examples are for Ubuntu. They may or may not work on other distros such as Arch, Fedora, SUSE or Gentoo.

    How about some truth in labeling? If the article is only about Ubuntu (or any other distro), don’t be shy about putting the distro name in the title. If the article is titled “…in Linux” then please let’s have some examples for distros other than Ubuntu. Even though Ubuntu-based distros may be the most popular segment of the Linux user base, there are more non-*buntu users than there Ubuntu-based users.

Leave a Comment

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.