You are reading this tutorial as you may be facing one of the below issue.
This tutorial is for you.
Let’s dig into it.
If you think your system has become slow, you must check the available RAM memory.
Use free command. This will give you a detail about total, used, cache and free memory.
free [OPTIONS]
Run simple free command. It gives a result in three rows about memory utilization on your Linux system.
aniruddc@aniruddc:~$ free total used free shared buff/cache available Mem: 13767048 846436 12081688 14284 838924 12640988 Swap: 2097148 0 2097148
The first row is the header. The second row is for the main memory. The third row is for swap memory.
This metrics covers following memory details.
By default, all the data shown here are in KiloBytes (KB). This format is not much readable and very difficult to count a number of digits.
Fortunately, you don’t need to do that. You can print all the memory size data in a human-readable format.
Let’s see how you can get this informaton in Human readable format?
Pass ‘-h’ as an option to the free command.
ani@ani:~$ free -h total used free shared buff/cache available Mem: 13G 819M 11G 13M 820M 12G Swap: 2.0G 0B 2.0G
You can also print the sum of the column to calculate the total size available and used to run any application.
ani@ani:~$ free -h -t total used free shared buff/cache available Mem: 13G 1.0G 10G 15M 1.2G 11G Swap: 2.0G 0B 2.0G Total: 15G 1.0G 12G
If you don’t have much free memory, you can uninstall unused packages from your Ubuntu system.
You can also clean the memory by disabling any running process.
Moving to further, you can show the RAM memory in different format and metrics.
Use following option with the free comand. (Information about each option is self descriptive.)
-b, --bytes - Display output in bytes. --kilo - Display output in kilobytes (1KB = 1000bytes). --mega - Display output in megabytes. --giga - Display output in gigabytes. --tera - Display output in terabytes. -k, --kibi - Display output in kibibytes. (1KiB = 1024bytes). This is the default unit. -m, --mebi - Display output in mebibytes. -g, --gibi - Display output in gibytes. --tebi - Display output in tebibytes. --peti - Display output in pebibytes. --si - Instead of 1024, use powers of 1000. For example --mebi --si is equal to --mega.
You can try these different options.
Now, let’s make it more interesting.
Are you running any application? And you want to track how much memory is getting utilized over the period.
You can print free memory by specifying seconds ‘-s’. It will print the memory metrics after every specified second.
Lets print the memory usage at every 5 seconds.
ani@ani:~$ free -s 5
total used free shared buff/cache available Mem: 13767048 1072732 11406516 15956 1287800 12379012 Swap: 2097148 0 2097148 total used free shared buff/cache available Mem: 13767048 1072740 11406508 15956 1287800 12379004 Swap: 2097148 0 2097148 total used free shared buff/cache available Mem: 13767048 1072740 11406508 15956 1287800 12379004 Swap: 2097148 0 2097148
It will keep displaying memory metrics until you stop it.
You can also specify the number of times memory metrics have to be printed using ‘-c’ option.
free -s 5 -c 10
Now it will display the memory metrics total 10 times. The Metric will be displayed every 5 seconds.
In this tutorial you have learned free command to check the main memory usage. Similary, you can check the available disk storage memory.
This is all about checking total, cache, buffer, available and free memory in Ubuntu. If you have any query, comment below.