国际访客建议访问 Primers 编程伙伴 国际版站点 > Bash 教程 > shred 以获得更好的体验。

# Bash 的 shred 命令

shred [OPTION]... FILE...

!subtitle:功能

粉碎文件数据(使用随机数据多次覆盖磁盘数据)以避免被恢复。

!subtitle:类型

可执行文件(/usr/bin/shred),属于 coreutils

!subtitle:参数

  • OPTION 选项:

    • -f, --force - 强制执行,如有必要,会修改文件的权限

    • -n, --iterations=N - 覆盖 N 次数据;默认为 3

    • --random-source=FILE - 从 FILE 文件获取随机数据

    • -s, --size=N - 粉碎 N 字节数据;支持 K M G 等单位后缀

    • -u - 粉碎后删除文件

    • --remove[=HOW] - 粉碎后删除文件,并指定怎样删除目录

      • unlink - 使用标准的 unlink 调用

      • wipe - 并且首先对名称中的字节进行混淆

      • wipesync - 并且将混淆后的字节同步到设备(默认)

    • -v, --verbose - 显示进度

    • -x, --exact - 不要将文件大小向上取整到一个标准块;对于非普通文件默认开启

    • -z, --zero - 最后额外使用全零覆盖一次

    • --help - 显示帮助

    • --version - 显示版本

  • FILE - 文件列表

# 示例

$ shred 1.txt               # 覆盖 1.txt 的数据 3 次(默认)
$ shred -n 10 -z 1.txt      # 覆盖 1.txt 的数据 10 次,然后用全零额外覆盖一次
$ shred -u 1.txt            # 覆盖 1.txt 的数据,然后将其删除

# 相关命令

命令 说明
rm 删除文件
rmdir 删除目录
unlink 删除文件

# 推荐阅读

# 手册

SHRED(1)                         User Commands                        SHRED(1)

NAME
       shred - overwrite a file to hide its contents, and optionally delete it

SYNOPSIS
       shred [OPTION]... FILE...

DESCRIPTION
       Overwrite  the specified FILE(s) repeatedly, in order to make it harder
       for even very expensive hardware probing to recover the data.

       If FILE is -, shred standard output.

       Mandatory arguments to long options are  mandatory  for  short  options
       too.

       -f, --force
              change permissions to allow writing if necessary

       -n, --iterations=N
              overwrite N times instead of the default (3)

       --random-source=FILE
              get random bytes from FILE

       -s, --size=N
              shred this many bytes (suffixes like K, M, G accepted)

       -u     deallocate and remove file after overwriting

       --remove[=HOW]
              like -u but give control on HOW to delete;  See below

       -v, --verbose
              show progress

       -x, --exact
              do not round file sizes up to the next full block;

              this is the default for non-regular files

       -z, --zero
              add a final overwrite with zeros to hide shredding

       --help display this help and exit

       --version
              output version information and exit

       Delete  FILE(s)  if  --remove (-u) is specified.  The default is not to
       remove the files because it is common to operate on device  files  like
       /dev/hda,  and those files usually should not be removed.  The optional
       HOW parameter indicates how to remove a directory  entry:  'unlink'  =>
       use  a  standard  unlink call.  'wipe' => also first obfuscate bytes in
       the name.  'wipesync' => also sync each obfuscated byte to the  device.
       The default mode is 'wipesync', but note it can be expensive.

       CAUTION:  shred  assumes the file system and hardware overwrite data in
       place.  Although this is  common,  many  platforms  operate  otherwise.
       Also,  backups and mirrors may contain unremovable copies that will let
       a shredded file be recovered later.  See the GNU coreutils  manual  for
       details.

AUTHOR
       Written by Colin Plumb.

REPORTING BUGS
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
       Report any translation bugs to <https://translationproject.org/team/>

COPYRIGHT
       Copyright  ©  2023  Free Software Foundation, Inc.  License GPLv3+: GNU
       GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
       This is free software: you are free  to  change  and  redistribute  it.
       There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
       Full documentation <https://www.gnu.org/software/coreutils/shred>
       or available locally via: info '(coreutils) shred invocation'

GNU coreutils 9.4                 April 2024                          SHRED(1)
本文 更新于: 2026-03-06 09:52:34 创建于: 2026-03-06 09:52:34