How to check if a file contains only zeros in a Linux shell?

后端 未结 6 2076
隐瞒了意图╮
隐瞒了意图╮ 2021-01-04 07:36

How to check if a large file contains only zero bytes (\'\\0\') in Linux using a shell command? I can write a small program for this but this seems to be an ov

6条回答
  •  温柔的废话
    2021-01-04 07:54

    The "file" /dev/zero returns a sequence of zero bytes on read, so a cmp file /dev/zero should give essentially what you want (reporting the first different byte just beyond the length of file).

提交回复
热议问题