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
If you have Bash,
cmp file <(tr -dc '\000'
If you don't have Bash, the following should be POSIX (but I guess there may be legacy versions of cmp
which are not comfortable with reading standard input):
tr -dc '\000'
Perhaps more economically, assuming your grep
can read arbitrary binary data,
tr -d '\000'
I suppose you could tweak the last example even further with a dd
pipe to truncate any output from tr
after one block of data (in case there are very long sequences without newlines), or even down to one byte. Or maybe just force there to be newlines.
tr -d '\000'