Unix History: Why does hexdump default to word alignment?

Unix History: Why does hexdump default to word alignment?

Nadav Har'El nyh at math.technion.ac.il
Thu Dec 1 10:10:55 IST 2011


On Thu, Dec 01, 2011, Elazar Leibovich wrote about "Unix History: Why does hexdump default to word alignment?":
> The default behaviour of hexdump is to align data word-wide. For instance

Just as a comment, if I remember correctly, "hexdump" isn't actually
part of ancient Unix history - the original was "od", which as its name
suggests dumps in *octal*, but had an option "od -x" to see hexadecimal.

In any case, od and hexdump are very similar, and apparently have the
same ideosynchacies, as "od -x" also defaults two two-byte words.

>     printf '\xFF\xFF\x01' | hexdump
>     0000000 ffff 0001
>     0000003
> 
> This makes little sense to me. In C, structs are not necessarily aligned to
> words, and it doesn't seems useful to view about any data format for which
> you're sure everything is word-aligned. The "hexdump -C" behaviour makes
> much more sense in the general case.

When you say "words" and "word aligned" here, you mean historic 2 byte words.
This is indeed *NOT* a very useful default on any modern computers. In some
old computers, like the PDP11 2 byte words were common and useful.
In other old computers, this was never a useful default.

I guess nobody cares because since the 1970s when these tools were
written, nobody uses them any more ;-) I don't think I used "od" in at
least two decade... At least since "less" was invented and usually does
the right thing (show ASCII when possible, or hex for nonvisible
characters).

Amazingly, I don't believe that the original od even had an option to
see hex for each byte: "od -c" didn't show hex, "od -x" showed hex for
each two bytes, and "od -b" (for "bytes") showed each byte but octal
(which evidentally was more popular than hex in the old days).

Gnu's od can do what you want with "od -t x1". As you saw, so can
hexdump with the "-C" flag.

-- 
Nadav Har'El                        |                   Thursday, Dec 1 2011, 
nyh at math.technion.ac.il             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |Make it idiot proof and someone will make
http://nadav.harel.org.il           |a better idiot.



More information about the Linux-il mailing list