フィードを購読する
Linux 

Sometimes, you need to get information about the CPU on a machine, whether it's because you just can't remember what kind of CPU your computer has or you need a specific detail, such as the number of cores or whether it's 32- or 64-bit. Here are six ways to get that information on Linux.

[ Explore the central processing unit's components and functionality. ]

GNOME settings

If you use the GNOME desktop, you can see what kind of CPU you use in the Settings application.

First, click the Activities button in the top-left corner of the GNOME desktop and type Settings. In the Settings window that appears, click About in the left column.

GNOME display for device information

[ Get the guide to installing applications on Linux. ]

KDE Kinfocenter

If you use the KDE desktop, find all the CPU information you could ever need in the KInfocenter application.

First, click the K Menu in the bottom-left corner of the KDE Plasma Desktop, and select Info Center. In the Info Center window, click Devices in the left column and then CPU.

KDE Kinfocenter display

[ Keep your most commonly used commands handy with the Linux commands cheat sheet. ]

Look at /proc/cpuinfo

While we often use the term "Linux" (or sometimes GNU+Linux) to refer to the operating system, it's a kernel first and foremost. As the binary responsible for bootstrapping your system, Linux has information about everything it's managing, including the CPU. This data is stored in the /proc virtual filesystem in a file named cpuinfo. It's this file that applications like KInfocenter parse to deliver data about your CPU, but you can parse it yourself, too.

$ cat /proc/cpuinfo | less
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 25
model           : 33
model name      : AMD Ryzen 5 5600X 6-Core Processor
stepping        : 0
microcode       : 0xa201009
cpu MHz         : 2200.000
cache size      : 512 KB
physical id     : 0
siblings        : 12
core id         : 0
cpu cores       : 6
[...]

Try arch

If all you need to know is the architecture of your CPU, you can use the arch command:

$ arch
x86_64

[ Keep your most frequently used commands handy with the Linux commands cheat sheet. ]

Use uname

The uname command is usually used to print information about your kernel. Because your kernel is highly dependent on your CPU, you can extract a lot of CPU data from its output. For example, you can get the vendor of your CPU with the --hardware-platform (-i for short) option:

$ uname --hardware-platform
authenticAMD

You can also get the model of your CPU with the --processor (-p for short) option:

$ uname --processor
AMD Ryzen 5 5600X 6-Core Processor

And finally, the architecture with --machine (-m):

$ uname --machine
x86_64

Programming libraries

Sometimes you need CPU information within a non-interactive interface. On Linux, any command you type into an interactive terminal session can be scripted so that it's non-interactive, but sometimes you're working with more than just a simple script. There are usually libraries for obtaining that information if you're using a compiled programming language and you need to determine what architecture you're on. However, you may also be able to do some rudimentary tests to determine the architecture without importing a special library.

There are too many programming languages for me to give an example of all of them, but here's a simple example in C++ of the kind of logic you might use:

#include <iostream>
using namespace std;

int main() {
    if ( SIZE_MAX == 0xFFFFFFFF ) {
      cout << "32 bit";
    } else if ( SIZE_MAX == 0xFFFFFFFFFFFFFFFF ) {
      cout << "64 bit";
    } else {
      cout << "Unknown";
    }
    return 0;
}

This code checks SIZE_MAX to determine the potential maximum size of a variable. If it's set to 64-bit, then the CPU that compiled the code is capable of 64-bit.

That's not the only way to extract that kind of data; if you have libraries that make it even easier, you can use those.

Knowledge is power

Getting insight into what CPU you're running is a useful trick to know. It may not come up often, but it's annoying when it occurs and you're caught without the necessary information.

I've covered all the ways I could think of to get CPU information in this article, but there are many other ways I haven't thought of. How do you get CPU information on your systems? Email us at enable-sysadmin@redhat.com to let us know.


執筆者紹介

Seth Kenlon is a Linux geek, open source enthusiast, free culture advocate, and tabletop gamer. Between gigs in the film industry and the tech industry (not necessarily exclusive of one another), he likes to design games and hack on code (also not necessarily exclusive of one another).

Read full bio
UI_Icon-Red_Hat-Close-A-Black-RGB

チャンネル別に見る

automation icon

自動化

テクノロジー、チームおよび環境に関する IT 自動化の最新情報

AI icon

AI (人工知能)

お客様が AI ワークロードをどこでも自由に実行することを可能にするプラットフォームについてのアップデート

open hybrid cloud icon

オープン・ハイブリッドクラウド

ハイブリッドクラウドで柔軟に未来を築く方法をご確認ください。

security icon

セキュリティ

環境やテクノロジー全体に及ぶリスクを軽減する方法に関する最新情報

edge icon

エッジコンピューティング

エッジでの運用を単純化するプラットフォームのアップデート

Infrastructure icon

インフラストラクチャ

世界有数のエンタープライズ向け Linux プラットフォームの最新情報

application development icon

アプリケーション

アプリケーションの最も困難な課題に対する Red Hat ソリューションの詳細

Original series icon

オリジナル番組

エンタープライズ向けテクノロジーのメーカーやリーダーによるストーリー