Free command is used to display the amount of free and used physical memory/RAM on your system.
Syntax
The command has following syntax.
free [OPTIONS]
OPTIONS are optional. We will explore some of the options in this article.
Examples
When a free command is run without options it displays, total, used, free, shared, buff/cache, and available RAM. It also displays, total, used, and free swap space on the system.
free
The default memory unit is bytes which is hard to read. You can use -h to show the output in human-readable format (higher possible unit) as follows.
free -h
You can also specify the unit of your choice. The following units are available.
- -b bytes
- -k kilobytes
- -m megabytes
- -g gigabytes
Suppose, we want the output in megabytes. We would run:
free -m
You can continuously display the RAM statistics by using -s and specifying the delay in seconds. Suppose you want to refresh the output every 2 seconds, invoke the free command as follows:
free -s2
Press CTRL + C to stop the command output.
You can use the -c option to print the output multiple times. Suppose you want the output to be displayed 2 times and the command should automatically quit after 2 repetitions. We would run:
Conclusion
I hope this article helped you a lot. If not, you can improve it by sending your suggestions using comments. Keep visiting Linux World.