When you delete a file in Linux using the standard rm command (or by dragging it to the graphical Trash bin), the file is not actually erased from your hard drive. The operating system merely deletes the index pointer that tells the computer where the file is located. The actual sensitive data—whether it is a financial spreadsheet or a private cryptographic key—remains intact on the physical disk until another program randomly overwrites it.
If you are selling an old computer, handing a server over to a new client, or simply practising good security hygiene, relying on rm is dangerous. To prevent data recovery software from restoring your sensitive documents, you must learn how to securely delete files in Linux using the shred command. This utility forcefully overwrites your data with random noise, destroying it completely.
Understanding How the Shred Command Works
The shred command is a core utility included in the GNU Coreutils package, meaning it is pre-installed on virtually every Linux distribution (Ubuntu, Debian, Fedora, Arch, etc.).
By default, when you execute shred against a file, it will overwrite the physical location of that file on the storage drive three separate times using complex, randomised patterns of data. This renders the original magnetic or digital signature entirely unreadable.
Basic Secure Deletion
To shred a file, you must use the command line.
- Open your Linux terminal.
- Navigate to the directory containing the sensitive file (e.g.,
cd ~/Documents). - Type the following command, replacing
passwords.txtwith your actual filename:
shred passwords.txt
The command will execute silently. However, there is a catch: the default command overwrites the data but does not delete the file itself from the directory. You will still see passwords.txt sitting in your folder, though if you try to open it, it will be full of garbled text.
Overwriting and Deleting Simultaneously (-u)
To make the utility behave like a secure version of the rm command—where it shreds the data and then automatically deletes the leftover file index—you must use the uppercase -u (Unlink) flag.
shred -u passwords.txt
The file is now overwritten three times, and then completely removed from your file system. It is gone forever.
Adding Verbose Output (-v)
Because securely overwriting data takes time (especially for large video files or databases), it is highly recommended to use the lowercase -v (Verbose) flag. This forces shred to print its progress to the terminal, showing you exactly which pass it is currently executing.
You can combine flags easily:
shred -vu passwords.txt
The terminal will output something similar to this:
shred: passwords.txt: pass 1/3 (random)...
shred: passwords.txt: pass 2/3 (ffffff)...
shred: passwords.txt: pass 3/3 (random)...
shred: passwords.txt: removing
shred: passwords.txt: renamed to 0000000000000
shred: passwords.txt: removed
Increasing the Number of Overwrite Passes (-n)
While the default three passes is generally considered secure enough to thwart standard data recovery software, paranoid users or those dealing with highly classified information may wish to overwrite the data more thoroughly.
You can specify the exact number of iterations using the -n flag followed by a number. For example, to overwrite a file 10 times, display the progress, and then delete the file, use:
shred -vu -n 10 top_secret_design.pdf
Important Warnings Regarding SSDs
The shred command was originally designed for traditional mechanical Hard Disk Drives (HDDs). Modern Solid State Drives (SSDs) and USB flash drives use a technology called “wear levelling” to extend their lifespan. This means that when shred attempts to overwrite the physical sector of a file, the SSD controller might secretly redirect that new data to a completely different sector, leaving the original data intact elsewhere on the chip.
For modern SSDs, the most secure deletion method is to encrypt the entire drive using LUKS/dm-crypt from the moment you install Linux. If the entire drive is encrypted, simply deleting the decryption key renders all data—including “deleted” files—permanently inaccessible.