This article is a detailed guide to securely erase a disk and file via the Linux shred command.
How to Securely Erase File using the Linux shred Command
In Linux, there are multiple commands for removing the files including rm and rmdir. However, the shred command is a different one that overwrites the files and makes them unrecoverable. The basic syntax of the shred command is given below:
If you just want to overwrite the test file, execute the following command:
If you want to remove the file then, use the -uvz flag with the shred command and name of the file, -u will remove the file after overwriting, the -v shows the progress and -z performs the overwriting:
In the below example, I am removing the document1 from my system:
By default, the shred command overwrites the file 3 times, you can change this behavior by using the -n with the count for overwriting the file:
Securely Erase a Disk Using the Linux shred Command
If you are selling your drive then you can remove the data from it using the shred command so that no one can access the previously deleted data from the drive. You can use the -v to get the detailed output, -f forces the overwrite, and -z writes the zeros in the final pass and removes or erases all the data from the hard disk or USB drive.
Note: Replace the /dev/sdb with the name of your device, which can be found through “lsblk” command.
shred is an important command-line tool for Linux systems as it deletes the data on the disk in a secure fashion so that no one can re-access the data from the disk. The tool is preinstalled on most Linux distributions including Debian and you can see the shred command use with different examples provides the above-mentioned guidelines.