当我输入uname -a时,它会给出以下输出。

Linux mars 2.6.9-67.0.15.ELsmp #1 SMP Tue Apr 22 13:50:33 EDT 2008 i686 i686 i386 GNU/Linux

我怎么知道给定的操作系统是32位还是64位?

这在编写配置脚本时很有用,例如:我为什么体系结构构建?


当前回答

真不敢相信这么久以来,居然没人提过

sudo lshw -class cpu

查阅有关中央处理器硬件的速度、数量、大小和功能的详细资料。

其他回答

该系统是32位的。uname中的iX86意味着它是32位体系结构。如果它是64位的,它会返回

Linux mars 2.6.9-67.0.15.ELsmp #1 SMP Tue Apr 22 13:50:33 EDT 2008 x86_64 i686 x86_64 x86_64 GNU/Linux

lscpu会列出关于你的CPU的其他信息:

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
...
$ grep "CONFIG_64" /lib/modules/*/build/.config
# CONFIG_64BIT is not set

简单的脚本获得64位或32位

        if $(getconf LONG_BIT | grep '64'); then
           echo "64 bit system"
        else
            echo "32 bit system"
        fi

在Bash中,使用整数溢出:

if ((1 == 1<<32)); then
  echo 32bits
else
  echo 64bits
fi

它比调用另一个进程或打开文件要高效得多。