如何检查文件是否只包含在Linux shell中的零? [英] How to check if a file contains only zeros in a Linux shell?
本文介绍了如何检查文件是否只包含在Linux shell中的零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Linux下使用shell命令检查一个大文件是否只包含零字节('\0'
)?我可以为此编写一个小程序,但这似乎是一个矫枉过正的问题。 解决方案
如果你使用bash,你可以如果找到了非code> NUL 字符,请使用 read -n 1
来提前退出:
< your_file tr -d'\0'|阅读-n 1 ||回声全零。
其中 your_file
。
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 overkill.
解决方案
If you're using bash, you can use read -n 1
to exit early if a non-NUL
character has been found:
<your_file tr -d '\0' | read -n 1 || echo "All zeroes."
where you substitute the actual filename for your_file
.
这篇关于如何检查文件是否只包含在Linux shell中的零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文