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

What are the common examples of free commands under Linux

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the common examples of free commands under Linux, which can be used for reference. Interested friends can refer to them. I hope you can learn a lot after reading this article.

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:

What do these columns mean?

Total-Total amount of installed memory (equivalent to MemTotal and SwapTotal in / proc/meminfo) used-used memory (calculation formula: used = total-free-buffers-cache) free-unused memory (equivalent to MemFree and SwapFree in / proc/meminfo) shared-usually memory used by temporary file systems (equivalent to Shmem in / proc/meminfo Available from kernel version 2.6.32 and shown as 0 if not available) buffers-memory used by kernel buffers (equivalent to Buffers in / proc/meminfo) cache-memory used by page cache and Slab allocation mechanism (equivalent to Cached and Slab in / proc/meminfo) sum of buff/cache-buffers and cache available-memory space that is expected to be used by newly started applications without calculating 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. (MemAvailable; in / proc/meminfo is available since kernel 3.14 and emulated since kernel 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

Six examples of free commands that beginners should look at six examples of free commands that beginners should see

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:

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 results based on 1000, you can use the-sj parameter. The following figure shows the results with or without this parameter:

6 examples of free commands for beginners should look at 6 examples of free commands 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 article carefully. I hope the article "what are the common examples of free commands under Linux" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Development

Wechat

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

12
Report