2012-01-28 63 views
-4

恢复我的损坏的硬盘后,我有很多“坏”文件。使用bash脚本删除损坏的文件

我需要的脚本在bash这有助于我删除喜欢

  • 零字节坏文件只包含(00 00 00 00 00 ...)
+0

你可以用'CMP文件名的/ dev/zero'。如果文件由全部空字节组成,“EOF”将包含在stderr的输出中,如果有任何非空字节,“differ”将包含在输出到stderr的输出中(基于GNU'cmp')。 – 2012-01-28 17:08:12

回答

0
find . -type f -size 0c -maxdepth 1 -exec rm {} \; 

这个怎么样?

+0

找到。 -type f -size 0 -exec rm {} \; | awk'{print $ 8}' - 删除零大小的文件,并且没问题。怎么样检测零字节填充的文件? – vinnitu 2012-01-28 10:42:21

+0

不应该是'rm \ {\}'?或者也许这是一个'zsh'的东西...... – Borealid 2012-01-28 21:14:39

+0

@Borealid它在bash中正常工作。 – 2012-01-28 21:20:55

1

这是更好地使用find

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

除了填充空值的文件不为空。另请参阅'-exec'和'-delete'。 – 2012-01-28 16:58:22