49

On my machine I get the following output when I run these commands:

$ echo foos > myfile
$ hexdump myfile
6f66 736f 000a

The output from hexdump is little-endian. Does this mean that my machine is little-endian, or does hexdump always use little-endian format?

jw013
  • 50,274
  • 9
  • 137
  • 141
Cory Klein
  • 18,391
  • 26
  • 81
  • 93

2 Answers2

66

The traditional BSD hexdump utility uses the platform's endianness, so the output you see means your machine is little-endian.

Use hexdump -C (or od -t x1) to get consistent byte-by-byte output irrespective of the platform's endianness.

Cory Klein
  • 18,391
  • 26
  • 81
  • 93
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • See also [this answer](https://stackoverflow.com/questions/15553493/how-to-print-only-the-hex-values-from-hexdump-without-the-line-numbers-or-the-as#15554717) for custom formats of `hexdump`'s output. – Matthias Braun Oct 09 '21 at 07:37
6

From the manpage:

 -x      Two-byte hexadecimal display.  Display the input offset in hexa‐
         decimal, followed by eight, space separated, four column, zero-
         filled, two-byte quantities of input data, in hexadecimal, per
         line.

...

 If no format strings are specified, the default display is equivalent to
 specifying the -x option.

Your output is little-endian (least significant byte first), which is also the endianness of the x86 and x86_64 architectures, which you are probably using.

Cory Klein
  • 18,391
  • 26
  • 81
  • 93
Dennis Kaarsemaker
  • 8,420
  • 3
  • 29
  • 31