Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux shred command

Linux shred command

Linux Command Reference Linux Command Reference


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:

  1. the file data still actually exists on the disk
  2. only the filesystem index is removed
  3. Using professional tools, these 'deleted' files can be easily recovered

shred Secure deletion is provided in the following ways:


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:

  1. Overwrite document.txt 3 times (default)
  2. Display detailed operation progress (-v option)
  3. The file still exists, but its content has been destroyed

Delete the file after overwriting

shred -u -v secret-file.txt

This command will:

  1. Overwrite the content of secret-file.txt
  2. Automatically delete the file when done (-u option)
  3. Display operation details (-v option)

Custom number of overwrites

shred -n 10 -v -z data.db

This command will:

  1. Overwrite data.db 10 times (-n 10)
  2. Finally overwrite with zeros to hide shred traces (-z)
  3. Display detailed process (-v)

Notes

  1. Solid-state drive (SSD) limitations:

  2. Due to the wear-leveling technology of SSDs, shred may not be able to completely erase data on SSDs
  3. For SSDs, it is recommended to use encryption or ATA secure erase commands
  4. - Due to the wear-leveling technology of SSDs, shred may not be able to completely erase data on SSDs - For SSDs, it is recommended to use encryption or ATA secure erase commands
    1. File system limitations:

    2. Some filesystems (such as journaling filesystems) may retain copies of old data
    3. For critical data, it is recommended to use shred on an unmounted partition
    4. - Some filesystems (such as journaling filesystems) may retain copies of old data - For critical data, it is recommended to use shred on an unmounted partition
      1. Performance considerations:

      2. Overwriting large files multiple times consumes more time and I/O resources
      3. For unimportant files, ordinary deletion may be more appropriate
      4. - Overwriting large files multiple times consumes more time and I/O resources - For unimportant files, ordinary deletion may be more appropriate
        1. Recovery possibilities:

        2. Even with shred, professional laboratories may still be able to recover some data
        3. The highest security level requires physical destruction of the storage medium
        4. - Even with shred, professional laboratories may still be able to recover some data - The highest security level requires physical destruction of the storage medium

          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:

          1. Use the dd command:

            dd if=/dev/zero of=file.txt bs=1M count=10
          2. Use the wipe command:

            wipe -r -q secret-file.txt
          3. 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 Linux Command Reference