如何在Linux/Unix上获取硬件信息?

时间:2022-08-25 23:35:57

How I can get hardware information from a Linux / Unix machine. Is there a set of APIs?

如何从Linux / Unix机器中获取硬件信息。有一组api吗?

I am trying to get information like:

我正试图获取如下信息:

  • OS name.
  • 操作系统的名称。
  • OS version.
  • 操作系统版本。
  • available network adapters.
  • 可用的网络适配器。
  • information on network adapters.
  • 网络适配器的信息。
  • all the installed software.
  • 所有安装的软件。

I am looking for an application which collects this information and show it in a nice format. I have used something similar with the "system_profile" command line tool for Mac OS X. I was wondering if something similar is available for Linux as well.

我正在寻找一个应用程序来收集这些信息并以一种很好的格式显示它。我使用了类似于Mac OS x的“system_profile”命令行工具,我想知道Linux是否也有类似的工具。

7 个解决方案

#1


15  

If you need a simple answer, use:

如果你需要一个简单的答案,使用:

  • cat /proc/cpuinfo
  • 猫/proc/cpuinfo
  • cat /proc/meminfo
  • 猫/proc/meminfo
  • lspci
  • lspci
  • lsusb
  • lsusb

and harvest any info you need from the output of these commands. (Note: the cut command may be your friend here if you are writing a shell script.)

并从这些命令的输出中获取所需的任何信息。(注意:如果您正在编写shell脚本,cut命令可能是您的朋友。)

Should you need more detail, add a -v switch to get verbose output from the lspci and lsusb commands.

如果需要更详细的信息,请添加一个-v开关,以便从lspci和lsusb命令获得详细的输出。

If what you are looking for is a more feature-complete API, then use HAL, though that may be an overkill for what you are trying to build.

如果您正在寻找的是一个功能更完整的API,那么请使用HAL,尽管对于您正在构建的东西来说,这可能有点过头了。

#2


8  

If you are looking for a tool that show System Information, the GUI tool like HardInfo would useful for you.

如果您正在寻找一个显示系统信息的工具,那么像HardInfo这样的GUI工具将对您有用。

In Ubuntu, you can install HardInfo like this...

在Ubuntu中,你可以像这样安装HardInfo…

sudo apt-get install hardinfo

sudo apt-get安装hardinfo

Cheers

干杯

#3


7  

There is a bash command lshw - list hardware

有一个bash命令lshw - list硬件

#4


2  

I would use hal, the hardware abstraction layer. It includes both some GUI commands, some tty commands (which can be used from shell programs), and library bindings for c and multiple other languages.

我会使用hal,硬件抽象层。它包括一些GUI命令、一些tty命令(可以从shell程序中使用)、c语言和多种其他语言的库绑定。

HAL is not really a standard part of "linux", but I think it is used by most modern distros.

HAL并不是“linux”的标准部分,但我认为大多数现代发行版都使用它。

#5


1  

Try sudo lshw. It's the easiest.

sudo lshw试试。这是最简单的。

#6


0  

Since you mentioned API, try the exec family of commands for C. You can use them to execute these binaries that other people have mentioned. To create a robust/flexible solution you will probably also have to leverage the Unix fork() commands. You will also have to develop a mechanism for capturing the output spewed by these utilities. Look into Unix pipes for that.

既然您提到了API,那么尝试一下c的exec系列命令,您可以使用它们来执行其他人提到的二进制文件。要创建健壮/灵活的解决方案,您可能还需要利用Unix fork()命令。您还必须开发一种机制来捕获这些实用程序的输出。请查看Unix管道。

#7


0  

You can use inxi which provide all hardware information including cpu temperature and so on.

您可以使用inxi提供所有硬件信息,包括cpu温度等等。

Install on Red Hat based OS sudo dnf install inixi

在Red Hat上安装基于OS sudo dnf的inixi

Install on Debian based OS apt-get install inxi

在Debian上安装基于OS apt-get的inxi安装

#1


15  

If you need a simple answer, use:

如果你需要一个简单的答案,使用:

  • cat /proc/cpuinfo
  • 猫/proc/cpuinfo
  • cat /proc/meminfo
  • 猫/proc/meminfo
  • lspci
  • lspci
  • lsusb
  • lsusb

and harvest any info you need from the output of these commands. (Note: the cut command may be your friend here if you are writing a shell script.)

并从这些命令的输出中获取所需的任何信息。(注意:如果您正在编写shell脚本,cut命令可能是您的朋友。)

Should you need more detail, add a -v switch to get verbose output from the lspci and lsusb commands.

如果需要更详细的信息,请添加一个-v开关,以便从lspci和lsusb命令获得详细的输出。

If what you are looking for is a more feature-complete API, then use HAL, though that may be an overkill for what you are trying to build.

如果您正在寻找的是一个功能更完整的API,那么请使用HAL,尽管对于您正在构建的东西来说,这可能有点过头了。

#2


8  

If you are looking for a tool that show System Information, the GUI tool like HardInfo would useful for you.

如果您正在寻找一个显示系统信息的工具,那么像HardInfo这样的GUI工具将对您有用。

In Ubuntu, you can install HardInfo like this...

在Ubuntu中,你可以像这样安装HardInfo…

sudo apt-get install hardinfo

sudo apt-get安装hardinfo

Cheers

干杯

#3


7  

There is a bash command lshw - list hardware

有一个bash命令lshw - list硬件

#4


2  

I would use hal, the hardware abstraction layer. It includes both some GUI commands, some tty commands (which can be used from shell programs), and library bindings for c and multiple other languages.

我会使用hal,硬件抽象层。它包括一些GUI命令、一些tty命令(可以从shell程序中使用)、c语言和多种其他语言的库绑定。

HAL is not really a standard part of "linux", but I think it is used by most modern distros.

HAL并不是“linux”的标准部分,但我认为大多数现代发行版都使用它。

#5


1  

Try sudo lshw. It's the easiest.

sudo lshw试试。这是最简单的。

#6


0  

Since you mentioned API, try the exec family of commands for C. You can use them to execute these binaries that other people have mentioned. To create a robust/flexible solution you will probably also have to leverage the Unix fork() commands. You will also have to develop a mechanism for capturing the output spewed by these utilities. Look into Unix pipes for that.

既然您提到了API,那么尝试一下c的exec系列命令,您可以使用它们来执行其他人提到的二进制文件。要创建健壮/灵活的解决方案,您可能还需要利用Unix fork()命令。您还必须开发一种机制来捕获这些实用程序的输出。请查看Unix管道。

#7


0  

You can use inxi which provide all hardware information including cpu temperature and so on.

您可以使用inxi提供所有硬件信息,包括cpu温度等等。

Install on Red Hat based OS sudo dnf install inixi

在Red Hat上安装基于OS sudo dnf的inixi

Install on Debian based OS apt-get install inxi

在Debian上安装基于OS apt-get的inxi安装