The Linux shred command is a tool for securely deleting files that cannot be recovered. So unlike other commands like the rm command, which only essentially removes a file’s reference from the filesystem, shred just overwrites the file’s data multiple times before deleting it. This means that it is much harder for recovery tools to retrieve the original content.
So whether you are removing sensitive data like documents, personal information, or even confidential business files, Linux shred command adds an extra layer of protection by ensuring that the files are deleted completely, like they are gone.
In this guide, we will walk through the Linux shred command, the syntax and examples.
Why Use shred Instead of Regular Delete?
When you delete a file using rm, Linux would only remove the pointer to the file data, but it does completely erase the data itself. This usually means that the file can be easily recovered using the data recovery tools. The Linux shred command, however, overwrites the file’s content with some random data before deleting it. This makes it almost impossible to recover data, which is mainly crucial for sensitive user information, like passcodes, financial records, or private documents.
Syntax of the shred Command
shred [OPTION]… FILE…
- OPTION – Flags that control how shred behaves (e.g., number of overwrites, whether to delete, etc.).
- FILE – The name of the file you want to securely delete.
Example:
Get exclusive access to all things tech-savvy, and be the first to receive
the latest updates directly in your inbox.
shred -u -n 5 secrets.txt
This overwrites secrets.txt 5 times and then deletes it.
Common shred Options and Their Usage
Some of the most common options in the Linux shred command are:
- -n (Number of overwrites)
This shred option allows you to specify the number of times the file should be overwritten. More passes would make data recovery even more harder and might also take longer. For example:
shred -n 5 secret.txt
This overwrites secret.txt five times but does not delete it.
- -u (Overwrite and remove)
Use the -u flag to overwrite the file and then delete it immediately afterward. For example:
shred -u confidential.doc
This securely deletes confidential.doc so it cannot be recovered.
- -z (Final overwrite with zeros)
This adds a final overwrite with zeros, which helps hide the fact that shredding was done. For example:

shred -n 3 -z sensitive.csv
This overwrites sensitive.csv three times, ends with a zero, and leaves the file intact unless the -u is also used.
- -v (Verbose mode)
The Verbose mode enables detailed output so that you can see the shredding progress in real time. For example:
shred -v -n 2 report.pdf
This overwrites report.pdf twice and displays the progress on screen.
- -f (Force permissions change)
If the file is write-protected, this option might face permission changes to allow overwriting. For example:
shred -f -u old_data.txt
This changes permissions if necessary, overwrites old_data.txt, and then deletes it.
How to Use shred: Step-by-Step Examples
Shredding a single file (overwrite, do NOT delete)
Use the command:
shred -v secret.txt
- -v = verbose (shows progress).
- By default shred overwrites the file 3 times with random data.
- After this, the file still exists (same name, same size) but its content is overwritten.
Overwriting multiple times (more passes for extra security)
Run the command:
shred -n 5 -v secret.txt
- -n 5 = overwrite 5 times instead of the default 3.
- Use higher counts (e.g., -n 7) only if you really need extra passes — it takes longer.
Shredding without deleting the file (explicit)
Use the command:
shred -n 5 -v secret.txt
The file will remain as it is on the disk and only the content will be replaced. It is useful if you want to keep the filename or size but remove the old content.
Shredding and removing the file permanently
Run the command:
shred -u -z -v secret.txt
A combination of -u and -z will remove the file after overwriting and add a final layer of zero over it. A typical safe combo: shred -n 3 -z -u -v filename (3 random passes, then zeros, then delete).
If the file is write-protected, run as root or use sudo:
sudo shred -f -u -z -v secret.txt
-f helps when the file is read-only.
Shredding many files (wildcard)
Run the command:
shred -u -z -v *.log
Shreds and removes every .log file in the current folder.
Shredding files inside a directory (recursive)
Run the command:
find /path/to/dir -type f -exec shred -u -z -v {} \;
rm -rf /path/to/dir
- find runs shred on every regular file.
- Be very careful — this is destructive.
Shredding an Entire Device or Partition (with Caution)
If you want to shred an entire device or partition, run the command:
sudo shred -n 3 -v /dev/sdb
- -n 3 → overwrite 3 times
- -v → show progress
- /dev/sdb → the target drive or partition (replace with the correct device)
This command, however, cannot be reversed, therefore, proceed with extreme caution.
Limitations of Linux shred Command
Limitation | Description |
File System Type | On journaling file systems (e.g., ext3, ext4, XFS), the actual data location may not be overwritten, leaving traces recoverable. |
Solid-State Drives (SSDs) | Due to wear-leveling, data may be written to different physical locations, making it harder to guarantee secure deletion. |
Network File Systems (NFS) | Data deletion is handled by the remote server, so shred can’t ensure complete overwriting. |
Snapshots & Backups | Even after shredding, copies may still exist in snapshots or backup systems. |
Metadata Exposure | shred removes file content but does not erase metadata like file names, sizes, or timestamps. |
Safety Tips When Using Linux shred Command
Always be super careful while using the Linux shred command since it is irreversible in most cases.
- Double check the file or the device name before executing a task.
- Use ls or fdisk -l to verify the target path.
- Do not use system partitions unless booted from a live USB device.
- For sensitive data, combine the Linux shred command with a full-disk encryption from the start.
Alternative Secure Deletion Tools on Linux
Some other disk deletion tools on Linux are:
- wipe: it is optimised for various filesystems.
- srm: Part of the secure-delete package, uses DoD standards for overwriting.
- dd: it can overwrite a device with random data, for example: sudo dd if=/dev/urandom of=/dev/sdb bs=4M status=progress
- blkdiscard – For SSDs, sends a TRIM command to discard all blocks.
Conclusion
The Linux shred command is one of the most powerful tools for securely deleting files and preventing sensitive data from being recovered. Combine shred with secure deletion practices or encryption methods to enhance security.