- Linux free command
- Syntax
- Options
- Examples
- Related commands
- free Command in Linux with examples
- Команда free в Linux
- Как использовать команду free
- Отображение использования памяти в удобочитаемом формате
- Отображение использования памяти в других показателях
- Отображение итоговых значений столбца
- Непрерывно печатать результат
- Выводы
- Free Command in Linux Explained With Examples
- Explaining the output of the Free command in Linux
- Customizing the output of the free command
- Automate the free command and run it continuously or periodically
Linux free command
On Unix-like operating systems, the free command displays the total amount of free and used physical and swap memory, and the buffers used by the kernel.
This page describes the GNU/Linux version of free.
Syntax
Options
-b, —bytes | Display the amount of memory in bytes. |
-k, —kilo | Display the amount of memory in kilobytes. This is the default. |
-m, —mega | Display the amount of memory in megabytes. |
-g, —giga | Display the amount of memory in gigabytes. |
—tera | Display the amount of memory in terabytes. |
-h, —human | Show all output fields automatically scaled to shortest three digit unit and display the units of print out. Following units are used. |
If you have a petabyte of RAM or swap, the number is in terabytes and your computer is awesome.
—seconds seconds
Examples
Running free with no options displays a chart similar to the example below.
When using the free command, the two important lines are the -/+ buffers/cache line and Swap line. If you want to get a good idea on how much free memory is available, the free section in the buffers/cache is what you should be reading. Linux keeps the contents of memory in the buffers to help having to access the same data over-and-over from the slower disk drive. If your buffers/cache free memory is low or your swap free is low, a memory upgrade is necessary.
The command above displays the memory in megabytes with the «s 5» telling the system to continuously poll the data and display the results.
This command is similar to the command mentioned above and uses watch to display the current memory usage.
Related commands
ps — Report the status of a process or processes.
top — Display a sortable, continually-updated list of processes.
vmstat — Report statistics about virtual memory usage.
Источник
free Command in Linux with examples
While using LINUX there might come a situation when you are willing to install a new application (big in size) and you wish to know for the amount of free memory available on your system. In LINUX, there exists a command line utility for this and that is free command which displays the total amount of free space available along with the amount of memory used and swap memory in the system, and also the buffers used by the kernel.
This is pretty much what free command does for you.
Syntax:
As free displays the details of the memory related to your system , its syntax doesn’t need any arguments to be passed but only options which you can use according to your wish.
Using free Command
You can use the free command as:
When no option is used then free command produces the columnar output as shown above where column:
- total displays the total installed memory (MemTotal and SwapTotal i.e present in /proc/meminfo).
- used displays the used memory.
- free displays the unused memory.
- shared displays the memory used by tmpfs(Shmen i.epresent in /proc/meminfo and displays zero in case not available).
- buffers displays the memory used by kernel buffers.
- cached displays the memory used by the page cache and slabs(Cached and Slab available in /proc/meminfo).
- buffers/cache displays the sum of buffers and cache.
Options for free command
- -b, – -bytes : It displays the memory in bytes.
- -k, – -kilo : It displays the amount of memory in kilobytes(default).
- -m, – -mega : It displays the amount of memory in megabytes.
- -g, – -giga : It displays the amount of memory in gigabytes.
- – – tera : It displays the amount of memory in terabytes.
- -h, – -human : It shows all output columns automatically scaled to shortest three digit unit and display the units also of print out. The units used are B(bytes), K(kilos), M(megas), G(gigas), and T(teras).
- -c, – -count : It displays the output c number of times and this option actually works with -s option.
- -l, – -lohi : It shows the detailed low and high memory statistics
- -o, – -old : This option disables the display of the buffer adjusted line.
- -s, – -seconds : This option allows you to display the output continuously after s seconds delay. In actual, the usleepsystem call is used for microsecond resolution delay times.
- -t, – -total : It adds an additional line in the output showing the column totals.
- – -help : It displays a help message and exit.
- -V, – -version : It displays version info and exit.
Using free command with options
1. Using -b : It just displays the output in unit bytes.
2. Using -k : This option displays the result in kilobytes.
3. Using -m : This option displays the result in megabytes.
4.using -g : This option displays the result in gigabytes.
5. Using -t (total) : This option displays an additional line containing the total of the total, used and free columns.
6. Using -s and -o: This option allows you to display the output of free command after a set time gap given by the user. This option requires a numeric value to be passed with it that is treated as the number of seconds after which the output will be displayed.
Now, with -s you can only specify the time gap but not the number of times you want the output to be displayed. For this, -c is used along with -s specifying the number of times the output will be displayed.
7. Using -o : This option makes the buffer/cache line go away from the output as shown below.
Источник
Команда free в Linux
Сколько свободной оперативной памяти доступно в моей системе Linux? Достаточно ли свободной памяти для установки и запуска новых приложений?
В системах Linux вы можете использовать команду free чтобы получить подробный отчет об использовании памяти системой.
Команда free предоставляет информацию об общем объеме физической памяти и памяти подкачки , а также о свободной и используемой памяти.
Как использовать команду free
Синтаксис free команды следующий:
При использовании без какой-либо опции команда free будет отображать информацию о памяти и подкачке в кибибайтах. 1 кибибайт (КиБ) равен 1024 байтам.
Вывод будет включать три строки, заголовок, одну строку для памяти и одну для свопа:
Вот что означает каждый столбец:
- total — это число представляет общий объем памяти, который может быть использован приложениями.
- used — Используемая память. Он рассчитывается как: used = total — free — buffers — cache
- бесплатно — Свободная / неиспользуемая память.
- общий — этот столбец можно игнорировать, поскольку он не имеет значения. Это здесь только для обратной совместимости.
- buff / cache — объединенная память, используемая буферами ядра, а также страничным кешем и блоками. Эта память может быть освобождена в любое время, если это необходимо приложениям. Если вы хотите, чтобы буферы и кеш отображались в двух отдельных столбцах, используйте параметр -w .
- доступно — оценка объема памяти, доступного для запуска новых приложений без подкачки.
Отображение использования памяти в удобочитаемом формате
По умолчанию команда free показывает информацию о памяти в кибибайтах. Чтобы просмотреть информацию в удобочитаемом формате (обычно в мегабайтах и гигабайтах), используйте параметр -h :
Отображение использования памяти в других показателях
Команда free также позволяет вам указать единицы измерения памяти. Допустимые варианты:
- -b , —bytes — отображать вывод в байтах.
- —kilo — отображать вывод в килобайтах (1 КБ = 1000 байт).
- —mega — отображать вывод в мегабайтах.
- —giga — Показать вывод в гигабайтах.
- —tera — Показать вывод в терабайтах.
- -k , —kibi — Показать вывод в кибибайтах. (1 КБ = 1024 байта). Это единица измерения по умолчанию.
- -m , —mebi — Показать вывод в мебибайтах.
- -g , —gibi — Показать вывод в гигабайтах.
- —tebi — отображать вывод в тебибайтах.
- —peti — Показать вывод в пебибайтах.
- —si — вместо 1024 используйте —mebi —si 1000. Например, —mebi —si равно —mega .
Например, чтобы отобразить результат в мегабайтах, введите:
Отображение итоговых значений столбца
Чтобы отобразить строку, показывающую итоги столбца, используйте параметр -t . Это дает вам сумму памяти и свопа в столбцах total, used и free.
Непрерывно печатать результат
Чтобы постоянно отображать информацию о памяти на экране, вызовите free с параметром -s ( —seconds ), за которым следует число, определяющее задержку.
Например, чтобы распечатывать информацию о памяти каждые пять секунд, вы должны выполнить:
free команда будет продолжать отображать результат, пока вы не нажмете CTRL+C Это похоже на поведение команды watch .
Чтобы отображать результат определенное количество раз, используйте параметр -c ( —count ). В примере ниже команда выведет результат десять раз:
Выводы
Мы показали вам, как использовать free команду для проверки использования памяти системой и интерпретации вывода команды. Чтобы просмотреть все доступные параметры, введите в терминале man free .
Если у вас есть какие-либо вопросы или отзывы, не стесняйтесь оставлять комментарии.
Источник
Free Command in Linux Explained With Examples
Explaining the output of the Free command in Linux
Using Free Command in Linux is pretty simple. Here’s the syntax for the free command:
free [options]
A sample output for the free command may look like this:
The free command without options returns results for ‘total’, ‘used’, and ‘free’ memory on your system by accessing information from the Linux kernel. It also displays categories for ‘shared’, ‘buff/cache’, and ‘available’.
To avoid some potential confusion, let’s clarify what those terms mean.
- Total is straightforward. This figure represents all existing memory.
- Used is a calculation of the total system ram minus allocated free, shared, buffer, and cache memory.
- Free is memory that is not being used for any purpose.
- Shared, Buffer, and Cache fields identify memory being used for kernel/operating system needs. The buffer and cache are added together and the sum is listed under ‘buff/cache’.
- Available memory appears in newer versions of free and is intended to give the end user an estimation of how many memory resources are still open for use.
These clarifications are important. Incorrectly attributing meaning to the terms free or used memory can create a misconception of your system’s memory use.
This may lead an inexperienced user to falsely believe their system needs to be upgraded with more RAM. Note that in previous versions there was no display for available memory. Users may incorrectly assume that because there is high memory usage, their hardware is underpowered. The available tab was presumably put in place to help offset this common misunderstanding.
The Linux operating system uses caching to improve performance. In very basic terms, this means that a certain amount of memory is set aside for use before it’s needed so it can be processed more quickly. This is a standard process and nothing to be concerned about unless the values seem very unusual for your current use.
The ‘available’ memory estimate is probably adequate for someone who simply wants to know how their system is responding to certain applications. If you are unable to see this field, you may need to update to the latest version of ‘free’. You can check your current version by running ‘free -V’. My version 3.3.15 has the ‘available’ in its output.
Customizing the output of the free command
The default output displays information in kilo bytes, but there are options to display in different formats if you prefer. Running the help (free -help) displays all the possible options you can append.
The most useful option here in my opinion is -h which shows the output of the free command in human readable format.
There are other options. They show the same requested information with some basic math conversions. I think that the human readable option (free -h) is one of the most effective for an everyday user.
Automate the free command and run it continuously or periodically
Another great feature is the capability to automate the command. There are two options that help us customize this tool:
- There is ‘-s’, which runs the free command for the designated interval of seconds until the user quits the program (^+C).
- There is also ‘-c’ which can be used separately or in conjunction with the seconds option. If you enter only ‘-c’ and an integer (n), it will run the command n number of times. By default it uses one second intervals.
Let’s say you want to open a series of applications and see how your memory is affected. For my test output I will use the human readable format using powers of 1000 (Gb) instead of 1024 (GiB). I’m going to record for 20 seconds to analyze the impact. I will capture the data every 5 seconds and I will do this for 4 counts. Here is this example formatted for the command line and its output:
I waited a few seconds and then I opened a few browser tabs and accessed some bookmarks. The stress of those activities is noted by the fluctuations in the output. Please note, the effect would be more pronounced using an output format with less rounding. For our purely demonstrative purposes, this is unnecessary.
If you want to continually monitor the memory usage with free command but don’t want its output to clutter the screen, you can use the watch command together with free command.
This will show you just one output for the free command but this output will be changed at regular interval.
Conclusion
This tutorial demonstrated how to get started using the ‘free’ command in Linux. Hopefully, you find this guide helpful and easy to understand. ‘Free’ can be used to analyze system memory usage and can be tweaked using its various options to finely tailor output for your needs.
If you have any questions or suggestions, please let us know in the comment section.
Источник