Janna Theme License is not validated, go to the theme options page to validate the license, you need a single license for each domain name.

8 Ways to Securely Delete Files in Linux

We've seen how to erase the entire contents of your hard drive, but what happens if all you want to do is permanently delete one, two, or twelve files? This guide shows you some of the most common solutions for how to securely delete files on your hard drive. Linux.

00 Ways to Securely Delete Files in Linux
Note: Most SSDs support (SSDMost SSDs on the market today use TRIM to manage their free space, a feature in their firmware that reallocates their contents. Combined with Linux journaling file systems, such as Ext3/4 and Reiser FS, deletion after individual file recovery is not guaranteed. The only solution in these cases is, unfortunately, a complete nuclear wipe of the entire contents of the SSD.

1. Bypass the Trash

When you delete a file, it's moved to the Trash (also known as the Recycle Bin). If you want, you can bypass the Trash folder. This way, your deleted files won't remain in the Trash and will be marked as completely deleted. While they're still recoverable, it's a step further to access them (in the Trash).

01 Ways to Securely Delete Files in Linux

To delete files in Linux distro Like Kubuntu with KDE, launch the default file manager, Dolphin. Click Menu -> Configuration -> Dolphin Configuration -> Trash To access the relevant preferences. There's no option to disable the trash completely, but you can use a neat trick that covers most bases: enable the size limit and reduce it to the smallest value.

02 Ways to Securely Delete Files in Linux

On our disk, this translated to 10.97 MB. Dolphin will erase the contents of the Recycle Bin when it exceeds this value, which will likely occur every other hour using a regular desktop. Other file managers, such as Nautilus or Nemo, have options to bypass the Recycle Bin entirely.

03 Ways to Securely Delete Files in Linux

Pros

  • easy to do
  • Gives you a grace period before permanently deleting files.

Negatives

  • Does not remove any metadata remaining on the disk.
  • Do not clean data from files.

2. Use shred

If you're using a different version of Ubuntu, shred is likely part of it. You can start using it right away to delete any sensitive files in Linux that you want to consign to oblivion.

If you want to delete “image.png” Finally, use:

shred -uvz -n 4 image.png
  • u shred tells you to remove the file before overwriting it.
  • v Displays extended information.
  • z fills the space occupied by data with zeros to reduce any chance of recovery.
  • -n 4 translates to five delete passes: The pass operation performs one pass by default, and with "-n" you can specify how many additional passes you need for added security. The general consensus is that five passes should be more than enough for most people.
    04 Ways to Securely Delete Files in Linux
Also read:  How to easily switch from the command prompt in Windows to the terminal in Linux

To remove multiple files or folder contents, use wildcards like:

shred -uvz -n 1 Pictures/images_0?.jpg shred -uvz -n 4 Pictures/*.*

In the first case, “?” It will be a wildcard for a single character, and the fragmentation will delete the named files. “images_01.jpg” و “images_02.jpg” , For example.

In the second case, the shredding process will erase all files in the directory. "Pictures" , regardless of its name or type.

Pros

  • One file will be completely deleted.
  • A glob match can be performed to cover multiple files.

Negatives

  • Some option tags are ambiguous.
  • It will take a long time to finish.

3. Using dd in individual files

Data Definition (dd) is another utility found in almost every Linux distribution today. However, unlike shred, one of dd's biggest advantages is that it allows you to customize how your files are deleted in Linux.

To use dd, you need to know the exact size of your file in bytes:

ls -l /path/to/your/file | awk '{print $5}'

05 Ways to Securely Delete Files in Linux

You can run dd on your current file. For example, this command will fill your file with blank characters:

dd status=progress bs=your_file_size count=1 if=/dev/zero of=/path/to/your/file

06 Ways to Securely Delete Files in Linux

Aside from filling your file with empty characters, you can also force dd to clear your file with pseudo-random data:

dd status=progress bs=your_file_size count=1 if=/dev/urandom of=/path/to/your/file

07 Ways to Securely Delete Files in Linux

You can now delete your file using the regular rm command:

rm /path/to/your/file

Pros

  • Versatile – It can do more than just delete files
  • File deletion can be set.

Negatives

  • The syntax is outdated, even for a command line program.
  • Requires a good understanding of block sizes.

4. Use wipe

Wipe is another excellent alternative. Find it in your distribution's software center and install it from there, or use:

sudo apt install wipe

08 Ways to Securely Delete Files in Linux

Using it is as simple as shredding, if not more so. To delete files in Linux using Wipe, run:

wipe Pictures/deleteme.png

This can be annoying, as scanning, by default, uses multiple, time-consuming passes to provide added security. Additionally, it will ask for confirmation of deletion.

Also read:  Understanding BSD and How It Differs from Linux in Operating Systems

09 Ways to Securely Delete Files in Linux

Use the f flag to remove the assertion and r to refer to subdirectories. c tells chmod to scan if necessary (when a file or directory doesn't have certain write permissions), and q allows you to reduce the number of passes for faster deletion. When using q, note that it is lowercase. It can be followed by a letter "Q" Large specifies the number of passes you require. For example, the previously simple command, with these modifications applied, would change to:

wipe -rfcq -Q 5 Pictures/deleteme.png

Pros

  • Easy to use, even with little command line experience.
  • Reasonable and safe default parameters

Negatives

  • The default parameters may be too strict for most users.
  • May not work well with active magazines.

5. Use secure deletion

SRM is one of the tools in the Secure Delete suite, which specializes in securely removing data from hard drives. Many consider it the best tool for this job.

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

sudo apt install secure-delete

10 Ways to Securely Delete Files in Linux

After that, you can delete any file using:

srm Pictures/deleteme.png

11 Ways to Securely Delete Files in Linux

You may want to use the z flag, which replaces the contents of your file with zeros, for added security, and the v flag for verbose information about the operation. If dealing with directories and subdirectories, also include the r flag for recursive mode. If 38 rewrites are too large for you, you can reduce the time required—as well as security—by using the l flag to reduce the number of passes to two. "only". This will convert the previous command to:

srm -rlvz Pictures/deleteme.png

Pros

  • The options are easy to understand and intuitive.
  • Deleting a file is very safe and comprehensive.

Negatives

  • It will take a long time to finish.
  • Does not work well with systems that use RAID.

6. Deleting Files in Linux with Perl

Aside from using tools, you can also take advantage of simple programming languages, such as Perl, to delete files in Linux. For example, the following line of code will replace the contents of your file with the character "0":

perl -i -pe 's/[^*]/0/g' /path/to/your/file
  • The -i flag tells Perl to process the file you provide in the command.
  • The -pe flag tells the program to loop through the contents of your file.
  • 's /[^*]/0/g' is a substitution command. The [^*] operator matches every byte within the file, and the number 0 will replace every byte.

12 Ways to Securely Delete Files in Linux

Once done, you can remove the modified file using rm:

rm /path/to/your/file

Pros

  • You don't need to learn a new syntax if you know Perl.
  • Uses familiar abstractions such as sed substitution.

Negatives

  • The command will only make one pass through the file.
  • Replacing content with random data may be unsafe.

7. GUI Method: Using Bleachbit

If you have an aversion to the command line, Bleachbit is one of the best solutions for securely erasing your data. (Bleachbit is famous for its ability to clean your Linux system.) By default, the tool specializes in detecting redundant files and get rid of them, which continue to take up space long after you need them. But it also includes the often forgotten ability to "tearing" Any file manually after recovery.

Also read:  Qubes offers protection and isolation that most other Linux distributions don't.

13 Ways to Securely Delete Files in Linux

Install it on your Ubuntu-compatible distribution through its software center or using:

sudo apt install bleachbit

Click Menu -> Preferences and enable the option “Overwriting file contents to prevent recovery” To improve security.

14 Ways to Securely Delete Files in Linux

Go back to its main interface, and click on Menu -> Shred Files From the pop-up prompt, select the files you want to send to nowhere. Click "delete" Bleachbit reassures you that you are sure of what you are trying to do.

15 Ways to Securely Delete Files in Linux

You should always keep in mind that using journal filing systems and the fact that we do not know how "Manage" The firmware of each hard drive contains its contents, meaning that the best solution is to erase the entire hard drive – or even better, physically destroy the device.

Pros

  • easy to use
  • You can set it to be secure by default.

Negatives

  • Disc wipes cannot be made.
  • Free space will not be wiped.

8. Wipe free space with dd

While secure deletion will make file recovery more difficult, it's still possible to reconstruct it using the metadata on your disk. Fix this problem by clearing all available free space on your device.

The easiest way to do this in Linux is to use dd to create a file that fills the entire hard drive:

dd status=progress if=/dev/zero of=/home/$USER/wipefree

16 Ways to Securely Delete Files in Linux

Once this is done, you need to tell your system to commit the “free space” file to the disk:

sync

Finally, remove the file. "free space" Using rm:

rm /home/$USER/wipefree

16 Ways to Securely Delete Files in Linux

Pros

  • Simple command that does not remove files
  • Clear all remaining metadata

Negatives

  • takes a long time to finish
  • It does not delete files directly.

Frequently Asked Questions

Q1: Is it possible to safely delete remote files in Linux?
answer. While it is possible to securely delete remote files, there is no guarantee that a remote Linux system will not back up files on its disks. It is best to assume that not every remote system and disk is secure.

Q2: Are my files completely gone after I securely delete them in Linux?
answer. Your system may still retain some metadata from your old file. For example, the swap partition may contain information about secure deletion on your system.

Mitigate this by rebooting and creating new files on your disk.

Q3: Is it better to have more permissions when deleting files?answer. Not necessarily. In most cases, five passes should prevent any data recovery tool from recreating your file. It is possible to recover a file with more than five passes, but it requires highly specialized tools and software to work.

Go to top button