Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the free command in linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to use the free command in linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Linux free command

Let's look at the syntax of the free command:

Free [options]

The man manual for the free command says:

The free command shows the total amount of physical and swap memory available and used by the system, as well as the cache space used by the kernel. This information is obtained from / proc/meminfo.

Next, let's use a question and answer to see how the free command works.

Q1. How do I use the free command to view used and unused memory?

This is easy, you just need to run the free command without any arguments:

Free

This is the output of the free command on my system:

View used and available memory using free command

What do these columns mean?

Total-the total amount of memory installed (equivalent to MemTotal and SwapTotal in / proc/meminfo)

Used-memory used (formula: used = total-free-buffers-cache)

Free-unused memory (equivalent to MemFree and SwapFree in / proc/meminfo)

Shared-memory typically used by temporary file systems (equivalent to Shmem; in / proc/meminfo available from kernel version 2.6.32, or 0 if not available)

Buffers-memory used by kernel buffers (equivalent to Buffers in / proc/meminfo)

Cache-memory used by the page cache and Slab allocation mechanism (equivalent to Cached and Slab in / proc/meminfo)

The sum of buff/cache-buffers and cache

Available-the amount of memory that is expected to be used by newly launched applications without counting swap space. Unlike the cache or free sections, this column takes into account the page cache, and not all recyclable slab memory can actually be reclaimed because there may be occupied parts. (equivalent to MemAvailable; in / proc/meminfo available since kernel version 3.14 and simulated since kernel version 2.6.27; on other versions this value is the same as the free column)

Q2. How to change the units displayed?

You can change the display unit of the memory if necessary. For example, if you want memory to be displayed in megabytes, you can use the parameter-m:

Free-m

Free command display metrics change

Similarly, you can display-b in bytes,-k in KB,-m in MB,-g in GB, and-- tera in TB.

Q3. How do you display readable results?

The free command provides the argument-h to convert the output to a readable format.

Free-h

With this parameter, the free command decides for itself in which units to display each value in memory. For example:

Diplsy data fromm free command in human readable form

Q4. How do I keep the free command running at regular intervals?

You can use the-s argument to have the free command execute continuously at regular intervals. You need to pass a numeric parameter to the command line as the number of seconds for this interval.

For example, make the free command execute every 3 seconds:

Free-s 3

If you need the free command to be executed only a few times, you can use the-c parameter to specify the number of times to execute:

Free-s 3-c 5

The above command ensures that the free command is executed every 3 seconds for a total of 5 times.

Note: this feature is currently problematic on Ubuntu systems, so it has not been tested.

Q5. How do you make free calculate memory based on 1000 instead of 1024?

If you specify that free uses MB to display memory (with the-m parameter), but you want to calculate the result based on 1000, you can use the-- sj parameter. The following figure shows the results with or without this parameter:

How to make free use power of 1000\ (not 1024\) while displaying memory figures

Q6. How do I make the free command display the sum of each column?

If you want the free command to display the sum of each column, you can use the-t argument.

Free-t

As shown in the following figure:

Thank you for reading! This is the end of this article on "how to use free commands in linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report