lscpu
The lscpu
command shows (among other things):
Byte Order: Little Endian
Systems this is known to work on
- CentOS 6
- Ubuntu (12.04, 12.10, 13.04, 13.10, 14.04)
- Fedora (17,18,19)
- ArchLinux 2012+
- Linux Mint Debian (therefore assuming Debian testing as well).
Systems this is known to not work on
- Fedora 14
- CentOS 5 (assuming RHEL5 because of this)
Why the apparent differences across distros?
After much digging I found out why. It looks like version util-linux version 2.19 was the first version that included the feature where lscpu
shows you the output reporting your system's Endianness.
As a test I compiled both version 2.18 and 2.19 on my Fedora 14 system and the output below shows the differences:
util-linux 2.18
$ util-linux-ng-2.18/sys-utils/lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
CPU(s): 4
Thread(s) per core: 2
Core(s) per socket: 2
CPU socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 37
Stepping: 5
CPU MHz: 1199.000
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
NUMA node0 CPU(s): 0-3
util-linux 2.19
$ util-linux-2.19/sys-utils/lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
CPU socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 37
Stepping: 5
CPU MHz: 2667.000
BogoMIPS: 5320.02
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
NUMA node0 CPU(s): 0-3
The above versions were downloaded from the kernel.org website.
od
method? It's simple and works everywhere. It's what I thought of before reading the body of your question. – Gilles 'SO- stop being evil' Aug 31 '13 at 10:57lscpu
method is more what I would come to expect. – slm Aug 31 '13 at 12:11od
approach should work on most open systems, not only linux, which would be the case with usinglscpu
. So what is "best" depends on the circumstances. – MattBianco Aug 08 '14 at 11:06lscpu
even support the endianness. You'll hae to use an alternative method on that OS. – slm Aug 27 '14 at 01:31echo -n | od -to2 | awk 'FNR==1{ print $2}
returns000111
, so the least significant element is right, right? And aren't character streams typically processed from left to right on screen? So how doesn't that indicate that the least significant element is processed last, equivalent to big rather than small endian? – Sam Apr 10 '18 at 17:34od
part more than anyhing else, but after yet some more experimentation and contemplation I think I have it figured out. I think I made the mistake of assuming that the-to2
flag with a 1 byte input makesod
apply a "padding" sort of byte, but I understand now that it simply reads past EOF, parsing a zero byte from the terminal driver. Then it makes sense that that byte is interpreted as the more significant one in little endian and the less significant in big endian, thus being placed left or right, respectively. Please correct me if I'm wrong. – Sam Apr 11 '18 at 08:14