bash 如何使用 hexdump 显示前 x 个字节?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28183957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to show the first x bytes using hexdump?
提问by OHHH
I have two files and I want to see if the first 40 bytes are similar. How can I do this using hex dump?
我有两个文件,我想看看前 40 个字节是否相似。我如何使用十六进制转储来做到这一点?
采纳答案by rici
If you are using the BSD hexdump
utility (which will also be installed as hd
, with a different default output format) then you can supply the -n40
command line parameter to limit the dump to the first 40 bytes:
如果您正在使用 BSDhexdump
实用程序(也将安装为hd
,具有不同的默认输出格式),那么您可以提供-n40
命令行参数以将转储限制为前 40 个字节:
hexdump -n40 filename
If you are using the Posix standard od
, you need a capital N
. You might find the following invocation useful:
如果您使用 Posix 标准od
,则需要大写N
。您可能会发现以下调用很有用:
od -N40 -w40 -tx1 -Ax filename
(You can do that with hexdump
, too, but the format string is more work to figure out :) ).
(你也可以用 来做到这hexdump
一点,但格式字符串需要更多的工作来弄清楚:))。
回答by Robin Hsu
Try this:
尝试这个:
head -c 40 myfile | hexdump
回答by zb'
Not sure why you need hexdump here,
不知道为什么这里需要 hexdump,
diff <(dd bs=1 count=40 if=file1) <(dd bs=1 count=40 if=file2)
with hexdump:
使用十六进制转储:
diff <(dd bs=1 count=40 if=file1|hexdump) <(dd bs=1 count=40 if=file2|hexdump)