10
1
I need to print first 10 bytes of a file in hexadecimal from linux mint command prompt.
Can anyone help me?
Thanks
10
1
I need to print first 10 bytes of a file in hexadecimal from linux mint command prompt.
Can anyone help me?
Thanks
11
I came here seeing three answers thinking that I'd have nothing to add, and that this would be an exercise in how many people can post the same 1-liner in the first minute of a question being asked. But I find people using some new-fangled hexdump
tool. That command is way longer than 2 letters; it alludes to some base other than The One True Base (base 8); and it's even apparent from its name what it does. Clearly this is not the Unix way.
So here's the joy of od
("octal dump").
First GNU, as you will find on your Linux Mint:
od --format=x1 --read-bytes=10 foo
Now BSD, where the irony is that it's actually the same program as hexdump
:
od -t x1 -N 10 foo
1I cut my teeth on 8-bit microprocessors where everything was done in hex. So to me, the one true base is 16. I've used Unix since about '84 and one thing I've always, always hated about it is its fixation with octal: I can't stand octal with its 3-bit encoding which won't seamlessly extend from one to multiple bytes. And octal integer literals in C and other languages is a train-wreck that still wreaks havoc to this day. (+1, by the way) – Adrian Pronk – 2014-01-28T10:29:04.707
11
Option -l len | -len len
is for: stop after writing <len>
octets.
Use it with file like this:
xxd -l 10 file
or
hexdump -C -n 10 file
where -n len
is the same as the -l
option from xxd.
5
You can use xxd
to do that.
$ xxd -ps -l 10 FILENAME
546865204d4954204c69
This prints the first 10 byte (-l 10
) of FILENAME
in plain hex format (-ps
).
http://stackoverflow.com/questions/2614764/how-to-create-a-hex-dump-of-file-containing-only-the-hex-characters-without-spac – Ciro Santilli 新疆改造中心法轮功六四事件 – 2015-09-04T08:21:53.347