在linux 中如何查看安裝的系統是64-bit or 32-bit ?

在linux 中如何查看安裝的系統是64-bit or 32-bit ?

查看linux kernel 是64-bit 或 32-bit

可以使用下列指令查看kernel 是64-bit 或 32-bit

uname -m

若是x86-64, 就是64-bit kernel.
若是i686, 就是32-bit kernel

查看CPU 是64-bit 或 32-bit

使用下列指令查看CPU資訊

cat /proc/cpuinfo

會顯示一堆CPU 相關資訊, 其中在flags訊息中, 若有lm 字眼出現, 表示是Long Mode, 即64-bit CPU.
詳細的cpuinfo 資訊, 可以參考這裡

也有簡單的方式如下

lscpu

其中CPU op-mode 會顯示你的CPU 是否為64-bit

在C code 中查看程式是32-bit or 64-bit

#include <stdio.h>

int main(void)
{
    printf("%d\n", __WORDSIZE);
    return 0;
}

看系統變數來得知是32-bit 或 64-bit

系統變數也可以知道是否為64-bit

getconf LONG_BIT

在bash 中使用更有效率的方式偵測32-bit 或 64-bit

#!/bin/bash
if ((1<<32)); then
  echo 64bits
else
  echo 32bits
fi

參考資訊

  1. How to determine whether a given Linux is 32 bit or 64 bit?
This entry was posted in Linux and tagged , . Bookmark the permalink.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *