首页·终端命令

shred

文件与目录

用法

shred -u [file]

删除前先覆写内容让它难以恢复,但在 SSD 和 btrfs、APFS 这类写时复制文件系统上旧块可能还在,真正的办法是整盘加密。

常用选项

选项含义
-uRemove the file after overwriting it
-nHow many overwrite passes; the default is 3
-zFinish with one pass of zeros so the shredding is not obvious
-vShow the progress of each pass
-sShred only the first N bytes

示例

shred -uvz secret.key

Overwrites, zeroes and then deletes.

sudo shred -vn 1 /dev/sdb

One pass over a whole disk.

rm -P secret.key

The nearest thing macOS ships.

移动、删除和查找。有些命令不会再问一遍,所以顺手加 -i 是在救自己。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. shred 是做什么的?

删除前先覆写内容让它难以恢复,但在 SSD 和 btrfs、APFS 这类写时复制文件系统上旧块可能还在,真正的办法是整盘加密。

Q. 怎么写?

shred -u [file] —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 5 个,完整列表在 man shred。这条命令属于文件与目录。

相关命令

man 手册: man shred