linux command to view memory --- free

free

Role:
Linux as Free command displays memory status.
free command displays memory usage, including physical memory, virtual memory swap files, shared memory segments, core and buffer systems used.

format

free parameters [options]

If no arguments situation, "free" command displays memory usage information. According to the default statistics counts k (b) a.

[root@linus ~]# free
              total        used        free      shared  buff/cache   available
Mem:        1867048      314712     1090716        9356      461620     1338224
Swap:       2097148           0     2097148

In which the explanation:
Mem: Memory
Swap: Swap
total: represents the total size of physical memory. (Total = Used + as Free)
Used: indicates how many have been used.
free: indicates how many available memory.
Shared: represents the total amount of memory shared by multiple processes.
Buffers / cached: indicates the disk cache size
available: remaining available memory

In linux, you can use the View command options man manual, so -help option, for example to -help

[root@linus ~]# free --help

Usage:
 free [options]

Options:
 -b, --bytes         show output in bytes
 -k, --kilo          show output in kilobytes
 -m, --mega          show output in megabytes
 -g, --giga          show output in gigabytes
     --tera          show output in terabytes
 -h, --human         show human-readable output
     --si            use powers of 1000 not 1024
 -l, --lohi          show detailed low and high memory statistics
 -t, --total         show total for RAM + swap
 -s N, --seconds N   repeat printing every N seconds	
 -c N, --count N     repeat printing N times, then exit	
 -w, --wide          wide output						
 
     --help     display this help and exit				
 -V, --version  output version information and exit		

For more details see free(1).

Common options

-b: Byte units to display memory usage.
-k: in KB display memory usage.
-m: in MB display memory usage.
-g: in GB display content usage.
-h: displays memory usage in appropriate units, choose the most appropriate units (byte, kb, mb, gb , tb) in.
-l: show the level of memory utilization.
-t: Show all memory of linux.
-s N: N indicates seconds every time printing information memory until the end with ctrl + c ctrl + Z or suspended.
-c N: represents a repeating print information memory N times
-V: Display version information

Simple application

[root@linus ~]# free -k			#以Byte为单位显示内存使用信息
              total        used        free      shared  buff/cache   available
Mem:        1867048      314204     1091164        9356      461680     1338684
Swap:       2097148           0     2097148
[root@linus ~]# free -b			#以KB为单位显示内存使用情况
              total        used        free      shared  buff/cache   available
Mem:     1911857152   321617920  1117478912     9580544   472760320  1370939392
Swap:    2147479552           0  2147479552
[root@linus ~]# free -m			#以MB为单位显示内存使用情况
              total        used        free      shared  buff/cache   available
Mem:           1823         306        1065           9         450        1307
Swap:          2047           0        2047
[root@linus ~]# free -h			#以合适的单位显示内存使用情况
              total        used        free      shared  buff/cache   available
Mem:           1.8G        306M        1.0G        9.1M        450M        1.3G
Swap:          2.0G          0B        2.0G
[root@linus ~]# free -l			#显示高低内存的利用率
              total        used        free      shared  buff/cache   available
Mem:        1867048      314456     1090900        9356      461692     1338432
Low:        1867048      776148     1090900
High:             0           0           0
Swap:       2097148           0     2097148
[root@linus ~]# free -t			#显示linux的全部内存
              total        used        free      shared  buff/cache   available
Mem:        1867048      314300     1091040        9356      461708     1338572
Swap:       2097148           0     2097148
Total:      3964196      314300     3188188
[root@linus ~]# free -s 1		#每隔1秒打印一次内存信息,打印了四次之后,将进程挂起
              total        used        free      shared  buff/cache   available
Mem:        1867048      314828     1090512        9356      461708     1338044
Swap:       2097148           0     2097148

              total        used        free      shared  buff/cache   available
Mem:        1867048      314844     1090496        9356      461708     1338028
Swap:       2097148           0     2097148

              total        used        free      shared  buff/cache   available
Mem:        1867048      314844     1090496        9356      461708     1338028
Swap:       2097148           0     2097148

              total        used        free      shared  buff/cache   available
Mem:        1867048      314844     1090496        9356      461708     1338028
Swap:       2097148           0     2097148

^Z
[8]+  已停止               free -s 1
[root@linus ~]# free -c 2			#打印内存信息两次
              total        used        free      shared  buff/cache   available
Mem:        1867048      315712     1089636        9356      461700     1337168
Swap:       2097148           0     2097148

              total        used        free      shared  buff/cache   available
Mem:        1867048      315712     1089636        9356      461700     1337168
Swap:       2097148           0     2097148

There are some remaining combinations, eg:

[root@linus ~]# free -h -s 2 -c 2		#以适合的单位打印,每隔两秒打印一次,共两次
              total        used        free      shared  buff/cache   available
Mem:           1.8G        308M        1.0G        9.1M        450M        1.3G
Swap:          2.0G          0B        2.0G

              total        used        free      shared  buff/cache   available
Mem:           1.8G        308M        1.0G        9.1M        450M        1.3G
Swap:          2.0G          0B        2.0G
Published 14 original articles · won praise 4 · Views 528

Guess you like

Origin blog.csdn.net/qq_42534026/article/details/103834534