The shred Command

Jan 29 2026

What is the shred Command?

The shred command is a powerful Linux utility used to securely delete files by overwriting them multiple times with random data. This ensures that the contents of the file cannot be recovered by data recovery tools or forensic analysis.

Why Use shred?

How to Use the shred Command

Basic Syntax: shred [options] [file...]

Option Description
-n Number of times to overwrite the file (default: 5)
-z Add a final overwrite with zeros (useful for hiding the file size)
-u Remove the file after overwriting
-v Verbose mode (shows progress)
-e Specify the erase method (e.g., --random for random data)
Examples of Using shred
  1. Securely Delete a File
    shred -v sensitive_data.txt
    This command will securely delete the file sensitive_data.txt by overwriting it 5 times.
  2. Overwrite a File 10 Times
    shred -n 10 -v secret_credentials.txt
    This command overwrites the file secret_credentials.txt 10 times with random data.
  3. Delete and Remove the File
    shred -u -v important_report.txt
    This command overwrites the file and then removes it from the file system, making it impossible to recover.
  4. Securely Delete a Directory
    shred -r -v /path/to/directory
    The -r option tells shred to recursively delete all files and subdirectories within the specified directory.
  5. Add Final Zero Overwrite
    shred -z -v confidential_log.txt
    This command overwrites the file with random data and then fills it with zeros, hiding the file size.
When to Use shred
Use Case When to Use shred
Delete sensitive files Always
Erase data from a drive Before selling or disposing of a drive
Securely erase logs After logging sensitive information
Comply with data protection laws GDPR, HIPAA, etc.
Don’t Use rm for Sensitive Data

The rm command only deletes the file entry in the file system. The actual data remains on the disk until it's overwritten. So, for sensitive data, always use shred instead.

Further Reading
Final Tips