Ubuntu

Delete and Dispose of Files Properly in Ubuntu With Shred.

Delete and Dispose of Files Properly in Ubuntu With Shred

Introduction

Usually, when a file is deleted on your computer, the system only deletes the file’s reference. The file remains intact for an indefinite time in your system memory.

Anyone can retrieve these files with file recovery programs and see the deleted data from your storage. It’s a serious risk if the files contain your private and sensitive information. So how can you erase your files permanently on Ubuntu?

This is when the shred tool comes in handy. This article will go over the shred command’s workings, limitations, and various ways to use them to dispose of files securely.

How Does shred Work?

Shred is a command-line tool that repeatedly overwrites a file’s original content with zeros. In this way, the original contents of any file get replaced by zeros, so the original data cannot be recovered even if the file is restored. The file can then be securely removed from system storage.

Limitations of the shred Command

The Shred utility does not work on journaled, RAID-based, or compressed file systems. It also does not work on the multiple Network File Systems (NFS). You can see the shred man page for more detailed information.

Given the above limitations, you should not use shred on a hard drive as overwriting can induce damage to it.

Prerequisites

Ubuntu or any other Linux-based distribution

Terminal access

Basic Syntax of the shred Command

The basic syntax of the shred command is as follows:

shred options filename

Where filename is the full path of the file you want to delete, And options are flags used to run different methods provided by the command.

Permanently Delete a File With shred

Run the following command to delete a file permanently.

shred -uvz text.txt

Option -u will delete the file, the -v option will display all the processes in the command console, and the -z option will overwrite the file’s content.

Delete/Overwrite File Content With shred

If you do not want to delete a file and only want to remove the contents of the file, you can run the following command.

shred -vz text.txt

Open the targeted file and you will see the file’s content is replaced with strings of zeros.

Overwrite File Content Multiple Times With shred

You can overwrite a file multiple times to ensure that the data is replaced. Just specify the number of times you want to overwrite a file with the -n option. Keep in mind that shred utility will always do an extra overwrite.

shred -uvz -n 3 text.txt

You can see the overwrite is done four times in the output.

Permanently Delete Multiple Files With shred

You can also delete multiple files with shred. Just mention multiple filenames in the command.

shred -uvz test1.txt test2.txt

Delete Files With Specific Formats

You can also delete by their specific formats. Run the following command to delete all the text files in the folder.

shred -uvz *.txt

Overwrite Part of a File With shred

Shred lets you do partial overwriting too. The command below will overwrite the one kilobyte of the file.

shred -vz -s 1K test3.txt

You can see that part of the file has been overwritten.

More About shred

You can run the following command and see what else the shred utility has to offer.

shred –help

Conclusion

The default method for deleting files and folders in Ubuntu is really simple and easy, but it is neither permanent nor secure. Your files can be recovered and leaked with the help of data recovery software.

Shred combats this issue by overwriting the file content with random data before deleting the file. In this tutorial, you have learned how to permanently delete files in Ubuntu using the shred utility.

Similar Posts