How to create a hex dump of file containing only t

2019-01-09 23:28发布

How do I create an unmodified hex dump of a binary file in Linux using bash? The od and hexdump commands both insert spaces in the dump and this is not ideal.

Is there a way to simply write a long string with all the hex characters, minus spaces or newlines in the output?

标签: linux bash hex
5条回答
相关推荐>>
2楼-- · 2019-01-09 23:51

The other answers are preferable, but for a pure Bash solution, I've modified the script in my answer here to be able to output a continuous stream of hex characters representing the contents of a file. (Its normal mode is to emulate hexdump -C.)

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-09 23:52

It seems to depend on the details of the version of od. On OSX, use this:

od -t x1 -An file |tr -d '\n '

(That's print as type hex bytes, with no address. And whitespace deleted afterwards, of course.)

查看更多
4楼-- · 2019-01-10 00:11

Perl one-liner:

perl -e 'local $/; print unpack "H*", <>' file
查看更多
疯言疯语
5楼-- · 2019-01-10 00:13

xxd -p file

Or if you want it all on a single line:

xxd -p file | tr -d '\n'

查看更多
欢心
6楼-- · 2019-01-10 00:14

Format strings can make hexdump behave exactly as you want it to (no whitespace at all, byte by byte):

hexdump -ve '1/1 "%.2x"'

1/1 means "each format is applied once and takes one byte", and "%.2x" is the actual format string, like in printf. In this case: 2-character hexadecimal number, leading zeros if shorter.

查看更多
登录 后发表回答