【问题标题】:removing corrupted files using a bash script [closed]使用 bash 脚本删除损坏的文件 [关闭]
【发布时间】:2012-02-21 02:27:41
【问题描述】:

恢复损坏的硬盘后,我有很多“坏”文件。

我需要 bash 中的脚本,它可以帮助我删除坏文件,例如

  • 零字节仅包含 (00 00 00 00 00 ...)

【问题讨论】:

  • 您可以使用cmp filename /dev/zero。如果文件包含所有空字节,“EOF”将包含在输出到 stderr,如果有任何非空字节,“差异”将包含在输出到 stderr(基于 GNU cmp)。

标签: bash find grep


【解决方案1】:

最好使用find:

find -maxdepth 1 -type f -empty -print0 | xargs -0 rm -f -v

【讨论】:

  • 除非用空值填充的文件不为空。另请参阅 -exec-delete
【解决方案2】:
find . -type f -size 0c -maxdepth 1 -exec rm {} \;

这个怎么样?

【讨论】:

  • 找到 . -type f -size 0 -exec rm {} \; | awk '{ print $8 }' -- 删除零大小的文件,没关系。检测零字节填充文件怎么样?
  • 不应该是rm \{\}吗?或者这可能是zsh 的事情......
  • @Borealid 在 bash 中运行良好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-17
  • 2017-04-17
  • 2012-07-02
  • 1970-01-01
  • 2020-01-07
  • 2015-05-27
相关资源
最近更新 更多