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.
Here at Ibmi Media, we shall look into the shred command's workings, limitations, and various ways to use them to dispose of files securely on Ubuntu 20.04.
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.
More About shred
You can run the following command and see what else the shred utility has to offer:
$ shred –help
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.
What is the Syntax of the shred Command ?
The basic syntax of the shred command is given below:
$ 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.
1. How to 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.
2. 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.
3. 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.
4. 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
5. 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
6. 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.
[Need help in fixing Linux system issues ? We can help you. ]