Tuesday 29 November 2022

How to check a Linux system is Little endian or Big

Example from Ubuntu System


lscpu | grep Endian

lscpu | grep -i byte


python3 -c "import sys; print(sys.byteorder)"

#Example from a little-endian system

echo -n I | od -to2 | head -n1 | cut -f2 -d" " | cut -c6

#using awk

echo -n I | od -to2 | awk '{ print substr($2,6,1); exit}'

echo -n I | od -to2 | awk 'FNR==1{ print substr($2,6,1)}'

#on all unix systems

echo I | tr -d [:space:] | od -to2 | head -n1 | awk '{print $2}' | cut -c6

#with hexdump

echo -n I | hexdump -o | awk '{ print substr($2,6,1); exit}'

hexdump -s 5 -n 1 -C /bin/busybox

hexdump -s 5 -n 1 /bin/sh

# apt install dpkg-dev on ubuntu

dpkg-architecture | grep -i end

#take advantage of ELF file format

xxd -c 1 -l 6 /bin/ls

Ref:- how-to-tell-if-a-linux-system-is-big-endian-or-little-endian

No comments:

Post a Comment