
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Free Command in Linux
Introduction
In Linux operating system, there are many commands that can be used to get system information, manage files, and perform various other tasks. One of most commonly used commands is "free" command. This command is used to display amount of free and used memory in system. In this article, we will discuss "free" command in detail, including its usage, options, and examples.
What is Free Command?
The "free" command is a tool that is used to display amount of free and used memory in Linux system. This command is very useful for monitoring system performance and identifying memory-related issues. "free" command provides information about total amount of memory available in system, amount of memory used by system, and amount of memory that is free and available for use.
Syntax of Free Command
The basic syntax of "free" command is as follows ?
free [options]
Options in Free Command ?
The "free" command has several options that can be used to customize output. Some of most commonly used options are ?
"-b" ? This option displays output in bytes.
"-k" ? This option displays output in kilobytes.
"-m" ? This option displays output in megabytes.
"-g" ? This option displays output in gigabytes.
"-t" ? This option displays total amount of memory, including buffers and caches.
Examples of Free Command
Now that we have discussed syntax and options of "free" command, let's take a look at some examples of how it can be used.
Example 1: Basic Usage
The most basic usage of "free" command is to simply display amount of free and used memory in system. To do this, simply enter following command ?
free
This will display output in kilobytes, as shown below ?
total used free shared buffers cached Mem: 2055480 2024700 30780 0 107008 1441320 -/+ buffers/cache: 478372 1577108 Swap: 1048572 0 1048572
As you can see, this output displays information about total amount of memory in system, as well as amount of memory that is used and free.
Example 2: Displaying Output in Megabytes
If you prefer to see output in megabytes instead of kilobytes, you can use "-m" option. For example, to display output in megabytes, enter following command ?
free -m
This will display output in megabytes, as shown below ?
total used free shared buffers cached Mem: 2004 1974 30 0 104 1407 -/+ buffers/cache: 462 1542 Swap: 1023 0 1023
Example 3: Displaying Total Memory
If you want to display total amount of memory in system, including buffers and caches, you can use "-t" option. For example, to display total amount of memory in megabytes, enter following command ?
free -t -m
This will display total amount of memory in system, including buffers and caches, as shown below ?
total used free shared buffers cached Mem: 2004 1974
Example 4: Displaying Output in Gigabytes
If you want to display output in gigabytes, you can use "-g" option. For example, to display output in gigabytes, enter following command ?
free -g
This will display output in gigabytes, as shown below ?
total used free shared buffers cached Mem: 1 0 1 0 0 0 -/+ buffers/cache: 0 1 Swap: 0 0 0
Example 5: Displaying Output in Bytes
If you want to display output in bytes, you can use "-b" option. For example, to display output in bytes, enter following command ?
free -b
This will display output in bytes, as shown below ?
total used free shared buffers cached Mem: 2105574912 2072870400 32784512 0 109750528 1473768448 -/+ buffers/cache: 494643424 1610931488 Swap: 1073741824 0 1073741824
Additional Information
Apart from basic usage, there are some additional options that can be used with "free" command to provide more detailed information about memory usage in system. Some of these options are ?
"-s <interval>" ? This option specifies interval (in seconds) at which memory usage information should be displayed. For example, to display memory usage every 5 seconds, enter following command: "free -s 5"
"-h" ? This option displays output in a more human-readable format, with memory sizes represented in a more user-friendly manner. For example, instead of displaying output in bytes, output is displayed in megabytes, gigabytes, or terabytes, depending on size of memory.
"-o" ? This option displays output in a different format, with each row representing a different memory segment. This option is useful for displaying detailed information about memory usage in system.
Example 6: Displaying Memory Usage in Real-time
To display memory usage in real-time, you can use "-s" option to specify interval at which information should be displayed. For example, to display memory usage every 2 seconds, enter following command ?
free -s 2
This will display memory usage information every 2 seconds, as shown below ?
total used free shared buffers cached Mem: 2004 1947 56 0 101 1358 -/+ buffers/cache: 487 1517 Swap: 1023 0 1023 total used free shared buffers cached Mem: 2004 1947 56 0 101 1358 -/+ buffers/cache: 487 1517 Swap: 1023 0 1023 total used free shared buffers cached Mem: 2004 1947 56 0 101 1358 -/+ buffers/cache: 487 1517 Swap: 1023 0 1023
As you can see, "free" command displays memory usage information every 2 seconds.
Example 7: Displaying Human-Readable Output
To display output in a more human-readable format, you can use "-h" option. For example, to display output in gigabytes, enter following command ?
free -h
This will display output in gigabytes, as shown below ?
total used free shared buffers cached Mem: 2.0G 1.8G 213M 0B 101M 1.3G -/+ buffers/cache: 411M 1.6G Swap: 1.0G 0B 1.0G
As you can see, memory sizes are displayed in gigabytes instead of bytes or kilobytes.
Example 8: Displaying Output in Different Format
To display output in a different format, you can use "-o" option. For example, to display output in a format that shows each row representing a different memory segment, enter following command ?
free -o
This will display output in a different format, as shown below ?
total used free shared buffers cached Mem: 205
As you can see, output is displayed in a different format, with each row representing a different memory segment. This option is useful for displaying detailed information about memory usage in system.
Conclusion
The "free" command is a very useful tool for monitoring system performance and identifying memory-related issues in Linux operating system. In this article, we discussed basic usage, options, and examples of "free" command. We hope that this article has helped you understand how to use "free" command in Linux.