使用免费和热门命令在Linux中查找内存大小

时间:2020-01-09 10:43:07  来源:igfitidea点击:

如何使用命令行选项找出Linux操作系统下的RAM大小?
您可以使用以下命令来查找Linux操作系统下的实际RAM大小:

使用/proc/meminfo文件在Linux中查找内存大小

/proc/meminfo文件告诉您服务器上的内存使用情况。

free命令和许多其他Linux命令使用此文件来显示系统上的可用内存和已使用内存(物理内存和交换内存)以及内核使用的共享内存和缓冲区的数量。
输入以下cat命令/less命令以查看已安装的ram总数和已使用的ram,执行:

$ less /proc/meminfo

或者

$ cat /proc/meminfo

输出示例:

MemTotal:      8177444 kB
MemFree:       1528304 kB
Buffers:        353152 kB
Cached:        2301132 kB
SwapCached:          0 kB
Active:        5250532 kB
Inactive:       983832 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:      8177444 kB
LowFree:       1528304 kB
SwapTotal:     1052248 kB
SwapFree:      1052248 kB
Dirty:            1796 kB
Writeback:           0 kB
AnonPages:     3579784 kB
Mapped:         106548 kB
Slab:           295500 kB
PageTables:      82956 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
CommitLimit:   5140968 kB
Committed_AS:  4959796 kB
VmallocTotal: 34359738367 kB
VmallocUsed:    263900 kB
VmallocChunk: 34359473347 kB
HugePages_Total:     0
HugePages_Free:      0
HugePages_Rsvd:      0
Hugepagesize:     2048 kB

当然,我们可以如下使用grep命令/egrep命令来过滤掉信息:

grep MemTotal /proc/meminfo
egrep 'MemTotal|MemFree|MemAvailable' /proc/meminfo

使用free命令检查RAM大小

Free命令是/proc/meminfo文件的前端。
它提供了更易于理解的输出,以向您显示系统中可用和可用的物理内存和交换内存的总量,以及内核使用的缓冲区,运行:

$ free -m

或者

$ free -g

输出示例:

total       used       free     shared    buffers     cached
Mem:          7985       6466       1519          0        344       2249
-/+ buffers/cache:       3871       4114
Swap:         1027          0       1027

free命令选项

在free(1)手册页中:

The -b switch displays the amount of memory in bytes; the -k switch (set by default) displays it in kilobytes; the -m switch displays it in megabytes.
 
       The -t switch displays a line containing the totals.
 
       The -o switch disables the display of a "buffer adjusted" line.  If the -o option is not specified, free subtracts buffer memory from the used memory and adds it to the free memory reported.
 
       The -s switch activates continuous polling delay seconds apart. You Jan actually specify any floating point number for delay, usleep(3) is used for microsecond resolution delay times.

因此,我们也尝试这些选项:

$ free
$ free -m
$ free -g -t -o
$ free -t
$ free -o

使用vmstat命令查找免费和使用过的ram信息

vmstat命令可以显示内存统计信息,包括有关进程,页面调度,块IO,陷阱和cpu活动的其他信息。
将-s选项传递给vmstat以向我们显示内存统计信息,如下所示:

$ vmstat -s

输出示例:

8177444  total memory
      6655064  used memory
      5251360  active memory
       989748  inactive memory
      1522380  free memory
       353316  buffer memory
      2308588  swap cache
      1052248  total swap
            0  used swap
      1052248  free swap
     38412570 non-nice user cpu ticks
       100117 nice user cpu ticks
      5153239 system cpu ticks
    271927635 idle cpu ticks
        45717 IO-wait cpu ticks
        63003 IRQ cpu ticks
       564561 softirq cpu ticks
            0 stolen cpu ticks
      1846153 pages paged in
    158053429 pages paged out
            0 pages swapped in
            0 pages swapped out
   1226003322 interrupts
    740976858 CPU context switches
   1295805340 boot time
       659452 forks

top命令

top命令提供正在运行的系统的动态实时视图,包括有关RAM,CPU的快速摘要信息以及Linux内核当前正在管理的任务列表。
执行以下命令:

$ top

dmidecode命令

dmidecode命令用于以人类可读的格式转储计算机DMI(有时称为SMBIOS)表内容。
该表包含对系统硬件组件的描述,以及其他有用的信息,例如序列号和BIOS版本。
由于有了此表,您可以检索此信息,而不必探究实际的硬件。
要查看有关内存的完整信息,请执行:

$ sudo dmidecode --type memory

输出示例:

# dmidecode 2.9
SMBIOS 2.6 present.

Handle 0x1000, DMI type 16, 15 bytes
Physical Memory Array
	Location: System Board Or Motherboard
	Use: System Memory
	Error Correction Type: None
	Maximum Capacity: 16 GB
	Error Information Handle: Not Provided
	Number Of Devices: 4

Handle 0x1100, DMI type 17, 28 bytes
Memory Device
	Array Handle: 0x1000
	Error Information Handle: Not Provided
	Total Width: 64 bits
	Data Width: 64 bits
	Size: 4096 MB
	Form Factor: DIMM
	Set: None
	Locator: DIMM_A
	Bank Locator: Not Specified
	Type: 
	Type Detail: Synchronous
	Speed: 1333 MHz (0.8 ns)
	Manufacturer: 80CE000080CE
	Serial Number: 45AAFB60
	Asset Tag: 01101800
	Part Number: M471B5273CH0-CH9  

Handle 0x1101, DMI type 17, 28 bytes
Memory Device
	Array Handle: 0x1000
	Error Information Handle: Not Provided
	Total Width: 64 bits
	Data Width: 64 bits
	Size: 4096 MB
	Form Factor: DIMM
	Set: None
	Locator: DIMM_B
	Bank Locator: Not Specified
	Type: 
	Type Detail: Synchronous
	Speed: 1333 MHz (0.8 ns)
	Manufacturer: 80CE000080CE
	Serial Number: 45AAFDAD
	Asset Tag: 01101800
	Part Number: M471B5273CH0-CH9  

Handle 0x1102, DMI type 17, 28 bytes
Memory Device
	Array Handle: 0x1000
	Error Information Handle: Not Provided
	Total Width: 64 bits
	Data Width: 64 bits
	Size: No Module Installed
	Form Factor: DIMM
	Set: None
	Locator: DIMM_C
	Bank Locator: Not Specified
	Type: 
	Type Detail: Synchronous
	Speed: Unknown
	Manufacturer:             
	Serial Number:         
	Asset Tag:         
	Part Number:                   

Handle 0x1103, DMI type 17, 28 bytes
Memory Device
	Array Handle: 0x1000
	Error Information Handle: Not Provided
	Total Width: 64 bits
	Data Width: 64 bits
	Size: No Module Installed
	Form Factor: DIMM
	Set: None
	Locator: DIMM_D
	Bank Locator: Not Specified
	Type: 
	Type Detail: Synchronous
	Speed: Unknown
	Manufacturer:             
	Serial Number:         
	Asset Tag:         
	Part Number: