Linux shred command
shred is a command-line tool in Linux systems for securely deleting files. Unlike ordinary rm commands,shred ensures that file data cannot be recovered by overwriting the file content multiple times.
Why shred is needed
When you use an ordinary delete command in Linux:
- the file data still actually exists on the disk
- only the filesystem index is removed
- Using professional tools, these 'deleted' files can be easily recovered
shred Secure deletion is provided in the following ways:
- Overwrite the file content multiple times (3 times by default)
- Optionally truncate and delete the file after overwriting
- Prevent data recovery using professional equipment such as magnetic force microscopes
shred command syntax
Basic syntax format:
shred [选项]... 文件...
Description of common options
| Option | Description |
|---|---|
-n N |
Number of overwrites (default is 3) |
-z |
Finally overwrite with zeros to hide the shred operation |
-u |
Truncate and delete the file after overwriting |
-v |
Display detailed operation progress |
-f |
Force permission changes when necessary to allow writing |
-x |
Do not process blocks larger than the file size |
Usage examples
Basic usage: Securely overwrite a file
shred -v document.txt
This command will:
- Overwrite document.txt 3 times (default)
- Display detailed operation progress (-v option)
- The file still exists, but its content has been destroyed
Delete the file after overwriting
shred -u -v secret-file.txt
This command will:
- Overwrite the content of secret-file.txt
- Automatically delete the file when done (-u option)
- Display operation details (-v option)
Custom number of overwrites
shred -n 10 -v -z data.db
This command will:
- Overwrite data.db 10 times (-n 10)
- Finally overwrite with zeros to hide shred traces (-z)
- Display detailed process (-v)
Notes
-
Solid-state drive (SSD) limitations:
-
File system limitations:
-
Performance considerations:
-
Recovery possibilities:
Advanced usage
Overwrite the entire device
shred -v -n 1 /dev/sdX
Warning: This will overwrite all data on the entire device; be sure to confirm the device path is correct!
Random source selection
shred --random-source=/dev/urandom -v file.txt
Use a specified random source for overwriting (default is /dev/urandom)
Alternatives
If shred is unavailable, consider the following alternatives:
-
Use the dd command:
dd if=/dev/zero of=file.txt bs=1M count=10
-
Use the wipe command:
wipe -r -q secret-file.txt
-
Secure deletion toolkit:
secure-delete 工具包中的 srm 命令
Summary
shred The command is an important tool in Linux for protecting sensitive data, ensuring files cannot be recovered through multiple overwrites. When using it, pay attention to the storage medium type and filesystem characteristics; for the highest security needs, consider combining encryption and physical destruction methods.

Remember: there is no 100% secure data deletion method; critical data should be protected with a multi-layered strategy.
Linux Command Reference